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

This workshop uses workshop 7 as the start point. *WORKSHOP 7 START* This worksh

ID: 3684927 • Letter: T

Question

This workshop uses workshop 7 as the start point.

*WORKSHOP 7 START*

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.

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;
}

}

public class DesktopPcTester {

/**
* @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
}
}
}

*WORKSHOP 7 END*

*DOOR EXAMPLE START*

public class DoorTester
{

public static void main(String[] args)
{
Door frontDoor = new Door("Front", "open");
Door sideDoor = new Door();
System.out.println("The front door is " + frontDoor.getState());

Door backDoor = new Door("Back", "closed");
  

System.out.println("The back door is " + backDoor.getState());

      
// Use the mutator to change the state variable
backDoor.setState("open");
System.out.println("The back door is " + backDoor.getState());
  
// Use the mutator to change the name variable
backDoor.setName("Kitchen");
System.out.println("The back door is called " + backDoor.getName());

sideDoor.setName("Side");
System.out.println("The side door is " + sideDoor.getState());
  
sideDoor.setState("open");
System.out.println("The side door is " + sideDoor.getState());
  
}
}

*DOOR EXAMPLE END*

-------------------------------------

With the existing DesktopPC class from workshop 7 above develop a small console application that interact with user and help them to build a pc.

Do not modify the DesktopPC class. Develop a java class called PCAdvisor:

PCAdvisor class is runnable, which means it has a main method;

In the program, ask user questions and set up the DesktopPC according to the answer;

Questions: 1. What is your budget(high or low), 2. What is your preferred CPU brand (Intel or AMD);

You may assume user give correct answer always so do not implement input validation;

Build DesktopPC object according to the answers:

high budget, intel - cpu: Intel i7, DRAM (Memory): 16GB, HD (hard drive): 2000GB, Price: 800

Low budget, intel - cpu: Intel celeron, DRAM (Memory): 4GB, HD (hard drive): 500GB, Price: 400

High budget, AMD - cpu: AMD FX-9590, DRAM (Memory): 16GB, HD (hard drive): 2000GB, Price: 800

Low budget, AMD - cpu: AMD Athlon II, DRAM (Memory): 4GB, HD (hard drive): 500GB, Price: 400

You may have noticed that the cpu differes according to combination of two questions but the rest of parameters like memory, hard drive and price only depend on the budget.

Declear and initialize a DesktopPC object to hold all data about the PC you are going to suggest;

Print the result like this: "The suggested high budget intel family CPU PC is: " followed by your toString() returned value of your DesktopPC object.

Submit both your DesktopPC.java and PCAdvisor.java in a correctly named zip file following the submission guide.

Explanation / Answer

import java.util.*;
public class PCAdvisor
{
     public static void main(String[] args)
     {
         Scanner input=new Scanner(System.in);
         System.out.println("What is your budget(high or low)");
         String budget=input.next();
         System.out.println("What is your preferred CPU brand (Intel or AMD)");
         String brand=input.next();
         String cpu="";
         int dram=0,hd=0;
         double price=0.0;
         if(budget=="low")
         {
             if(brand!="Intel")
             {
                 cpu="AMD Athlon II";
             }
             else
             {
                 cpu="Intel celeron";

             }
                 dram=4;
                 hd=500;
                 price=400;
         }
         else
         {
             if(brand!="Intel")
             {
                 cpu="AMD FX-9590";
             }
             else
             {
                 cpu="Intel i7";
             }
                 dram=16;
                 hd=2000;
                 price=800;
         }
           DesktopPc desktopPc1 = new DesktopPc();
           desktopPc1.setCpu(cpu);
           desktopPc1.setMemoryCapacity(dram);
           desktopPc1.setHardDriveCapacity(hd);
           desktopPc1.setPrice(price);
         
         System.out.println("The suggested high budget intel family CPU PC is: "+desktopPc1.toString());
       
       
     }
}

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;
   }

}

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