Question

Write a program that meets the following requirements: Sandwich Class Create a class called Sandwich which has the following instance variables. No other instance variables should be used: - ingredi...

Write a program that meets the following requirements:

Sandwich Class

  1. Create a class called Sandwich which has the following instance variables. No other instance variables should be used:

- ingredients (an array of up to 10 ingredients, such as ham, capicola, American cheese, lettuce, tomato)

-condiments (an array of up to 5 condiments, such as mayonnaise, oil, vinegar and mustard)

  1. Create a two argument constructor
  2. Write the getters and setters for the instance variables
  3. Override the toString method using the example shown above.

There should be NO main method in the Sandwich class.

SandwichMaker Class

  1. Create a class called SandwichMaker which constructs 5 different Sandwich objects
  2. Add each Sandwich object to an array
  3. Use a for loop to SOP each Sandwich reference

  • You should use the class names of Sandwich and SandwichMaker
  • Using Java or eclipse
0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

import java.util.Arrays;

public class Sandwich{

private String ingredients[];

private String condiments[];

public Sandwich(String ingredients[], String condiments[]){

this.ingredients = ingredients;

this.condiments = condiments;

}

/**

* @param ingredients the ingredients to set

*/

public void setIngredients(String[] ingredients) {

this.ingredients = ingredients;

}

/**

* @param condiments the condiments to set

*/

public void setCondiments(String[] condiments) {

this.condiments = condiments;

}

/**

* @return the ingredients

*/

public String[] getIngredients() {

return ingredients;

}

/**

* @return the condiments

*/

public String[] getCondiments() {

return condiments;

}

public String toString(){

return "Ingredients: "+Arrays.toString(ingredients)+"\nCondiments: "+Arrays.toString(condiments);

}

}

public class SandwichMaker{

public static void main(String[] args) {

Sandwich sandwiches[] = new Sandwich[5];

String ingredients1[] = {"ham", "capicola", "American cheese", "lettuce", "tomato"};

String condiments1[] = {"mayonnaise", "oil", "vinegar", "mustard"};

sandwiches[0] = new Sandwich(ingredients1, condiments1);

String ingredients2[] = {"ham", "capicola", "American cheese"};

String condiments2[] = {"mayonnaise", "oil", "vinegar"};

sandwiches[1] = new Sandwich(ingredients2, condiments2);

sandwiches[2] = new Sandwich(ingredients1, condiments2);

sandwiches[3] = new Sandwich(ingredients2, condiments2);

sandwiches[4] = new Sandwich(ingredients1, condiments2);

for(int i=0; i<sandwiches.length; i++){

System.out.println(sandwiches[i]);

}

}

}

Add a comment
Know the answer?
Add Answer to:
Write a program that meets the following requirements: Sandwich Class Create a class called Sandwich which has the following instance variables. No other instance variables should be used: - ingredi...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need help to create general class Classes Data Element - Ticket Create an abstract class called...

    Need help to create general class Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...

  • Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram)

    Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...

  • Course, Schedule, and ScheduleTester (100%) Write a JAVA program that meets the following requirements: Course Class Cr...

    Course, Schedule, and ScheduleTester (100%) Write a JAVA program that meets the following requirements: Course Class Create a class called Course. It will not have a main method; it is a business class. Put in your documentation comments at the top. Be sure to include your name. Course must have the following instance variables named as shown in the table: Variable name Description crn A unique number given each semester to a section (stands for Course Registration Number) subject A...

  • Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type...

    Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type double that stores the amount of the payment and appropriate accessor (getPaymentAmount() ) and mutator methods. Also create a method named paymentDetails that outputs an English sentence to describe the amount of the payment. Override toString() method to call the paymentDetails() method to print the contents of payment amount and any other details not included in paymentDetails(). Define a class named CashPayment that is...

  • Ticket Hierarchy Ticket Abstract Class Create a static variable called nextTicketId. This is an integer representing...

    Ticket Hierarchy Ticket Abstract Class Create a static variable called nextTicketId. This is an integer representing the next available integer for the ticketId                                 private static int nextTicketId = 1000; getPrice method: Abstract method that returns a double. NOTE: Do not make price an instance variable in Ticket. Noargument constructor: Sets event name to “none”, event location to “none”, and ticket id to 0. Create a constructor that accepts the event name and event location as parameters. Set the ticket Id...

  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

  • In C++ Write a program that contains a class called VideoGame. The class should contain the...

    In C++ Write a program that contains a class called VideoGame. The class should contain the member variables: Name price rating Specifications: Dynamically allocate all member variables. Write get/set methods for all member variables. Write a constructor that takes three parameters and initializes the member variables. Write a destructor. Add code to the destructor. In addition to any other code you may put in the destructor you should also add a cout statement that will print the message “Destructor Called”....

  • Programming Assignment 1 Write a class called Clock. Your class should have 3 instance variables, one...

    Programming Assignment 1 Write a class called Clock. Your class should have 3 instance variables, one for the hour, one for the minute and one for the second. Your class should have the following methods: A default constructor that takes no parameters (make sure this constructor assigns values to the instance variables) A constructor that takes 3 parameters, one for each instance variable A mutator method called setHour which takes a single integer parameter. This method sets the value of...

  • Create a java class for an object called Student which contains the following private attributes: a...

    Create a java class for an object called Student which contains the following private attributes: a given name (String), a surname (family name) (String), a student ID number (an 8 digit number, String or int) which does not begin with 0. There should be a constructor that accepts two name parameters (given and family names) and an overloaded constructor accepting two name parameters and a student number. The constructor taking two parameters should assign a random number of 8 digits....

  • Part I (20%) [File: Student.java] Create a class called Student that has the following stored properties:...

    Part I (20%) [File: Student.java] Create a class called Student that has the following stored properties: • StudentID • First Name • Last Name Class Student should have read/write properties, constructor(s) and should implement the Academic interface. For academic methods, return zero for average, zero for credits and false for graduate. Also implement the toString() method that returns the above information as a String. Part II (5%) [File: Academic.java] Create an interface Academic that declares three methods: 1. average -...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT