赞
踩
用户信息(用户名,密码,手机号,地址)
package work; import java.security.PublicKey; import java.util.Scanner; public class DengLu {//用户类 我这里名字本来应该是User,我这个是个错误; private String name; private String mima; private String phone; private String adress; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getMima() { return mima; } public void setMima(String mima) { this.mima = mima; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public String getAdress() { return adress; } public void setAdress(String adress) { this.adress = adress; } public void register() { System.out.println("输入用户名"); Scanner scanner=new Scanner(System.in); String na=scanner.next(); System.out.println("输入密码"); String mi=scanner.next(); if(this.name.equals(na)&&this.mima.equals(mi)) { System.out.println("登录成功"); } else { System.out.println("登录失败"); } } public void login() { System.out.println("输入用户名"); Scanner scanner=new Scanner(System.in); String na=scanner.next(); this.name=na; System.out.println("输入密码"); String mi=scanner.next(); this.mima=mi; System.out.println("输入手机号"); String ph=scanner.next(); this.phone=ph; System.out.println("输入地址"); String addr=scanner.next(); this.adress=addr; System.out.println("注册成功"); } } 测试类: package work; public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub DengLu userDengLu=new DengLu(); userDengLu.login(); System.out.println(userDengLu.getAdress()); userDengLu.register(); } }
测试结果
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。