T1.显示所有书店客户的信息
示例代码
public static void main(String[] args) {
String[][] users={
{"1100","18","100"},
{"1101","24","834"},
{"1102","13","20000"},
{"1103","20","2938"},
{"1104","22","500"},
{"1105","22","3569"},
{"1106","45","45"},
{"1107","6","450"}
};
System.out.println("书店管理系统>会员信息管理>显示客户信息");
System.out.println("会员号\t年龄\t积分");
for(int i = 0; i < users.length; i++) {
for (int j = 0; j < users[i].length; j++) {
System.out.print(users[i][j]+"\t");
}
System.out.println();
}
}
T2.新增客户信息
示例代码
/**
* 新增信息
*/
public static void main(String[] args) {
String[][] users={
{"1100","18","100"},
{"1101","24","834"},
{"1102","13","20000"},
{"1103","20","2938"},
{"1104","22","500"},
{"1105","22","3569"},
{"1106","45","45"},
{"1107","6","450"}
};
Scanner input=new Scanner(System.in);
System.out.println("书店管理系统>会员信息管理>新增客户信息");
System.out.println("请输入会员名:");
String name=input.next();
System.out.println("请输入年龄:");
String age=input.next();
System.out.println("请输入积分:");
String score=input.next();
int count=users.length+1;
String[][] newUser=new String[count][3];
//添加用户信息的关键代码
for (int i = 0; i < users.length; i++) {
for (int j = 0; j < users[i].length; j++) {
newUser[i][j]=users[i][j];
}
}
newUser[count-1][0]=name;
newUser[count-1][1]=age;
newUser[count-1][2]=score;
System.out.println("书店管理系统>会员信息管理>显示客户信息");
System.out.println("会员号\t年龄\t积分");
for (int i = 0; i < newUser.length; i++) {
for (int j = 0; j < newUser[i].length; j++) {
System.out.print(newUser[i][j]+"\t");
}
System.out.println();
}
}
T3.成绩排名
示例代码
/**
* 成绩排名
*/
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String names[]=new String[10];//存储学生姓名
double scores[]=new double[10];//存储学生成绩
for (int i = 0; i < 10; i++) {
System.out.println("请输入第"+(i+1)+"位学生姓名");
names[i]=sc.next();
System.out.println("请输入"+names[i]+"的成绩");
scores[i]=sc.nextDouble();
}
//排序
for (int i = 0; i < scores.length-1; i++) {
for (int j = 0; j < scores.length-1-i; j++) {
if(scores[j] < scores[j + 1]){ //把小的值交换到后面
//换分数位置
double temp = scores[j];
scores[j] = scores[j + 1];
scores[j + 1] = temp;
//同时换名字位置
String temp2 = names[j];
names[j] = names[j+1];
names[j+1] = temp2;
}
}
}
//输出排名
for (int i = 0; i < scores.length; i++) {
System.out.println("第"+(i+1)+"名\t"+names[i]+"\t"+scores[i]);
}
}
T4.ATM取款机多用户登陆
示例代码
/**
* ATM取款机多用户登录
*/
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
String[][] userArray=new String[][]{
{"百里半","111"},
{"admin","admin"},
{"002","123"}
};
boolean isLogin=false;//登录状态
do {
System.out.println("====================================");
System.out.println("= 欢迎使用ATM取款机 =");
System.out.println("====================================");
System.out.print("账号:");
String username=scanner.next();
System.out.print("密码:");
String userpwd=scanner.next();
for (int i = 0; i < userArray.length; i++) {
if(userArray[i][0].equals(username) && userArray[i][1].equals(userpwd)) {
isLogin=true;
break;
}
}
//判断登录状态
if(isLogin) {
System.out.println("登录成功");
}else {
System.out.println("登录失败");
}
} while (isLogin==false);
}
T5.打印输出ATM所有用户信息
====================================
= 欢迎使用ATM取款机 =
====================================
编号 账号 密码 姓名 年龄 性别 余额
1 百里半 111 李小鹏 18 男 1000
2 002 123 陈晨 20 男 10000
3 admin admin 桂池 22 男 100000
4 004 456 陈红 18 女 5000
5 005 456 郑瑞 20 男 50000
6 006 456 张婷 22 女 200000
public static void main(String[] args) {
// TODO Auto-generated method stub
String[][] userArray=new String[][]{
{"1","百里半","111","李小鹏","18","男","1000"},
{"2","002","123","陈晨","20","男","10000"},
{"3","admin","admin","桂池","22","男","100000"},
{"4","004","456","陈红","18","女","5000"},
{"5","005","456","郑瑞","20","男","50000"},
{"6","006","456","张婷","22","女","200000"}
};
System.out.println("====================================");
System.out.println("= 欢迎使用ATM取款机 =");
System.out.println("====================================");
System.out.println("编号\t账号\t密码\t姓名\t年龄\t性别\t余额");
for(int i=0;i<userArray.length;i++)
{
for(int j=0;j<userArray[i].length;j++)
{
System.out.print(userArray[i][j]+"\t");
}
System.out.println("");
}
}