java - 我无法让我的包按照我想要的方式编译

标签 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]

关于java - 我无法让我的包按照我想要的方式编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56171897/

相关文章:

java - 虽然 write() 中将 byteval 声明为整数,但为什么 Java I/O 流中只将低位八位写入文件

java - 由于 Domino JVM 中缺少 TLS 密码套件导致 SSLHandshakeException

java - XMLList 的 XStream 转换器(类似于 Jaxb)

java - 如何在 lambda 函数中对收集 IntStream 的值进行操作

java - Weblogic 安装程序从错误的文件中读取

java - Hibernate 查询比 MySQL 中的 native 查询慢

java - 有没有一种简单的方法来实现代理 HTTP 请求并将它们转换为 SSL?

java - 将 cglib BeanCopier 与多个类加载器一起使用

java - 如何有效地在selenium中长时间等待

java - 如何从双卡手机 Android 获取运营商名称?