首页 > 代码库 > java-第十四章-代参的方法(二)-实现MyShopping系统的添加会员功能
java-第十四章-代参的方法(二)-实现MyShopping系统的添加会员功能
package com.wxws.sms; public class Customer { int No; int integarl; } package com.wxws.sms; public class Customers { Customer[] customers = new Customer[100]; public void add(Customer cust){ for (int i = 0; i <customers.length; i++) { if (customers[i]==null) { customers[i]=cust; break; } } } public void show(){ System.out.println("会员列表*****"); for (int i = 0; i <customers.length; i++) { if (customers[i]!=null) { System.out.print(customers[i].No+"\t"+customers[i].integarl+"\t"); } } } } package com.wxws.sms; import java.util.Scanner; public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner (System.in); Customer A = new Customer(); Customers B = new Customers(); System.out.print("请输入会员编号:"); A.No=in.nextInt(); System.out.print("请输入会员积分:"); A.integarl=in.nextInt(); B.add(A); B.show(); } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。