0

コンピューター システムの詳細を表示するためのさまざまなメソッドを持つシステム クラスを作成しました。

import java.util.Properties;

public class System_Y3881268 
{
    // the attributes
    private String make;
    private String model;
    private int speed;
    private int memorySize;
    private double hardDiskSize;
    private double purchaseCost;

     // the methods

     // the constructor
    public System_Y3881268(String makeIn, String modelIn, int speedIn) 
    {
        make = makeIn;
        model = modelIn;
        speed = 2;
    }

    // methods to set the corresponding attributes- mutator methods
        public void setMemory(int memorySizeIn) 
        {
            memorySize = memorySizeIn;
        }

        public void setHardDisk(double hardDiskSizeIn) 
        {
            hardDiskSize = hardDiskSizeIn;
        }

        public void setPurchaseCost(double purchaseCostIn) 
        {
            purchaseCost = purchaseCostIn;
        }

    // methods to return attribute values- accessor methods
    public String getMake() 
    {
        return make;
    }

    public String getModel() 
    {
        return model;
    }

    public int getProcessorSpeed() 
    {
        return speed;
    }

    //display details of the system
    public void displayDetails() 
    {
        System.out.println("*****Computer Details*****");
        System.out.println("Make: " + getMake());
        System.out.println("Model: " + getModel());
        System.out.println("Processor speed; " + getProcessorSpeed() + "GHz");
        System.out.println("Memory size: " + memorySize + " MB"); 
        System.out.println("Hard disk size: " + hardDiskSize + " GB");
        System.out.println("Purchase cost: £" + purchaseCost);
    }

    //check if the hard disk size is below 2GB and print corresponding message   
    public String checkHDStatus(double hardDiskSizeIn) 
    {
        if(hardDiskSizeIn<2) 
        {
            return("Low");
        }

        else 
        {
            return("Ok");
        }
    }

    //Check if the memory size is below 128MB and print corresponding message
    public boolean goodMemorySize(int memorySizeIn) 
    {
        if(memorySizeIn<128) 
        {
            return false;
        }

        else 
        {
            return true;
        }
    }

    /*use the checkHDStatus() method and the goodMemorySize() method to diagnose the 
     * system by displaying the appropriate messages*/
    public void diagnoseSystem() 
    {
        System.out.println();
        System.out.println("*****System Diagnosis*****");
        System.out.println("Hard disk size = " + checkHDStatus(hardDiskSize));
        System.out.println("Memory size Ok = " + goodMemorySize(memorySize));
    }

    //method to display system properties
    public static void displaySystemProperties() 
    {
        Properties pros = System.getProperties();
        pros.get(System.out);

        System.out.println();
        System.out.println("*****System Properties*****");

        System.out.println("Operating System Architecture: " + System.getProperty("os.arch"));
        System.out.println("Operating System Name: " + System.getProperty("os.name"));
        System.out.println("Operating System Version: " + System.getProperty("os.version"));
        System.out.println("User Account Name: " + System.getProperty("user.name"));
        System.out.println("Java Version: " + System.getProperty("java.version"));
        System.out.println();

        if(System.getProperty("os.name").equals("Windows 10")) 
        {
            System.out.println("Thumbs up! Your operating system is Windows 10");
        }
        else if(System.getProperty("os.name").equals("Linux")) 
        {
            System.out.println("Thumbs down! Your operating system is Linux");
        } 

        else 
        {
            System.out.println("Your choice of operating system is ok");
        }

    }
}

次に、この情報を使用し、switch ステートメントを使用してこれらのメソッドをドロップダウン メニューとして呼び出すテスト システム GUI クラスを作成しました。プログラムが正常に動作していません。ドロップダウン メニューを含むペインを作成し、オプションとして 1 ~ 5 をリストしますが、選択肢 1、2、または 4 を選択しても何もしません。対応するメソッドからの情報を表示することになっています。これを修正する方法がわかりません。

オプション 3 を選択すると、入力ボックスが表示されますが、何を入力しても同じ結果が得られます。これは 0 に初期化されているためだと思いますが、数値なしで初期化する方法がわかりません。

また、オプション 5 を選択すると、プログラムを終了するはずですが、終了せず、これを修正する方法もわかりません。次の行にもエラーがあります: while(input != "5"); 「入力を変数に解決できない」と言っている

何かアドバイス?

更新されたテスト システムの GUI コードは次のとおりです。一番下の行: この行に複数のマーカー - 構文エラー、"Identifier (" を挿入して MethodHeaderName を完成 - 構文エラー、"SimpleName" を挿入して QualifiedName を完成

import javax.swing.JOptionPane;

import com.sun.javafx.binding.MapExpressionHelper.SimpleChange;

public class SystemTestGUI_Y3881268 
{

    javax.swing.SwingUtilities.@invokeLater(new Runnable() {
        private StringBuffer input;

        public void run() {
            createGUI();
        }

        private void createGUI() {


            do {
                String[] choices = { "Select...", "1", "2", "3", "4", "5" };
                String input = (String) JOptionPane.showInputDialog(null, "Select a choice\n1: Print System Details\n2: Diagnose "
                        + "System\n3: Set Details\n4: Print System Properties\n5: Quit the Program", 
                        "Computer System Menu", JOptionPane.INFORMATION_MESSAGE, null, choices, choices[0]);

                System_Y3881268 s;
                switch(input) 
                {

                case "1": 

                    s.displayDetails();

                break;

                case "2": 

                    s.diagnoseSystem();

                break;

                case "3": 

                    JOptionPane.showInputDialog(null, "Enter hard disk size in GB: ");
                    double hardDiskSize = 0;
                    s.setHardDisk(hardDiskSize);
                    if(hardDiskSize<2) 
                    {
                        JOptionPane.showMessageDialog(null, "Hard disk size = Low");
                    }

                    else 
                    {
                        JOptionPane.showMessageDialog(null, "Hard disk size = Ok");
                    }

                    JOptionPane.showInputDialog(null, "Enter memory size in MB: ");
                    int memorySize = 0;
                    s.setMemory(memorySize);
                    if(memorySize<128) 
                    {
                        JOptionPane.showMessageDialog(null, "Memory Ok = False");
                    }

                    else 
                    {
                        JOptionPane.showMessageDialog(null, "Memory Ok = True");
                    }

                break;

                case "4": 

                    System_Y3881268.displaySystemProperties();

                break;

                case "5": break;
                default: JOptionPane.showMessageDialog(null, "Enter only numbers from 1 - 5");

        }
    }while (!"5".contentEquals(input)




    );}


    public static void main(String[] args) {
        System_Y3881268 s=new System_Y3881268("Lenovo", 
                "Ideacentre A340-24IWL", 2);
        s.setHardDisk(2);
        s.setMemory(128);
        s.setPurchaseCost(599);

        s.displayDetails();
        s.diagnoseSystem();
        System_Y3881268.displaySystemProperties();

    }

}));

}
4

0 に答える 0