
Concept explainers
Please help with the following:
Code in Java keep the code as simple as possible do not use arrays nor parseItnt StringBuilder etc keep it very simple.
Class pizza
This class consists of the following fields.
String name
double price
String topping1
String topping2
String topping3
In the constructor, you will ask for four variables: String name, String topping1, String topping2, String topping3. These fields will be sat immediately using the proper setter methods. Also, in the constructor, another method will be called. Namely, the private void setPrice() method.
The setPrice method, will check if any of the toppings is equals to the empty string ”” and set the price of the pizza depending on the count of the none empty fields according to the following:
no toppings the price will be sat to 10$.
With 1 topping the price will be 15$
With 2 topping the price will be 17.5$
With 3 topping the price will be 22$
All fields have to be private thus they have the proper setter and getter methods for each.
Class Person
Each person has the following fields:
private String name
private double age
private Pizza pizza
Here, you will only set the name and the age of the person using the constructor. The class should have proper setters and getters for each of the fields. However, you will need to set the values using the this.keyword expression.
This class also has a method called order(). Order is a public method that is responsible for initializing the pizza the person orders. This method works the following way.
When the order method is called, a message will be displayed on the screen asking the person to order a pizza by asking them to input the name of the pizza they want together the name of the three toppings they wish to have on their pizza. These will be stored in four variables. Then a new pizza object in the method will be created using the elements that the user inputted via the scanner. Keep in mind this all happens in the Person class.
However, you keep the field in the global variables. And just do the memory allocation within the method. Like this:
In the global fields you still need to define : Pizza pizza;
then
public void order(){ do a bunch of stuff scanner input....
pizza=new pizza...... do a bunch of stuff
}
There is another thing the order method should do too. All of the things that I described above should be repeated until the user inputs the string ”yes”. So, when the order method is called, the user will be asked to input what they want to eat. Then once the object has been created, the user is asked if they are sure that this is the pizza they want, and until they do not input ”yes”, they will be asked to input their toppings and the pizza object will be
reinitialized.
The main Class Main
Three people decide to go to a restaurant. They all sit around the same table. Initialize these people without using the scanner in the main method (manually the way you like). Then, for each of the people call the order method. Once the order method is called and terminated successfully. You have to print the pizza object that the person ordered. So, you will call person.getPizza() and then print the object. This means you have to have a toString method for the pizza class that displays the name of the pizza and its toppings as one string.

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

- Help me With this Java Taskarrow_forwarddef area(side1, side2): return side1 * side2s1 = 12s2 = 6Identify the statements that correctly call the area function. Select ALL that apply. Question options: area(s1,s2) answer = area(s1,s2) print(f'The area is {area(s1,s2)}') result = area(side1,side2)arrow_forwardAttributes item_name (string) item_price (int) item_quantity (int) Default constructor Initializes item's name="none", item's price = 0, item's quantity=0 Method print_item_cost() Ex of print_item_cost() output: Bottled Water 10 @ $1 = $10 in the main section of your code, prompt the user for two items and create two objects of the ItemToPurchase class. Exc Item 1 Enter the item name: Chocolate Chips Enter the item price: 3 Enter the item quantity: 1 Item 2 Enter the item name: Bottled Water Enter the item price: 1 Enter the item quantity: 10 Add the costs of the two items together and output the total cost Ex TOTAL COST Chocolate Chips 1 @ $3-$3 Bottled Water 10 @ $1= $10 Total: $13arrow_forward
- Please help with the following: Code in Java keep the code as simple as possible do not use arrays nor parseItnt StringBuilder etc keep it very simple. Class pizza This class consists of the following fields. 1. String name2. double price3. String topping1 4. String topping2 5. String topping3 In the constructor, you will ask for four variables: String name, String topping1, String topping2, String topping3. These fields will be sat immediately using the proper setter methods. Also, in the constructor, another method will be called. Namely, the private void setPrice() method. The setPrice method, will check if any of the toppings is equals to the empty string ”” and set the price of the pizza depending on the count of the none empty fields according to the following: no toppings the price will be sat to 10$. With 1 topping the price will be 15$With 2 topping the price will be 17.5$With 3 topping the price will be 22$ All fields have to be private thus they have the proper setter and…arrow_forwardpublic class Accumulator { private int total private String name; public Accummulator (string name , int total) { this .name = name; this .total=total; } } 3. In a main method, create an object of Accumulator with the name as "Mary" and total as 100.arrow_forwardpython class Student:def __init__(self, first, last, gpa):self.first = first # first nameself.last = last # last nameself.gpa = gpa # grade point average def get_gpa(self):return self.gpa def get_last(self):return self.last def to_string(self):return self.first + ' ' + self.last + ' (GPA: ' + str(self.gpa) + ')' class Course:def __init__(self):self.roster = [] # list of Student objects def drop_student(self, student):# Type your code here def add_student(self, student):self.roster.append(student) def count_students(self):return len(self.roster) if __name__ == "__main__":course = Course() course.add_student(Student('Henry', 'Nguyen', 3.5))course.add_student(Student('Brenda', 'Stern', 2.0))course.add_student(Student('Lynda', 'Robinson', 3.2))course.add_student(Student('Sonya', 'King', 3.9)) print('Course size:', course.count_students(),'students')course.drop_student('Stern')print('Course size after drop:', course.count_students(),'students')arrow_forward
- #this is a python program #topic: OOP Design the Country class so that the code gives the expected output. [You are not allowed to change the code below] # Write your Class Code here country = Country() print('Name:',country.name) print('Continent:',country.continent) print('Capital:',country.capital) print('Fifa Ranking:',country.fifa_ranking) print('===================') country.name = “Belgium” country.continent = “Europe” country.capital = “Brussels” country.fifa_ranking = 1 print('Name:',country.name) print('Continent:',country.continent) print('Capital:',country.capital) print('Fifa Ranking:',country.fifa_ranking) Output: Name: Bangladesh Continent: Asia Capital: Dhaka Fifa Ranking: 187 =================== Name: Belgium Continent: Europe Capital: Brussels Fifa Ranking: 1arrow_forward# 17 and Java Programarrow_forwardA object which overloads the () operator is called a _______. Group of answer choices overload operator function object Overload object constructor objectarrow_forward
- public String firstAndLast(String str) { //declare and create your first char //declare and create your second char //return your first and last char as a String }arrow_forwardTrue or False ___(10) The term length( ) in the String class is a method that returns the total number of characters in a string. ___(11) If variable name contains string “Valentino”, then the expression name.substring(3, 5) is “ent”. ___(12) Java initializes all variables when they are declared.arrow_forwardCheck the following method header: public void displayValue(int value) { Which code segment contains a legal call to the displayValue method if x is declared : int x=7;? a) displayValue(x); b) x= displayValue( ) ; c) displayValue(int x); d) displayValue ( ) ; e) displayMethod Value ( )arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





