java - 我无法让我的包按照我想要的方式编译
问题描述
我在做一个学校项目,它是关于一家电脑店的。基本上,用户必须输入他们想要的计算机/笔记本电脑的规格。如果他们想查看他们输入的内容,他们会输入 3。
但由于某种原因,我无法按照我想要的方式编译,所以我提供了主类。我认为其他课程没有任何问题。
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);
}
}
解决方案
我试过它已经为我编译并得到了输出。
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]
推荐阅读
- python - 尝试 pip numba JIT 编译器时出错
- c# - 重新连接后网络服务不工作
- google-apps-script - 谷歌表单获取谷歌表格值
- python-3.x - 通过Python删除单链表中所有节点值为'x'
- c# - 表单之间的 C# 通信错误
- python - 由于 SSL 模块不可用 Python 无法访问 URL
- sql-server - SQL Server Docker Compose SQLCMD 不执行
- java - 为什么我的递归函数不会遍历堆栈中的所有数据?
- f# - 我可以让返回类型随参数而变化,有点像 F# 中的 sprintf 吗?
- ios - 如何在客户班播放声音并识别声音播放结束