public class AdministratorTest {
public static void main(String[] args) {
Administrator admin1 = new Administrator(); //创建管理员对象1
Administrator admin2 = new Administrator(); //创建管理员对象2
//给管理员对象1赋值并调用显示方法
admin1.name = "admin1";
admin1.password = "111111";
admin1.show();
//给管理员对象2赋值并调用显示方法
admin2.name = "admin2";
admin2.password = "222222";
admin2.show();
}
}
public class Customer {
int points; //积分
String cardType; //卡类型
//显示信息方法
public void show(){
System.out.println("积分:" + points + ",卡类型:" + cardType);
}
}
public class InitialCustomer {
public static void main(String[] args) {
Customer cust = new Customer(); //创建客户对象
cust.points = 1000;
cust.cardType = "普卡";
cust.show();
}
}
import java.util.Scanner;
public class ChangePassword {
/**
* 更改管理员密码
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Administrator admin = new Administrator(); //创建管理员对象
admin.name = "admin1"; //给name属性赋值
admin.password = "111111"; //给password属性赋值
//输入旧的用户名和密码
System.out.print("请输入用户名:");
String nameInput = input.next();
System.out.print("请输入密码:");
String pwd = input.next();
//判断用户输入的用户名和密码是否正确
if(admin.name.equals(nameInput) && admin.password.equals(pwd)){
System.out.print("\n请输入新密码:");
admin.password = input.next(); //修改密码
System.out.println("修改密码成功,您的新密码为:" + admin.password);
}else{
System.out.print("用户名和密码不匹配!您没有权限更新管理员信息。");
}
}
}
public class PointsAward {
/**
* 回馈积分
*/
public static void main(String[] args) {
Customer cust = new Customer(); //创建客户对象
cust.points = 3050;
cust.cardType = "金卡";
cust.show();
if((cust.points>1000 && cust.cardType.equals("金卡"))||
(cust.points>5000 && cust.cardType.equals("普卡"))){
System.out.println("回馈积分500分!");
}
}
}