Question

In: Computer Science

PLEASE EXPLAIN ANSWER. USING JAVA via jGRASP i am getting an error messge a. Create a...

PLEASE EXPLAIN ANSWER. USING JAVA via jGRASP

i am getting an error messge

a. Create a class named Sandwich. Data fields include a String for the main ingredient (such as tuna), a String for bread type (such as wheat), and a double for price (such as 4.99). Include methods to get and set values for each of these fields. Save the class as Sandwich.java.

b. Create an application named TestSandwich that instantiates one Sandwich object and demonstrates the use of the set and get methods. Save this application as TestSandwich.java.

Solutions

Expert Solution

//Java Code

public class Sandwich {
    private String mainIngredient;/*String for the main ingredient (such as tuna)*/
    private String breadType;/*String for bread type (such as wheat)*/
    private double price;/* double for price (such as 4.99)*/


    //getters and setters

    /**
     *
     * @return main ingredient
     */
    public String getMainIngredient() {
        return mainIngredient;
    }

    /**
     * set main ingredient
     * @param mainIngredient
     */
    public void setMainIngredient(String mainIngredient) {
        this.mainIngredient = mainIngredient;
    }

    /**
     *
     * @return bread type
     */
    public String getBreadType() {
        return breadType;
    }

    /**
     * set bread type
     * @param breadType
     */
    public void setBreadType(String breadType) {
        this.breadType = breadType;
    }

    /**
     *
     * @return price
     */
    public double getPrice() {
        return price;
    }

    /**
     * set price
     * @param price
     */
    public void setPrice(double price) {
        this.price = price;
    }


}
public class TestSandwich {
    public static void main(String[] args)
    {
        // instantiates one Sandwich object
        Sandwich sandwich = new Sandwich();
        //set the main ingredient
        sandwich.setMainIngredient("Tuna");
        // set bread type
        sandwich.setBreadType("Wheat");
        //set price
        sandwich.setPrice(4.99);
        //print object info using getters
        System.out.println("Main Ingredient: "+sandwich.getMainIngredient()+", Bread Type: "+sandwich.getBreadType()+", Price: "+sandwich.getPrice());
    }
}

//Output

//If you need any help regarding this solution....... please leave a comment..... thanks


Related Solutions

PLEASE EXPLAIN ANSWER. USING JAVA via jGRASP a. Create a class named Student that has fields...
PLEASE EXPLAIN ANSWER. USING JAVA via jGRASP a. Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method...
This is in Python I am getting an error when I run this program, also I...
This is in Python I am getting an error when I run this program, also I cannot get any output. Please help! #Input Section def main(): name=input("Please enter the customer's name:") age=int(input("Enter age of the customer: ")) number_of_traffic_violations=int(input("Enter the number of traffic violations: ")) if age <=15 and age >= 105: print('Invalid Entry') if number_of_traffic_violations <0: print('Invalid Entry') #Poccessing Section def Insurance(): if age < 25 and number_of_tickets >= 4 and riskCode == 1: insurancePrice = 480 elif age >=...
Syntax error in C. I am not familiar with C at all and I keep getting...
Syntax error in C. I am not familiar with C at all and I keep getting this one error "c error expected identifier or '(' before } token" Please show me where I made the error. The error is said to be on the very last line, so the very last bracket #include #include #include #include   int main(int argc, char*_argv[]) {     int input;     if (argc < 2)     {         input = promptUserInput();     }     else     {         input = (int)strtol(_argv[1],NULL, 10);     }     printResult(input);...
I am making a html game with phaser 3 I keep getting an error at line...
I am making a html game with phaser 3 I keep getting an error at line 53 of this code (expected ;) I have marked the line that needs to be fixed. whenever I add ; my whole code crashes const { Phaser } = require("./phaser.min"); var game; var gameOptions = {     tileSize: 200,     tileSpacing: 20,     boardSize: {     rows: 4,     cols: 4     }    }    window.onload = function() {     var gameConfig = {         width: gameOptions.boardSize.cols * (gameOptions.tileSize +             gameOptions.tileSpacing) + gameOptions.tileSpacing,...
I am getting an error at linen 57 and can't figure out how to fix it....
I am getting an error at linen 57 and can't figure out how to fix it. // Java program to read a CSV file and display the min, max, and average of numbers in it. import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Scanner; public class Main {     // method to determine and return the minimum number from the array     public static int minimum(int numbers[])     {         int minIdx = 0;         for(int i=1;i<numbers.length;i++)         {             if((minIdx...
Why am I getting the error: ValueError: The truth value of a Series is ambiguous. Use...
Why am I getting the error: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all() Fielding is a DataFrame, but I am not sure why I am getting this error. Any help would be appreciated! RAR = [] for i in range(0,len(Fielding)): position = (Fielding['POS'][i]) value = 0 if position == 'C': value = (9.0/150.0) * (Fielding['GS'][i]) elif position == 'SS': value = (7.0/150.0) * (Fielding['GS'][i]) elif position == '2B': value = (3.0/150.0)...
Getting an error with my for loop.  How do I correct it?  I am supposed to: Continuously prompt...
Getting an error with my for loop.  How do I correct it?  I am supposed to: Continuously prompt for the number of minutes of each Rental until the value falls between 60 and 7,200 inclusive. For one of the Rental objects, create a loop that displays Coupon good for 10percent off next rental as many times as there are full hours in the Rental. ///////////////////////////////RentalDemo package java1; import java.util.Scanner; public class RentalDemo { public static void main(String[] args) {    Rental object1 =...
Please create using only For loops, as simple as possible as I am attending Java1 Create...
Please create using only For loops, as simple as possible as I am attending Java1 Create two Java programs that do the following: a. Use a for loop to print the numbers below on a single line as shown. 1 2 4 8 16 32 64 128. b. Ask the user to enter numbers using the for loop.  First ask the user how many numbers they will be entering in. Print the sum and average of the entered numbers. c. Write...
In java, I keep getting the error below and I can't figure out what i'm doing...
In java, I keep getting the error below and I can't figure out what i'm doing wrong. Any help would be appreciated. 207: error: not a statement allocationMatrix[i][j];
I'm getting an error with my code on my EvenDemo class. I am supposed to have...
I'm getting an error with my code on my EvenDemo class. I am supposed to have two classes, Event and Event Demo. Below is my code.  What is a better way for me to write this? //******************************************************** // Event Class code //******************************************************** package java1; import java.util.Scanner; public class Event {    public final static double lowerPricePerGuest = 32.00;    public final static double higherPricePerGuest = 35.00;    public final static int cutOffValue = 50;    public boolean largeEvent;    private String...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT