PF1 LAB7 Designing, Creating and Using our first Java Class NOTE: Place your sol
ID: 3708967 • Letter: P
Question
PF1 LAB7 Designing, Creating and Using our first Java Class NOTE: Place your solution for this lab in ~/PF1/lab7/Lab7.java OBJECTIVES: 1) Further practice using the Java compiler and RTE by creating a Java application. 2) Designing, creating and using Java classes of our own. PROCEDURE: You have been promoted to Chief Technology Officer of the local Taco Bell. You have heard that there will soon be a major breakthrough in burrito making technology with the upcoming announcement of an Object Oriented Burrito Maker (OOBM). You want your Taco Bell to be on the cutting edge with this new technology. So your job is to create a program that will create burrito objects that will ultimately be delivered over a local network to the OOBM for production. For now, you are to design a "Burrito" class that will contain all of the information needed to serve up a custom made burrito. The burritos are made of beans, beef, cheese and salsa. Also, we want to associate a customer name with each burrito object that we create so that we can call them by name when the OOBM chucks their custom made burrito onto an awaiting plastic tray. Yum! Your Burrito class should provide: 1) A constructor that will create a "default" burrito with two units of beans and one unit each of beef, cheese and salsa. This constructor does not receive any parameters. The customer name which is associated with this burrito should be "No Name". 2) A custom constructor that will allow a custom burrito to be constructed based on parameters which specify the amount of beans, beef, cheese, salsa and the customer name. 3) A method called "print_order" which we can use to ask our burrito objects to print out their ingredients and associated customer name. 4) A method called "weight" which we can use to ask our burrito to tell us how much it weighs. (assume one ounce per unit of each of the ingredients) This method should not perform any output, but should instead simply return the weight of the burrito. You should write a main method to create two burrito objects. The first burrito will be a "default" burrito and the second one will be custom made. The input values for the custom burrito are given below in the example. These will be hard coded into your main method. The test program will also invoke the internal mechanisms within each burrito to print the ingredients and weight as shown below. Late breaking news! In response to market demand, you need to also include a way to update a burrito object after it has been created, but prior to sending it to the OOBM. Include the capability to double the ingredients of the burrito by invoking a method called "gutBuster" which will be part of the burrito object. In your testing, create an initial (default) burrito, ask the burrito object to print its contents, and its weight, then Super Size the burrito via the gutBuster method and then again ask the burrito to print its contents and weight. Then repeat the same six steps (create, print, weigh, gutBuster, print, weigh) for a custom burrito which matches the ingredients list that is shown below. Notes: 1) Protect the data in this object from modification (except for via the mechanisms you provide). 2) If you're wondering which block of code should generate the output(s), examine the sample piece of code below and the sample output it generates. That will show where the output is not coming from! Also, the constructor produces no output. Here is a sample piece of code which you will integrate into your main method: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Create a custom burrito! Burrito b1 = new Burrito(8,2,3,1,"Big Al"); b1.print_order(); System.out.println("The burrito weighs " + b1.weight() + " ounces."); b1.gutBuster(); b1.print_order(); System.out.println("The burrito weighs " + b1.weight() + " ounces."); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ When run, it produces the following output: (your program output should be very similar) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Big Al's burrito will be made of: 8 ounce(s) of beans 2 ounce(s) of beef 3 ounce(s) of cheese 1 ounce(s) of salsa The burrito weighs 14 ounces. Invoking the Gut Buster Special!!! Big Al's burrito will be made of: 16 ounce(s) of beans 4 ounce(s) of beef 6 ounce(s) of cheese 2 ounce(s) of salsa The burrito weighs 28 ounces. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Explanation / Answer
Here is your required Burrito class. Everything is defined exactly as specified and well explained using Javadoc comments. Go through the code and let me know if you have any doubts. Thanks.
//Burrito.java
public class Burrito {
// attributes specifying units of each ingredients
private int beans;
private int beef;
private int cheese;
private int salsa;
private String customerName;
/**
* Default constructor
*/
public Burrito() {
/**
* Default values
*/
beans = 2;
beef = 1;
cheese = 1;
salsa = 1;
customerName = "No Name";
}
/**
* constructor to initialize all fields
*/
public Burrito(int beans, int beef, int cheese, int salsa,
String customerName) {
/**
* Initializing all fields
*/
this.beans = beans;
this.beef = beef;
this.cheese = cheese;
this.salsa = salsa;
this.customerName = customerName;
}
/**
* method to display the contents of the Burrito
*/
public void print_order() {
System.out.println(customerName + "'s burrito will be made of:");
System.out.println(beans + " ounce(s) of beans");
System.out.println(beef + " ounce(s) of beef");
System.out.println(cheese + " ounce(s) of cheese");
System.out.println(salsa + " ounce(s) of salsa");
}
/**
* method to return the weight of the burrito
* @return - sum total of all units of ingredients
*/
public int weight() {
return beans + beef + salsa + cheese;
}
/**
* special method to double all ingredients
*/
public void gutBuster() {
beans = 2 * beans;
beef = 2 * beef;
cheese = 2 * cheese;
salsa = 2 * salsa;
System.out.println("Invoking the Gut Buster Special!!!");
}
public static void main(String[] args) {
/**
* Creating a burrito using default constructor
*/
Burrito b1 = new Burrito();
b1.print_order();
System.out.println("The burrito weighs " + b1.weight() + " ounce(s)");
b1.gutBuster();
b1.print_order();
System.out.println("The burrito weighs " + b1.weight() + " ounce(s)");
/**
* Creating a burrito using parameterized constructor
*/
Burrito b2 = new Burrito(8, 2, 3, 1, "Big Al");
b2.print_order();
System.out.println("The burrito weighs " + b2.weight() + " ounce(s)");
b2.gutBuster();
b2.print_order();
System.out.println("The burrito weighs " + b2.weight() + " ounce(s)");
}
}
/*OUTPUT*/
No Name's burrito will be made of:
2 ounce(s) of beans
1 ounce(s) of beef
1 ounce(s) of cheese
1 ounce(s) of salsa
The burrito weighs 5 ounce(s)
Invoking the Gut Buster Special!!!
No Name's burrito will be made of:
4 ounce(s) of beans
2 ounce(s) of beef
2 ounce(s) of cheese
2 ounce(s) of salsa
The burrito weighs 10 ounce(s)
Big Al's burrito will be made of:
8 ounce(s) of beans
2 ounce(s) of beef
3 ounce(s) of cheese
1 ounce(s) of salsa
The burrito weighs 14 ounce(s)
Invoking the Gut Buster Special!!!
Big Al's burrito will be made of:
16 ounce(s) of beans
4 ounce(s) of beef
6 ounce(s) of cheese
2 ounce(s) of salsa
The burrito weighs 28 ounce(s)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.