Create a noarg constructor for Sandwich Inside the construct

Create a no-arg constructor for Sandwich. Inside the constructor, initialize the instance variables:
meat should be “turkey”
numOfSlicesOfTomato should be 3
lettuce should be true (lettuce = true)
3. Create a three parameter constructor for Sandwich. The Constructor declaration will look like:

4. Create getters and setters for all instance variables.

5. Create the printData method that will System.out.print (SOP) each of the instance variables.
6. Create a method that will calculate the price of the sandwich. A regular sandwich with no tomatoes is $3. There is a 25 cent extra charge for each tomato purchased.
a. Name the method: calculatePrice
b. Number of parameters: none
c. Return: double
d. Method body: calculate and return the price of the sandwich using the description above.

nside the main method
a. Create a Sandwich object using your zero parameter constructor and call it sandwich1. Do all of the following for sandwich1:
Use your setter methods for all three instance variables to change the values for sandwich1.
Call the printData method on sandwich1.
Call the calculatePrice method on sandwich1 and SOP the results.
b. Create a Sandwich object using your three parameter constructor and call it sandwich2. Do all of the following for sandwich2
Use valid and correct values to create sandwich2 using three parameter constructor.
Call the printData method on sandwich2.
Call the calculatePrice method on sandwich2 and SOP the results.
b. Use the Scanner class to
i. Ask the user for type of meat. Store this in a local variable called meat.
ii. Ask the user for number of tomatoes. Store this in a local variable called numTomatoes.
iii. Create a Sandwich object using your no-arg constructor and call it sandwich3.
iv. Use the setMeat method to set the type of meat to whatever the user typed in
v. Use the setNumTomatoes method to set the number of tomatoes based upon what the user typed in
vi. Call the printData method on sandwich3.
4. Compile, Save, and Run the SandwichTester class. If it works correctly, you should see a printout of 3 sandwiches, each containing a meat, a number of slices of tomato, and whether or not lettuce is included when you run the program. Lettuce will be true or false.

Are there any restrictions on any of the three data fields in Sandwich class? Add code into the setter method to insure only valid values are stored in each data field.

In SandwichTester.java, create SandwichCrazy using three parameter constructor and at least one invalid value. Use printData with SOP to show the contents of SandwichCrazy

Add two static variables to the Sandwich class to count how many sandwiches are sold and how many slices of tomato are used. Initialize each to 0. 8. Where do you add code to increment the sandwich counter? Determine this and then add code.

Where will you add code to count the tomato slices used? Once you figure out where, add the code.

Add a method to get the number of sandwiches and another method to get number of tomato slices used.

In SandwichTester at the very top of main, add a SOP that gets the number of sandwiches made and prints. Then get number of tomato slices and print.

In SandwichTester at the very bottom of main, add a SOP that gets the number of sandwiches made and prints. Then get number of tomato slices and print.

You should see 0 sandwiches and tomato at the start of main, but the last printed line should accurately total what your Tester used!

Solution



And this is the code used to run it. Not sure where to go from what I have now...

Create a no-arg constructor for Sandwich. Inside the constructor, initialize the instance variables: meat should be “turkey” numOfSlicesOfTomato should be 3 let
Create a no-arg constructor for Sandwich. Inside the constructor, initialize the instance variables: meat should be “turkey” numOfSlicesOfTomato should be 3 let

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site