Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This workshop consist of create a simple class and a tester class. Download and

ID: 3682136 • Letter: T

Question

This workshop consist of create a simple class and a tester class. Download and review the Door Example on the content page as this provides a solid example of creating a simple class;

Create a simple DesktopPc class:

Instance variables: String: cpu - the CPU of PC like i7, celeron, etc. int: memoryCapacity - in gigabytes int: hardDriveCapacity - in gigabytes double: price

Methods: default constructor - initialize variables to empty values parameterized constructor - set all instance values with parameters passed in; take 4 parameters corresponds to all instance variables; try to use mutator to set the value of instance variables Mutators (setter) of all instance variables Accessor (getter) of all instance variables String:toString() method to print out like: "Desktop PC: CPU intel i7, DRAM 16GB, HD 2000GB, Price $800.00"

Create a tester class DestopPcTester with a main method to do the following: Create two DestopPc objects. One with default constructor and uses mutator class to set the values. Another use the parameterized constructor. Use mutator to change the price of the first DestopPc object to $100 lower. Print the toString() results before and after the

Document your classes with Javadoc and submit to dropbox with correct format.

*DOOR EXAMPLE*

public class Door
{
       /**
       The position of the door, opened or closed
       */
private String state;
      
       /**
       The title of the door,such as back or front
       */
private String name;
      
       /**
       Constructs a door object with default values for instance fields
       */
public Door()
{
state = "";
name = "";
   
}
      
       /**
       Constructs a door object
       @param initName the name of the door
       @param initState the state of the door
       */
public Door(String initName, String initState)
{
name = initName;
state = initState;
}
      
       /**
       Returns the name of the door
       @return the name of the door
       */
public String getName()
{
return name;
}

       /**
       Returns the state of the door
       @return state of the door
       */
public String getState()
{
return state;
}
      
    /**
       Sets the door to the parameter value
       @param newName the name of the door
       */
public void setName(String newName)
{
name = newName;
}

       /**
       Sets the state of the door (e.g. open or closed)
       @param newState the name of the door
       */
public void setState(String newState)
{
state = newState;
}
}

Explanation / Answer

/**
* @author srinu
*
*/
public class DesktopPc {

   String cpu;
   int memoryCapacity;
   int hardDriveCapacity;
   double price;

   public DesktopPc() {

       this.cpu = "";
       this.memoryCapacity = 0;
       this.hardDriveCapacity = 0;
       this.price = 0.00d;
   }

   /**
   * @param cpu
   * @param memoryCapacity
   * @param hardDriveCapacity
   * @param price
   */
   public DesktopPc(String cpu, int memoryCapacity, int hardDriveCapacity,
           double price) {

       this.cpu = cpu;
       this.memoryCapacity = memoryCapacity;
       this.hardDriveCapacity = hardDriveCapacity;
       this.price = price;
   }

   /**
   * @return the cpu
   */
   public String getCpu() {
       return cpu;
   }

   /**
   * @param cpu
   * the cpu to set
   */
   public void setCpu(String cpu) {
       this.cpu = cpu;
   }

   /**
   * @return the memoryCapacity
   */
   public int getMemoryCapacity() {
       return memoryCapacity;
   }

   /**
   * @param memoryCapacity
   * the memoryCapacity to set
   */
   public void setMemoryCapacity(int memoryCapacity) {
       this.memoryCapacity = memoryCapacity;
   }

   /**
   * @return the hardDriveCapacity
   */
   public int getHardDriveCapacity() {
       return hardDriveCapacity;
   }

   /**
   * @param hardDriveCapacity
   * the hardDriveCapacity to set
   */
   public void setHardDriveCapacity(int hardDriveCapacity) {
       this.hardDriveCapacity = hardDriveCapacity;
   }

   /**
   * @return the price
   */
   public double getPrice() {
       return price;
   }

   /**
   * @param price
   * the price to set
   */
   public void setPrice(double price) {
       this.price = price;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Desktop PC :" + cpu + ", DRAM " + memoryCapacity + "GB, HD "
               + hardDriveCapacity + "GB, Price $" + price;
   }

}

/**
* @author srinu
*
*/
public class DestopPcTester {

   /**
   * @param args
   */
   public static void main(String[] args) {

       try {
           DesktopPc desktopPc1 = new DesktopPc();
           desktopPc1.setCpu("celeron");
           desktopPc1.setMemoryCapacity(16);
           desktopPc1.setHardDriveCapacity(200);
           desktopPc1.setPrice(800.00d);

           DesktopPc desktopPc2 = new DesktopPc("i7", 32, 500, 1600.00d);
           desktopPc2.setPrice(desktopPc2.getPrice() - 100.00);
           System.out.println(desktopPc1);
           System.out.println(desktopPc2);

       } catch (Exception e) {
           // TODO: handle exception
       }
   }
}

OUTPUT:

Desktop PC :celeron, DRAM 16GB, HD 200GB, Price $800.0
Desktop PC :i7, DRAM 32GB, HD 500GB, Price $1500.0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote