我的作业是一个迷你桌面计算器,具有不同的类和实践继承。我有一个包含所有方法的长整数类,以及4个子类,称为二进制,八进制,十六进制和十进制,以及一个提示用户并运行while循环的驱动程序类。我的驱动程序类中有一个错误,这里是底部的代码和错误,我不知道这是什么或如何解决它。任何建议都很可爱:)
public class IntDriver {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
LongInteger object;
String mode, digits;
boolean b = true;
System.out.println("Welcome to the Programmer calculator application. Please pick a mode.\n");
mode = menu(s);
if(mode.equals("T")) {
System.out.print("Enter in a number in forms of 0 - 9: ");
digits = s.nextLine();
b = validateDecimal(digits);
while(!b) {
System.out.println("Sorry. You need to input a number in forms of 0 through 9.");
digits = s.nextLine();
b = validateDecimal(digits);
}
object = new DecimalInteger(digits);
} else if(mode.equals("W")) {
System.out.print("Enter in a number in forms of 0 or 1: ");
digits = s.nextLine();
b = validateBinary(digits);
while(b == false) {
System.out.println("Sorry. You need to input a number in forms of 0s or 1s.");
digits = s.nextLine();
b = validateDecimal(digits);
}
object = new BinaryInteger(digits);
} else if(mode.equals("O")) {
System.out.print("Enter in a number in forms of 0 through 7: ");
digits = s.nextLine();
b = validateOctal(digits);
while(b == false) {
System.out.println("Sorry. You need to input a number in forms of 0 through 7.");
digits = s.nextLine();
b = validateDecimal(digits);
}
object = new octalInteger(digits);
} else {
System.out.print("Enter in a number in forms of 0 through 9 and/or A through F: ");
digits = s.nextLine();
b = validateHexadecimal(digits);
while(b == false) {
System.out.println("Sorry. You need to input a number in forms of 0 through 7.");
digits = s.nextLine();
b = validateHexadecimal(digits);
}
object = new HexInteger(digits);
}
}
public static String menu(Scanner s) {
System.out.println("Decimal - T");
System.out.println("Binary - W");
System.out.println("Octal - O");
System.out.println("Hexadecimal - H\n");
String l = s.nextLine();
while(!l.equals("T") && !l.equals("W") && !l.equals("O") && !l.equals("H")) {
System.out.print("Sorry, you did not pick within the list. Please try again: ");
l = s.nextLine();
}
s.nextLine();
return l;
}
public static boolean validateDecimal(String digits) {
boolean test = true;
for(int i = 0; i < digits.length(); i++) {
if(digits.charAt(i) != '0' && digits.charAt(i) != '1' && digits.charAt(i) != '2' && digits.charAt(i) != '3' && digits.charAt(i) != '4' && digits.charAt(i) != '5' && digits.charAt(i) != '6' && digits.charAt(i) != '7' && digits.charAt(i) != '8' && digits.charAt(i) != '9') {
test = false;
} else {
test = true;
}
}
return test;
}
public static boolean validateBinary(String digits) {
boolean test = true;
for(int i = 0; i < digits.length(); i++) {
if(digits.charAt(i) != '0' && digits.charAt(i) != '1') {
test = false;
} else {
test = true;
}
}
return test;
}
public static boolean validateOctal(String digits) {
boolean test = true;
for(int i = 0; i < digits.length(); i++) {
if(digits.charAt(i) != '0' && digits.charAt(i) != '1' && digits.charAt(i) != '2' && digits.charAt(i) != '3' && digits.charAt(i) != '4' && digits.charAt(i) != '5' && digits.charAt(i) != '6' && digits.charAt(i) != '7') {
test = false;
} else {
test = true;
}
}
return test;
}
public static boolean validateHexadecimal(String digits) {
boolean test = true;
for(int i = 0; i < digits.length(); i++) {
if(digits.charAt(i) != '0' && digits.charAt(i) != '1' && digits.charAt(i) != '2' && digits.charAt(i) != '3' && digits.charAt(i) != '4' && digits.charAt(i) != '5' && digits.charAt(i) != '6' && digits.charAt(i) != '7' && digits.charAt(i) != '8' && digits.charAt(i) != '9' && digits.charAt(i) != 'A' && digits.charAt(i) != 'B' && digits.charAt(i) != 'C' && digits.charAt(i) != 'D' && digits.charAt(i) != 'E' && digits.charAt(i) != 'F') {
test = false;
} else {
test = true;
}
}
return test;
}
}
这是错误:
IntDriver.java:40: cannot find symbol
symbol : class octalInteger
location: class IntDriver
object = new octalInteger(digits);
^
DecimalInteger.java:6: cannot find symbol
symbol : constructor LongInteger()
location: class LongInteger
{
^
BinaryInteger.java:6: cannot find symbol
symbol : constructor LongInteger()
location: class LongInteger
{
^
HexInteger.java:6: cannot find symbol
symbol : constructor LongInteger()
location: class LongInteger
{
^
4 errors