我无法将新变量从adminadd类获取到adminview类。我想将新客户添加到管理员视图,但我不能。请帮助大家这是我的两个类的代码
public class adminview {
public void view() {
String table[] = {
"Account Number",
"Account Name",
"Balance",
"Pin Number"
};
String acct[] = {
"0123-4567-8901",
"2345-6789-0123",
"3456-7890-1234",
"4567-8901-2345",
"5678-9012-3456"
};
String name[] = {
"Dina Balle",
"Mally Gaya",
"Toto Lee",
"Mina Mahal",
"Cory Pot"
};
int bal[] = {
5000,
0,
10000,
2500,
10000
};
int pinarr[] = {
0000,
1111,
2222,
3333,
4444,
5555
}; {
System.out.print("====================FBC====================\n\nFILIPINAS BANKING CORPORATION\n\n" + table[0] + "\t\t" + table[1] + "\t\t" + table[2] + "\t\t" + table[3] + "\n");
System.out.println(acct[0] + "\t\t" + name[0] + "\t\t\t" + bal[0] + "\t\t\t" + pinarr[1]);
System.out.println(acct[1] + "\t\t" + name[1] + "\t\t\t" + bal[0] + "\t\t\t" + pinarr[2]);
System.out.println(acct[2] + "\t\t" + name[2] + "\t\t\t" + bal[2] + "\t\t\t" + pinarr[3]);
System.out.println(acct[3] + "\t\t" + name[3] + "\t\t\t" + bal[3] + "\t\t\t" + pinarr[4]);
System.out.println(acct[4] + "\t\t" + name[4] + "\t\t\t" + bal[4] + "\t\t\t" + pinarr[5]);
}
}
}
import java.util.Scanner;
public class adminadd {
public static void add() {
Scanner sc = new Scanner(System.in);
String nname;
String nacct;
int nbal;
int npin;
String table[] = {
"Account Number",
"Account Name",
"Balance",
"Pin Number"
};
String acct[] = {
"0123-4567-8901",
"2345-6789-0123",
"3456-7890-1234",
"4567-8901-2345",
"5678-9012-3456"
};
String newaact[] = {
""
};
String name[] = {
"Dina Balle",
"Mally Gaya",
"Toto Lee",
"Mina Mahal",
"Cory Pot"
};
String newname[] = {
""
};
int bal[] = {
5000,
0,
10000,
2500,
10000
};
int pinarr[] = {
0000,
1111,
2222,
3333,
4444,
5555
};
System.out.print("====================FBC====================\n\nFILIPINAS BANKING CORPORATION\n");
System.out.print("Enter New Account #: ");
nacct = sc.nextLine();
System.out.print("Enter New Customer: ");
nname = sc.nextLine();
System.out.print("Enter New Balance: ");
nbal = sc.nextInt();
System.out.print("Enter New Pin: ");
npin = sc.nextInt();
System.out.print("\n\n");
System.out.println("Account #\t\t\tAccount Name\t\tBalance\t\t\tPin");
System.out.println(acct[0] + "\t\t" + name[0] + "\t\t\t" + bal[0] + "\t\t\t" + pinarr[1]);
System.out.println(acct[1] + "\t\t" + name[1] + "\t\t\t" + bal[0] + "\t\t\t" + pinarr[2]);
System.out.println(acct[2] + "\t\t" + name[2] + "\t\t\t" + bal[2] + "\t\t\t" + pinarr[3]);
System.out.println(acct[3] + "\t\t" + name[3] + "\t\t\t" + bal[3] + "\t\t\t" + pinarr[4]);
System.out.println(acct[4] + "\t\t" + name[4] + "\t\t\t" + bal[4] + "\t\t\t" + pinarr[5]);
System.out.println(nacct + "\t\t" + nname + "\t\t\t" + nbal + "\t\t\t" + npin);
}
}
答案 0 :(得分:0)
虽然不是很好的做法,但你可以通过调用它来获得一个公共变量从一个类到另一个类,就像这个“class.yourvariable”
通常,建议将实例变量设置为private,并通过getter和setter获取它们。
答案 1 :(得分:0)
使用吸气剂。 如果不可能,请使用反射。
我认为它会是这样的:
Object val = YourClass.class.getDeclaredField("fieldName").get(YourInstance);