I have created a system class that has different methods for displaying details of a computer system.
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");
}
}
}
I have then created a test system GUI class that uses this information and calls these methods as a drop down menu using a switch statement. The program is not working as it should. It creates a pane with a drop down menu, listing 1-5 as options but when I select choices 1, 2, or 4 it doesn't do anything. It is supposed to display the information from the corresponding methods. I'm not sure how to fix this.
When I select option 3 it displays the input boxes as it should but it doesn't matter what I enter it gives the same result. I believe this is because they are initialized to 0, but I'm not sure how I can initialise it without a number.
Also when I select option 5 it is supposed to exit the program, but it does not and again I don't know how to fix this. There is also an error on this line: while(input != "5"); saying that "input cannot be resolved to a variable"
any advice?
Here is the updated test system GUI code: Although I know have this at the "}));" line at the bottom: Multiple markers at this line - Syntax error, insert "Identifier (" to complete MethodHeaderName - Syntax error, insert "SimpleName" to complete 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();
}
}));
}