package project4; import java.awt.*; import javax.swing.JOptionPane; import javax.swing.UIManager; import javax.swing.plaf.FontUIResource; public class Computer { private static String manufacturer; private static String model; private static String cPU; private static String optical; private static String oS; private static int memory; private static int disk; private static float retailPrice; //no arg constructor that sets fields defaults to null, zero, or None public Computer(){ manufacturer="None"; model="None"; memory='0'; disk='0'; cPU="null"; optical="null"; oS="null"; retailPrice='0'; } //constructor that takes parameters and initializes the appropriate fields public Computer(String newManufacturer, String newModel, int newMemory, int newDisk, String newCPU, String newOptical, String newOS, float newRetailPrice ){ manufacturer=newManufacturer; model=newModel; memory=newMemory; disk=newDisk; cPU=newCPU; optical=newOptical; oS=newOS; retailPrice=newRetailPrice; } //setManufacturer method that accepts a String argument for the manufacture and sets the manufacturer. public void setManufacturer(String newManufacturer){ manufacturer= newManufacturer; } //A setModel method that accepts a String argument for the model and sets the model. public void setModel(String newModel){ model= newModel; } //A setMemory method that accepts an integer argument for the memory size and sets the memory size. If the memory size passed in is less than 2 GB, set the size to 2GB and display an error message via JOptionPane about the invalid size. public void setMemory(int newMemory){ if(newMemory > 2){ memory=newMemory; } else{ JOptionPane.showMessageDialog(null,"Invalid Memory Size Entered: "+newMemory+" GB \n\nSetting memory size to 2 GB" , "Error", JOptionPane.ERROR_MESSAGE); memory=2; } } //A setDisk method that accepts an integer argument for the disk size and sets the disk size. If the disk size passed in is less than 250 GB, set the size to 250 GB and display an error message via JOptionPane about the invalid size. public void setDisk(int newDisk){ if(newDisk > 250){ disk= newDisk; } else{ JOptionPane.showMessageDialog(null,"Invalid Disk Size Entered: "+newDisk+" GB \n\nSetting disk size to 250 GB" , "Error", JOptionPane.ERROR_MESSAGE); disk= 250; } } //A setCPU method that accepts a String argument for the CPU type and sets the CPU type. public void setCPU(String newCPU){ cPU= newCPU; } //A setOptical method that accepts a String argument for the optical dive type and sets the optical dive type. public void setOptical(String newOptical){ optical=newOptical; } //A setOS method that accepts a String argument for the OS version and sets the OS version. public void setOS(String newOS){ oS=newOS; } //A setRetailPrice method that accepts a float argument for the retail price and sets the price. If the value passed in is not equal to or greater than $299.99, display an error message via JOptionPane and set the value to $299.99 public void setRetailPrice(float newRetailPrice){ if(newRetailPrice > (float) 199.99){ retailPrice= newRetailPrice; } else{ JOptionPane.showMessageDialog(null,"Invalid Price Entered: $"+String.format("%.2f",newRetailPrice)+"\n\nSetting Price to $299.99" , "Error", JOptionPane.ERROR_MESSAGE); retailPrice= ((float) 299.99); } } //A getManufacturer method that returns the computers manufacturer. public String getManufacturer(){ return manufacturer; } //A getModel method that returns the computers model number. public String getModel(){ return model; } //A getMemory method that returns the computers memory size. public int getMemory(){ return memory; } //A getDisk method that returns the computers disk size. public int getDisk(){ return disk; } //A getCPU method that returns the computers CPU type size. public String getCPU(){ return cPU; } //A getOptical method that returns the computers optical drive type. public String getOptical(){ return optical; } //A getOS method that returns the computers OS version public String getOS(){ return oS; } //A getRetailPrice method that returns the computers retail price. public float getRetailPrice(){ return retailPrice; } //A displayComputer method that displays the computers information with labels in a JOptionPane public static void displayComputer(){ UIManager.put("OptionPane.messageFont",new FontUIResource(new Font("Courier New", Font.BOLD, 16))); JOptionPane.showMessageDialog(null, "Inventory Computer Detail \n\n" + "Manufacturer: " + manufacturer + "\nModel Name: " + model+ "\nMemory Size: " +memory+ " GB \nDisk Size: " +disk+ " GB \nCPU Type: " +cPU+ "\nOptical Drive: " + optical+ "\nOS Version: " + oS+ "\nRetail Price: $" + String.format("%.2f",retailPrice), "Geekazoid Inc.", JOptionPane.INFORMATION_MESSAGE); } //A toString method that creates and returns the computers information in a single string with the fields separated by colons. public String toString(){ return manufacturer +":"+ model +":" +memory +":" + disk +":" + cPU +":" + optical + ":" + oS; } }