定义管理员类和会员类

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分!");
		}
	}
}

简单易懂的代码public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String method=request.getParameter("method"); if(method!=null){ if(method.equals("addcategory")){ addCategory(request, response); }else if(method.equals("categorylist")){ categoryList(request, response); }else if(method.equals("toUpdate")){ toUpdate(request, response); }else if(method.equals("updateCategory")){ updateCategory(request, response); } } else{ request.setAttribute("msg", "路径有误请重试"); request.getRequestDispatcher("/404.jsp").forward(request, response); } } public void addCategory(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name=request.getParameter("name"); String sortNo=request.getParameter("sortNo"); if(name==null||name.equals("")){ request.setAttribute("msg", "请输入分区名称"); request.getRequestDispatcher("/admin/category/addCategory.jsp").forward(request, response); }else if(sortNo==null||sortNo.equals("")){ request.setAttribute("msg", "请输入分区序号"); request.getRequestDispatcher("/admin/category/addCategory.jsp").forward(request, response); }else{ CategoryDao dao=new CategoryImpl(); Category category=new Category(); category.setName(name); category.setSortNo(Integer.parseInt(sortNo)); category.setState(1); boolean flag=dao.addCategory(category); if(flag){ categoryList(request, response); }else{ request.setAttribute("msg", "添加失败请重试"); request.getRequestDispatcher("/admin/category/addCategory.jsp").forward(request, response); } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值