我在会员类中创建多个方法,使用对象进行数值控制台输入
我想在会员类的验证方法中进行上面两个方法的数据比较,作为验证
这是问题代码
if (my_.password==my.password&&my_.AdminName.equals(my.AdminName)&&my_.num==my.num){
System.out.println("登录成功");
}else{
System.out.println("密码、账号或会员号错误!");
}
但是局部变量无法更改和调用,怎么样可以调用到另一个方法??
会员类代码
import java.util.Random;
import java.util.Scanner;
/**
* @author woo-m
* 会员类
*/
public class Admin {
String AdminName = null;
String password = null;
int num = 0;
//注册方法
public static void User(){
Scanner x = new Scanner(System.in);
Admin my = new Admin();
System.out.print("user:");
my.AdminName = x.next();
System.out.print("password:");
my.password = x.next();
}
//返回方法
public static void Admins(){
Admin my = new Admin();
Random random=new Random();
my.num=random.nextInt(99999)+100000;
System.out.println("注册成功,你的会员卡号:"+my.num);
}
//登录方法
public static void Log_in(){
Admin my_ = new Admin();
int vip = 0;
Scanner x = new Scanner(System.in);
System.out.print("Your User:");
my_.AdminName = x.next();
System.out.print("Your Password:");
my_.password = x.next();
System.out.print("会员号:");
my_.num = x.nextInt();
}
//验证方法
public static void verify(){
Admin my = new Admin();
Admin my_ = new Admin();
if (my_.password==my.password&&my_.AdminName.equals(my.AdminName)&&my_.num==my.num){
System.out.println("登录成功");
}else{
System.out.println("密码、账号或会员号错误!");
}
}
}
程序入口代码
import java.util.Scanner;
/**
* @author woo-m
* 幸运抽奖系统
*/
public class Luck {
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
int menu = 0;
//注册循环环节
do {
System.out.println("1.注册");
System.out.println("2.登录");
System.out.println("3.抽奖");
System.out.print("输入菜单:");
menu = x.nextInt();
switch (menu){
case 1:
break;
case 2:
System.out.println("-----你还未注册哦!-----");
continue;
case 3:
System.out.println("-----请先登录!-----");
continue;
default:
System.out.println("-----参数错误!-----");
continue;
}
break;
}while (true);
//new Admin类 对象
Admin user = new Admin();
//调用注册方法
Admin.User();
//调用返回会员卡号方法
Admin.Admins();
//调用登录方法
System.out.println("-----欢迎登录-----");
Admin.Log_in();
Admin.verify();
}
}