Question: Please create a JAVA program by following all the directions below: Create 2 short programs in the assignment. The first program will create a class
Please create a JAVA program by following all the directions below:
Create 2 short programs in the assignment. The first program will create a class named ch4lastnameSandwich. It will have 3 variables: a String for the main ingredient (such as Tuna), a String for the bread type (such as wheat), and a Double for price (such as 4.99) . Include methods to get and set values of each of these fields. Save the class as ch4lastnameSandwich.java Compile this program but no need to Run it (no main method).
Create a second program named ch4lastnameTestSandwich that instantiates (creates) one Sandwich object, defines the 3 variables, prompts the user for the 3 variables, main ingredient, the bread type and the price, sets the 3 variables by accessing the first program (Ex. sandwich.setMainIngredient(ingredient); ) and then displays the 3 values (gets by accessing the first program, Ex. sandwich.getMainIngredient() ). Save the application as ch4lastnameTestSandwich.java Compile and Run this second program.
Example of the Program Run:
How to start the first program: (compile only) // your name // Ch4 Sandwich class Ch4lastnameSandwich { // define 3 variables private String mainIngredient; private String bread; private double price; // set and get mainIngredient public void setMainIngredient(String ingredient) // receives ingredient from the second program { mainIngredient = ingredient; } public String getMainIngredient() // returns mainIngredient to the second program { return mainIngredient; } // set and get bread // set and get price
How to start the second program: (compile and run) // your name // Ch4 TestSandwich import java.util.Scanner; class Ch4lastnameTestSandwich { public static void main (String args[]) { Ch4lastnameSandwich sandwich = new Ch4lastnameSandwich(); // instantiates (creates) one Sandwich object // define 3 variables String ingredient; String bread; double price; Scanner input = new Scanner(System.in); // prompts user System.out.print("Enter main sandwich ingredient >> "); ingredient = input.nextLine(); // finish the program
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
