帮我做一道数组对象的题
结果如下输入会员编号:12345输入会员积分:1000*****会员列表******编号积分123451000创建会员类Customer,添加属性;编号,积分;会员操作类...
结果如下
输入会员编号:12345
输入会员积分:1000
*****会员列表******
编号 积分
12345 1000
创建会员类Customer,添加属性;编号,积分;
会员操作类.CustManager;
谁给出步骤?感激不尽 展开
输入会员编号:12345
输入会员积分:1000
*****会员列表******
编号 积分
12345 1000
创建会员类Customer,添加属性;编号,积分;
会员操作类.CustManager;
谁给出步骤?感激不尽 展开
3个回答
展开全部
package ch14;
/**
* 会员类
* @author Administrator
*
*/
public class Customer {
String no;//编号
int score;//积分
}
import java.util.Scanner;
/**
* 操作类
* @author Administrator
*
*/
public class CustManager {
Customer[] cust = new Customer[10];//创建对象会员数组
/**
*增加会员方法,对象作为参数
* @param cu
*/
public void addCust(Customer cu){
for(int i = 0;i<cust.length;i++){
if(cust[i] == null){
cust[i] = cu;
break;
}
}
}
/**
* 输出会员信息
*/
public void show(){
System.out.println("编号"+"\t"+"积分");
for(int i = 0;i<cust.length;i++){
if( cust[i]!=null &&cust[i].no != null && cust[i].score != 0){
System.out.println(cust[i].no+"\t"+cust[i].score);
break;
}
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
CustManager cust = new CustManager();
Customer cu = new Customer();
System.out.print("请输入会员编号:");
cu.no = input.next();
System.out.print("请输入会员积分:");
cu.score = input.nextInt();
cust.addCust(cu);//将输入的会员信息导入到数组中
System.out.println("****会员列表****:");
cust.show();
}
}
你要的题怎么跟我在学校的练习是一样的呢?
要输入多个,可以循环输入。
/**
* 会员类
* @author Administrator
*
*/
public class Customer {
String no;//编号
int score;//积分
}
import java.util.Scanner;
/**
* 操作类
* @author Administrator
*
*/
public class CustManager {
Customer[] cust = new Customer[10];//创建对象会员数组
/**
*增加会员方法,对象作为参数
* @param cu
*/
public void addCust(Customer cu){
for(int i = 0;i<cust.length;i++){
if(cust[i] == null){
cust[i] = cu;
break;
}
}
}
/**
* 输出会员信息
*/
public void show(){
System.out.println("编号"+"\t"+"积分");
for(int i = 0;i<cust.length;i++){
if( cust[i]!=null &&cust[i].no != null && cust[i].score != 0){
System.out.println(cust[i].no+"\t"+cust[i].score);
break;
}
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
CustManager cust = new CustManager();
Customer cu = new Customer();
System.out.print("请输入会员编号:");
cu.no = input.next();
System.out.print("请输入会员积分:");
cu.score = input.nextInt();
cust.addCust(cu);//将输入的会员信息导入到数组中
System.out.println("****会员列表****:");
cust.show();
}
}
你要的题怎么跟我在学校的练习是一样的呢?
要输入多个,可以循环输入。
展开全部
1、创建Customer.java;
public class Customer{
public Customer(String order,String point){
this.order = order;
this.point = point;
}
private String order;
public String getOrder(){
return this.order;
}
public void setOrder(String order){
this.order = order;
}
public String point(){
return this.point;
}
public void setPoint(String point){
this.point = point;
}
}
2、创建CustManager.java;
public class CustManager{
public CustManager(){}
public void doCust(String order ,String point){
Customer c = new Customer(order,point);
System.out.println("*****会员列表******");
System.out.println("编号 积分");
System.out.println(c.getOrder()+" "+c.getPoint());
}
}
public class Customer{
public Customer(String order,String point){
this.order = order;
this.point = point;
}
private String order;
public String getOrder(){
return this.order;
}
public void setOrder(String order){
this.order = order;
}
public String point(){
return this.point;
}
public void setPoint(String point){
this.point = point;
}
}
2、创建CustManager.java;
public class CustManager{
public CustManager(){}
public void doCust(String order ,String point){
Customer c = new Customer(order,point);
System.out.println("*****会员列表******");
System.out.println("编号 积分");
System.out.println(c.getOrder()+" "+c.getPoint());
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
/**
* 会员类
* @author Administrator
*
*/
public class Customer {
private String number; //编号
private String integral; //积分
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getIntegral() {
return integral;
}
public void setIntegral(String integral) {
this.integral = integral;
}
}
/**
* 操作类
* @author Administrator
*
*/
public class CustManager {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Customer customer = xinxi();
System.out.println("输入会员编号:"+customer.getNumber());
System.out.println("输入会员积分:"+customer.getIntegral());
System.out.println("*****会员列表******");
System.out.println("编号 积分");
System.out.println(customer.getNumber()+" "+customer.getIntegral());
}
private static Customer xinxi(){
Customer customer = new Customer();
customer.setNumber("12345");
customer.setIntegral("1000");
return customer;
}
}
不太明白的要用什么方法做! 所以,我按自己的想法做的!
* 会员类
* @author Administrator
*
*/
public class Customer {
private String number; //编号
private String integral; //积分
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getIntegral() {
return integral;
}
public void setIntegral(String integral) {
this.integral = integral;
}
}
/**
* 操作类
* @author Administrator
*
*/
public class CustManager {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Customer customer = xinxi();
System.out.println("输入会员编号:"+customer.getNumber());
System.out.println("输入会员积分:"+customer.getIntegral());
System.out.println("*****会员列表******");
System.out.println("编号 积分");
System.out.println(customer.getNumber()+" "+customer.getIntegral());
}
private static Customer xinxi(){
Customer customer = new Customer();
customer.setNumber("12345");
customer.setIntegral("1000");
return customer;
}
}
不太明白的要用什么方法做! 所以,我按自己的想法做的!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询