带参数的方法------客户添加信息

    xiaoxiao2022-06-30  64

    public class Customer { public String name; public int age; public boolean con; public void showinfo(){ System.out.println(name+"\t"+age+"\t"+con); } } public class cusbiz { Customer[] c=new Customer[30]; public void addCustomer( Customer cust){ for(int i=0;i<c.length;i++){ if(c[i]==null){ c[i]=cust; break; } } } public void showCustomer(){ System.out.println("客户信息:"); for(int i=0;i<c.length;i++){ if(c[i]!=null){ c[i].showinfo(); } } System.out.println(); } } public class Test { public static void main(String[] args){ // TODO Auto-generated constructor stub Customer cu1=new Customer(); cu1.name="王一"; cu1.age=30; cu1.con=false; Customer cu2=new Customer(); cu2.name="张三"; cu2.age=20; cu2.con=true; cusbiz cb=new cusbiz(); cb.addCustomer(cu1); cb.addCustomer(cu2); cb.showCustomer(); } }
    转载请注明原文地址: https://ju.6miu.com/read-1126034.html

    最新回复(0)