Question: This is one problem with two parts... I need them both answered, please. In java. Today we look at scoping (private vs. public), constructors, and


This is one problem with two parts... I need them both answered, please. In java.
Today we look at scoping (private vs. public), constructors, and how information is partitioned between classes by looking at a set of classes that work together. Regarding the last item, in Part 2, we will look at two classes that make use of one another with the second class storing an array of objects of the first class. So, we will also get to work with more complex arrays than arrays of primitives. Part 1 Scoping and Multiple Constructors Create a class named Pizza that stores information about a single pizza. It should contain the following: Private instance variables to store the size of the pizza (either small, medium, or large), the number of meat toppings, the number of veggie toppings and whether or not the pizza should be vegan-friendly in which case you must make sure that the number of meat toppings is 0). Discuss with your partner what the difference between a private and public instance variable is. Constructors that set all of the instance variables. One constructor should be a no-arg constructor, with defaults of medium, no toppings, non-vegan. At least one other constructor should enable you to give all the private instance variables a value when you create the object. You should also include error checking to make sure the values you are setting are legitimate (e.g., there is no such a size pizza as "grande"). Discuss with your partner why there is more than one kind of constructor and when will each constructor be used. Public methods to get and set the instance variables. Discuss with your partner what would happen if these methods set to private and why these accessor and getter methods needed. A public method named calcCost that returns a double that is the cost of the pizza. Pizza cost is determined by: Small: $10 Medium: $12 Large: $14 Each meat topping cost $2 and each veggie topping cost $1 If the pizza is vegan, it costs an additional $2 A public method named getDescription that returns a String containing the pizza size, whether it is vegan or not, quantity of each topping, and the pizza cost as calculated by calcCost. Use the provided class named Pizzaria, (download from above) to test your Pizza class. The Pizzaria class provides test code to create several pizzas and outputs their descriptions Part 2 You will create three classes, the first two being Student and LineAtOffice Hour. The instances of the first class defines a single student while an instance of the second class defines a line of students waiting to see an instructor in their office hour. The Student class should have the following: Private instance variables to store the first and last name of the student. A constructor that sets all of the instance variables. You do not need to write a no-arg constructor in addition to the constructor that sets all of the instance variables. Public methods to get and set the instance variables and a method fullName() that returns the full name of the student (first then last) as a String (i.e., does not print it out to the screen). The LineAtOffice Hour class holds Student objects in a line and has methods to manipulate this line. The LineAtOffice Hour class holds Student objects in a line and has methods to manipulate this line. Private instance variables: o an array of Students called line. o an integer N representing the number of students in the line. o an integer back representing the index of the last student in line. Constructors: o no-argument constructor which sets the length of the line to 5, however the line should start off empty. o a constructor that takes an array of Student objects as argument and fills the line variable with up to 5 Students (but can also take as input an array of fewer than 5 Student objects). If the given input argument array has more than 5 Students, then you should populate the line with the first 5 Students out of the input array. Public methods: o a method called isEmpty which returns true if the line is empty. o a method called isFull which returns true if the line is full. o a method called size which returns the number of students waiting in line. o a method called enterline which takes a Student object as the argument and puts it at the back of the line (i.e. behind the last student currently in line). This method does not need to return anything. Note: if the line is full, the Student should not be placed in the line and should be rejected with an appropriate message. o a method called seeTeacher which removes the Student object from the front of the line (i.e. the student who is currently first in line gets to see the teacher when this method is called) and returns the Student object. Note: the remaining students should move toward the front of the line as result of this method being called. o a method called whosInLine which returns a list (as a String) of all the names of the Students in the line, in the order they are in line (the first student first, a comma, the second name, and so on). Finally, write a driver class TestLine that will create a LineAtOffice Hour object, fill it with Student objects, and test that the methods of LineAtOffice Hour function correctly
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
