一案例要求:
二代码实现:
Ⅰ
package 重修;
import java.util.Random;
import java.util.Scanner;
public class first {
public static void main(String[] args) {
javabean s1=new javabean("张世杰","5201314");
Scanner sc=new Scanner(System.in);
int i=1;
while (true) {
System.out.print("请输入登录名:");
String a=sc.next();
System.out.print("请输入密码:");
String b=sc.next();
javabean s2=new javabean(a,b);
javabeanoperate op=new javabeanoperate(s1.getLandmark(), s1.getCard());
Boolean m;
m=op.panduan(s2.getLandmark(),s2.getCard());
if (m==true) {
System.out.println("登录成功");break;
}
else {
System.out.println("登录失败,登陆名或密码错误");
System.out.println("请再次输入,您还有"+(3-i)+"次机会");
i++;
}
}
}
}
Ⅱ
package 重修;
public class javabean {
private String landmark;
private String card;
public javabean() {
}
public javabean(String landmark, String card) {
this.landmark = landmark;
this.card = card;
}
public String getLandmark() {
return landmark;
}
public void setLandmark(String landmark) {
this.landmark = landmark;
}
public String getCard() {
return card;
}
public void setCard(String card) {
this.card = card;
}
}
Ⅲ
private String a;
private String b;
public javabeanoperate() {
}
public javabeanoperate(String a, String b) {
this.a = a;
this.b = b;
}
public Boolean panduan(String a, String b){
if (this.a.equals(a)){
if (this.b.equals(b)) return true;
else return false;
}
return false;
}
}