Question

In: Computer Science

2 Builder Pattern java -set up builder pattern to run this RobotBuilder builder = new RobotBuilder();...

2 Builder Pattern
java
-set up builder pattern to run this 

RobotBuilder builder = new RobotBuilder();
builder.setRam(1000);
builder.setStorage(10000);
builder.setWheels(2);
builder.setName("Robo Ron");
Robot robot = builder.build();

builder = new RobotBuilder();
builder.setName("Robo Rene");
builder.setRam(500);
builder.setStorage(15000);
Robot robot2 = builder.build();

Solutions

Expert Solution

class Robot{
   private int ram;
   private int storage;
   private int wheels;
   private String name;
   /**
   * @return the ram
   */
   public int getRam() {
       return ram;
   }
   /**
   * @param aRam the ram to set
   */
   public void setRam(int aRam) {
       ram = aRam;
   }
   /**
   * @return the storage
   */
   public int getStorage() {
       return storage;
   }
   /**
   * @param aStorage the storage to set
   */
   public void setStorage(int aStorage) {
       storage = aStorage;
   }
   /**
   * @return the weheel
   */
   public int getWheels() {
       return wheels;
   }
   /**
   * @param aWeheel the weheel to set
   */
   public void setWheels(int aWeheel) {
       wheels = aWeheel;
   }
   /**
   * @return the name
   */
   public String getName() {
       return name;
   }
   /**
   * @param aName the name to set
   */
   public void setName(String aName) {
       name = aName;
   }
   /**
   * @param aRam
   * @param aStorage
   * @param aWheels
   * @param aName
   */
   public Robot(int aRam, int aStorage, int aWheels, String aName) {
       super();
       ram = aRam;
       storage = aStorage;
       wheels = aWheels;
       name = aName;
   }
   /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Robot [ram=" + ram + ", storage=" + storage + ", wheels=" + wheels + ", name=" + name + "]";
   }
  
}
class RobotBuilder{
   private int ram;
   private int storage;
   private int wheels;
   private String name;
   /**
   * @return the ram
   */
   public int getRam() {
       return ram;
   }
   /**
   * @param aRam the ram to set
   */
   public void setRam(int aRam) {
       ram = aRam;
   }
   /**
   * @return the storage
   */
   public int getStorage() {
       return storage;
   }
   /**
   * @param aStorage the storage to set
   */
   public void setStorage(int aStorage) {
       storage = aStorage;
   }
   /**
   * @return the weheel
   */
   public int getWheels() {
       return wheels;
   }
   /**
   * @param aWeheel the weheel to set
   */
   public void setWheels(int aWeheel) {
       wheels = aWeheel;
   }
   /**
   * @return the name
   */
   public String getName() {
       return name;
   }
   /**
   * @param aName the name to set
   */
   public void setName(String aName) {
       name = aName;
   }
   public Robot build(){
       return new Robot(ram,storage,wheels,name);
   }
   /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "RobotBuilder [ram=" + ram + ", storage=" + storage + ", wheels=" + wheels + ", name=" + name + "]";
   }

}
public class TestBuilder {
   public static void main(String[] args) {
       RobotBuilder builder = new RobotBuilder();
       builder.setRam(1000);
       builder.setStorage(10000);
       builder.setWheels(2);
       builder.setName("Robo Ron");
       Robot robot = builder.build();

       builder = new RobotBuilder();
       builder.setName("Robo Rene");
       builder.setRam(500);
       builder.setStorage(15000);
       Robot robot2 = builder.build();
      
       System.out.println(robot);
       System.out.println(robot2);
      
      
   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

Exercise 3.1.5: Expressing sets in set builder notation. About Express each set using set builder notation....
Exercise 3.1.5: Expressing sets in set builder notation. About Express each set using set builder notation. Then if the set is finite, give its cardinality. Otherwise, indicate that the set is infinite. PLEASE show some explanation how you got answer. Thanks! (a) {-2, -1, 0, 1, 2} (b) { 3, 6, 9, 12, .... } (c) { -3, -1, 1, 3, 5, 7, 9 } (d) { 0, 10, 20, 30, ...., 1000 } Exercise 3.2.4: A subset of a...
2 Write a Java program called Pattern that prints an 8-by-8 checker box pattern using an...
2 Write a Java program called Pattern that prints an 8-by-8 checker box pattern using an if loop.
Create a new Java project, name it “Quiz02”. (This is a JAVA Programming question, thumbs up...
Create a new Java project, name it “Quiz02”. (This is a JAVA Programming question, thumbs up quick and correct answer) 1) Create a java class Traveler that has four data members, String name, Date bDate, int id and int noOfDependens. Generate the following: 1- Getters and Setters. 2- Four parametrize constructor to initialize the four data members above. 3- toString() method. Create a java class Flight that has four data members, String number, String destination, int capacity, and ArrayList travelers....
I need to set up and run a goodness of fit test. I am trying to...
I need to set up and run a goodness of fit test. I am trying to learn more about the type of novels that people prefer to read. Please include null and alternative hypotheses. Show all work and please explain if you use any excel tests. Total number of responses is 30. Romance: 18 Sci - Fi: 7 Fiction: 5
The Clearwater National Bank is planning to set up a new branch.This new branch is...
The Clearwater National Bank is planning to set up a new branch. This new branch is anticipated to generate 5 percent of the total business of the bank after it is opened. The bank also expects the return for this branch to be 15 percent with a standard deviation of 5 percent. Currently the bank has a 10 percent rate of return with a standard deviation of 5 percent. The correlation between the bank's current return and returns on the...
Why isn't set-builder notation used for defining functions?
In set-builder notation, we use | to show givens, yet there isn't really a standard symbol to show givens when defining functions. So why don't we just import the symbol from set-builder notation so that it becomes standardised?
The following Java code is set up to ask how many people are attending a meeting...
The following Java code is set up to ask how many people are attending a meeting and checks these user generate responses with replies, using the do while setup. To end the loop you type 0, change this to accept the answer "Y" to continue the loop after every response and "N" to end the loop with every case type. (Y,y,N,n) Meeting.java ------ import java.util.Scanner; public class Meeting {    public static void main(String[] args) {        Scanner input...
An activity-based costing system is generally easier to set up and run than a traditional cost...
An activity-based costing system is generally easier to set up and run than a traditional cost system. True False
Trademark Inc. is planning to set up a new manufacturing plant in New York to produce...
Trademark Inc. is planning to set up a new manufacturing plant in New York to produce safety tools. The company bought some land six years ago for $4.3 million in anticipation of using it as a warehouse and distribution site, but the company has since decided to rent these facilities from a competitor instead. If the land were sold today, the company would sell for $4.6 million on an after-tax basis. In four years, the land could be sold for...
Define target run-up? What are some possible reasons for run-up?
Define target run-up? What are some possible reasons for run-up?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT