java中创建一个客户类数组customer[] 怎么给数组中的变量赋值?

如果可以的话,采用另外的方法也可以。
要求输出结果相同:

输入会员编号:20101
输入会员积分:1800
***会员列表***
编号 积分
20101 1800
1. 创建会员类 Customer 添加两个属性:会员编号、会员积分
2。创建会员操作类 CustManager

添加属性会员数组 customers
Customer [] customer = new Customer[100];

可添加多个会员编号和积分,要求接收add() 和打印所有 show()

先给数组元素new customer对象,然后通过customer对象在给属性变量赋值。

过程

customer类:

class customer{//定义customer类
   public int a1;//顶一个变量属性a1
}

1、顶一个customer数组

customer[] ct = new customer[3];//定一个customer数组,数组长度是3

2、给数组中的customer赋值

for(int i=0;i<ct.length;i++){
    ct[i] = new customer();//实例化customer对象
    ct[i].a1 = 2;//给customer类的a1属性赋值
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-09-14
把会员信息封装成对象加到数据里面就行 要赋值就取出对象用setID 或者setJF方法就可以把
第2个回答  2011-09-14
public class Customer {
int custNum;
int points;

public Customer(){}
public Customer(int custNum,int points)
{
this.custNum = custNum;
this.points = points;
}

public int getCustNum() {
return custNum;
}
public void setCustNum(int custNum) {
this.custNum = custNum;
}
public int getPoints() {
return points;
}
public void setPoints(int points) {
this.points = points;
}

public String lineInfo(){
return this.custNum + "/t" + this.points;
}

/**
* 你的 show()
*/
public static void printList(Customer[] ca){
System.out.println("***会员列表***/r/n编号/t 积分");

if(ca!=null)
for(int i=0; i<ca.length; i++){
if(ca[i]!=null)
System.out.println(ca[i].lineInfo());
}
}

/**
* 你的 add()
* @return
* @throws IOException
*/
public Customer input() throws IOException{
Customer c = new Customer();
System.out.println("输入会员号:");
c.setCustNum(System.in.read());
System.out.println("输入会员积分:");
c.setPoints(System.in.read());

return c;
}
第3个回答  2011-09-14
import java.io.IOException;

public class Customer {
int custNum;
int points;

public Customer(){}
public Customer(int custNum,int points)
{
this.custNum = custNum;
this.points = points;
}

public int getCustNum() {
return custNum;
}
public void setCustNum(int custNum) {
this.custNum = custNum;
}
public int getPoints() {
return points;
}
public void setPoints(int points) {
this.points = points;
}

public String lineInfo(){
return this.custNum + "/t" + this.points;
}

/**
* 你的 show()
*/
public static void printList(Customer[] ca){
System.out.println("***会员列表***/r/n编号/t 积分");

if(ca!=null)
for(int i=0; i<ca.length; i++){
if(ca[i]!=null)
System.out.println(ca[i].lineInfo());
}
}

/**
* 你的 add()
* @return
* @throws IOException
*/
public Customer input() throws IOException{
Customer c = new Customer();
System.out.println("输入会员号:");
c.setCustNum(System.in.read());
System.out.println("输入会员积分:");
c.setPoints(System.in.read());

return c;
}

}

你要的大部分功能有了,自己拆补去吧!
第4个回答  2011-09-14
为什么用数组而不用List。。。
Customer类:
int age;
String name;
Customer(int age,String name)
{
this.age = age;
this.name = name;
}

@Override
public String toString()
{
return "[" + name + "," + age + "]";
}

调用:
Customer[] customer = new customer[3];
customer[0] = new Customer (xxx,"XXX");
相似回答