public class Customer {
private String customerName
private int age
private boolean isValid
public Customer(String customerName, int age, boolean isValid) {
super()
this.customerName = customerName
this.age = age
this.isValid = isValid
}
public String getCustomerName() {
return customerName
}
public void setCustomerName(String customerName) {
this.customerName = customerName
}
public int getAge() {
return age
}
public void setAge(int age) {
this.age = age
}
public boolean isValid() {
return isValid
}
public void setValid(boolean isValid) {
this.isValid = isValid
}
}
import java.util.ArrayList
import java.util.List
public class CustomerBiz {
private List<Customer> customerList = new ArrayList<Customer>()
public void addCustomer(Customer customer){
customerList.add(customer)
}
public void showCustomers(){
Customer customer = null
for(int i=0i<customerList.size()i++){
customer = customerList.get(i)
System.out.println(customer.getCustomerName()+" "+customer.getAge()+" "+customer.isValid())
}
}
public static void main(String[] args){
CustomerBiz customerBiz = new CustomerBiz()
customerBiz.addCustomer(new Customer("王一",30,false))
customerBiz.addCustomer(new Customer("郝强",19,true))
customerBiz.showCustomers()
}
}
package com_AddCust/**
*
* 实现循环录入客户信息:
* 1、循环录入3位客户信息
* 2、判断会员号是否合法(4位整数)
* 3、会员号合法,显示录入的信息,否则显示录入失败
*/
import java.util.*
import com_MainMenu.MainMenu
import com_CustMMenu.CustMMenu
public class AddCust {
int in2
int in
int in4
int i
String in1
int in3
public void addCust(){
Scanner scan=new Scanner(System.in)
System.out.println("我素管理购物管理系统 >客户信息管理 >添加客户信息")
System.out.println()
System.out.println()
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *")
System.out.println("请输入会员个数")
in4=scan.nextInt()
for(int i=0i<in4i++){
System.out.print("请输入会员号<四位整数>:")
in=scan.nextInt()
System.out.print("")
System.out.print("请输入会员生日:<月/日用两位数表示:")
in1=scan.next()
System.out.print("")
System.out.print("请输入会员积分<四位整数>:")
in2=scan.nextInt()
System.out.println("录入会员"+in+"信息成功")
if((in>999)&&(in<=9999))
continue
System.out.println("客户号"+in+"是无效的会员名!\n")
System.out.println("录入信息失败!\n\n\n")
}
System.out.print("请 选 择,输 入 数 字 或 按 0 返 回 上 一 级 菜 单:")
do{
in3=scan.nextInt()
if(in3==0){
com_CustMMenu.CustMMenu cust=new CustMMenu()
cust.custMMenu()
}
else
{
System.out.println("输入有误,请从新输入")
}
}while(in3!=0)
}
public void main(){
for(i=0i<in4i++){
if((in>999)&&(in<=9999)){
System.out.println(in+"\t\t"+ in1+"\t\t"+in2)
}
}
}
}
public class CustomerBiz {List<User> list=null
public CustomerBiz() {
list=new ArrayList<User>()
}
private void addName(String name) {
User user=new User(name)
list.add(user)
}
private void showNames() {
System.out.println("***************************************")
System.out.println(" 客户姓名列表")
System.out.println("***************************************")
for (int i = 0 i < list.size() i++) {
System.out.print(list.get(i).getName()+" ")
if(i%4==0 && i>0)
System.out.println()
}
}
public static void main(String[] args) {
CustomerBiz customerBiz=new CustomerBiz()
doInput(customerBiz)
}
public static void doInput(CustomerBiz customerBiz){
String name=""
Scanner in=new Scanner(System.in)
System.out.println("请输入客户姓名:")
name=in.next()
if(name.equals("")) {
System.out.println("请重新输入客户姓名:")
name=in.next()
}
customerBiz.addName(name)
System.out.println("继续输入吗?y/n")
String tag=in.next()
if(tag.equals("y")){
doInput(customerBiz)
}else{
customerBiz.showNames()
}
}
}
class User{
String name
public String getName() {
return name
}
public void setName(String name) {
this.name = name
}
public User(String name) {
this.name=name
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)