我正在做一个学校项目,关于一个计算机商店。基本上,用户必须输入他们想要的计算机/笔记本电脑规格。如果要查看输入的内容,请输入3。
但是由于某种原因,我无法按照我想要的方式进行编译,因此我提供了Main Class。我认为其他班级没有任何问题。
import java.util.Scanner;
public class ComputerShop1{
public static void main(String[] args) {
int response = 0;
int desktopCounter = 0;
int laptopCounter = 0;
Scanner scanner = new Scanner(System.in);
Desktop[] dt = new Desktop[5];
Laptop[] lt = new Laptop[5];
do{
System.out.println("************************************* BoBo Co. *************************************");
System.out.println("Computer Menu: ");
System.out.println("1. Add information for new Desktop ");
System.out.println("2. Add information for new Laptop ");
System.out.println("3. Display all computer information ");
System.out.println("4. Quit ");
System.out.println("*******************************************************************************************************");
System.out.println("Please enter either 1 to 4: ");
response = Integer.parseInt(scanner.nextLine());
if (response <= 0 || response > 4 ){
System.out.println("Enter a number from 1 to 4 Please : ");
} else {
if(response == 1) {
dt[desktopCounter] = new Desktop();
System.out.println("====================================================================");
System.out.println("Information for new Desktop");
System.out.println("====================================================================");
System.out.println("What is the Desktop Model: ");
dt[desktopCounter].setID(scanner.nextLine());
System.out.println("What is the Processor Speed: ");
dt[desktopCounter].setSpeed(scanner.nextLine());
System.out.println("What is the RAM size: ");
dt[desktopCounter].setRAM(scanner.nextLine());
System.out.println("What is the Harddrisk size: ");
dt[desktopCounter].setHDD(scanner.nextLine());
System.out.println("What is the Monitor Type: ");
dt[desktopCounter].setMonitor(scanner.nextLine());
System.out.println();
System.out.println("Your information has been added successfully");
System.out.println();
desktopCounter++;
} else if (response == 2){
lt[laptopCounter] = new Laptop();
System.out.println("====================================================================");
System.out.println("Information for new Laptop");
System.out.println("====================================================================");
System.out.println("What is the Laptop Model: ");
lt[laptopCounter].setID(scanner.nextLine());
System.out.println("What is the Processor Speed: ");
lt[laptopCounter].setSpeed(scanner.nextLine());
System.out.println("What is the RAM size: ");
lt[laptopCounter].setRAM(scanner.nextLine());
System.out.println("What is the Harddisk size: ");
lt[laptopCounter].setHDD(scanner.nextLine());
System.out.println("What is the Weight: ");
lt[laptopCounter].setWeight(scanner.nextLine());
System.out.println();
System.out.println("Your information has been added successfully");
System.out.println();
laptopCounter++;
} else if (response == 3) {
for(int i = 0; i < desktopCounter; i++){
System.out.println("Desktop" + (i + 1));
dt[i].displayInfo();
System.out.println();
}
for (int i = 0;i < laptopCounter; i++ ){
System.out.println("Laptop "+ ( i + 1));
lt[i].displayInfo();
System.out.println();
}
}
}
} while (response < 4);
}
}
答案 0 :(得分:0)
我尝试过为我编译并获得输出。
enter code here
************************************* BoBo Co. *************************************
Computer Menu:
1. Add information for new Desktop
2. Add information for new Laptop
3. Display all computer information
4. Quit
*******************************************************************************************************
Please enter either 1 to 4:
1
====================================================================
Information for new Desktop
====================================================================
What is the Desktop Model:
sdfsdf
What is the Processor Speed:
23
What is the RAM size:
500
What is the Harddrisk size:
500
What is the Monitor Type:
sony
Your information has been added successfully
************************************* BoBo Co. *************************************
Computer Menu:
1. Add information for new Desktop
2. Add information for new Laptop
3. Display all computer information
4. Quit
*******************************************************************************************************
Please enter either 1 to 4:
3
Desktop1
Desktop [ID=sdfsdf, speed=23, ram=500, HDD=500, monitor=sony]