Concept explainers
Explanation of Solution
a.
Program code:
Sandwich.java
//create a class Sandwitch
public class Sandwich
{
//create string variables
private String ingredient, breadType;
//create double variable
private double price;
//define a constructor
public Sandwich()
{
}
//define a method getIngredient()
public String getIngredient()
{
//return the ingredient
return ingredient;
}
//define a method setIngredient()
public void setIngredient(String ingredient)
{
//set value of the variable ingredient
this.ingredient = ingredient;
}
//define a method getBreadType()
public String getBreadType()
{
//return the breadType
return breadType;
}
//define a method setBreadType()
public void setBreadType(String breadType)
{
//set value of the variable breadType
this.breadType = breadType;
}
//define a method getPrice()
public double getPrice()
{
//return the price
return price;
}
//define a method setPrice()
public void setPrice(double price)
{
//set value of the variable price
this.price = price;
}
}
Explanation:
The above snippet of code is used create a class “Sandwich”. The class contain different static methods for store the details of sandwich. In the code,
- Define a class “Sandwich”
- Define the constructor “Sandwich()” method.
- Define the “getIngredient()” method.
- Return the value of the variable “ingredient”.
- Define the “setIngredient()” method.
- Set the value of the variable “ingredient”.
- Define the “getBreadType()” method.
- Return the value of the variable “breadType”.
- Define the “setBreadType ()” method...
Trending nowThis is a popular solution!
Chapter 3 Solutions
Java Programming (MindTap Course List)
- Write code to declare and create a Random class object (use the rand object reference variable). Then, using the nextInt method, create a list of expressions that produce random numbers in the following ranges, including the end points. Use the nextInt method's iteration that only takes an integer input.a. 0 to 10 b. 0 to 500c. 1 to 10d. 1 to 500e. 25 to 50f. -10 to 15 Write code to declare and create a Random class object (use the rand object reference variable). Then, using the nextInt method, create a list of expressions that produce random numbers in the following ranges, including the end points. Use the nextInt method's iteration that only takes an integer input.a. 0 to 10 b. 0 to 500c. 1 to 10d. 1 to 500e. 25 to 50f. -10 to 15arrow_forwardTOPICS: Using Classes and Objects MUST BE IN JAVA. PLEASE USE COMMENTS AND WRITE THE CODE IN SIMPLEST FORM. 1. Write an application that prompts for and reads the user’s first and last name (separately), then displays a string composed of the first four characters of the user’s last name, followed by the first two letters of the user’s first name, followed by a random number in the range of 10 to 99. Assume that the last name is at least four letters long. Similar algorithms are sometimes used to generate usernames for new computer accounts. Testing: If the inputs were “Michael” and “Jackson,” the output should look like “JackMi42.” Include several tests with different inputs, including your own name.arrow_forwardHelp me With this Java Taskarrow_forward
- Microsoft Visual C# 7th edition, programming Exercise 8-2. I need help, please, thanks. Create a program for Smalltown Regional Airport Flights that accepts either an integer flight number or string airport code from the options in Figure 8-33. Pass the user’s entry to one of two overloaded GetFlightInfo() methods, and then display a returned string with all the flight details. For example, if 201 was input, the output would be: Flight #201 AUS Austin Scheduled at: 0710 (note that there should be two spaces between 'Austin' and 'Scheduled'). The method version that accepts an integer looks up the airport code, name, and time of flight; the version that accepts a string description looks up the flight number, airport name, and time. The methods return a message if the flight is not found. For example, if 100 was input, the output should be Flight #100 was not found. If no flights were scheduled for the airport code entered, for example MCO, the message displayed should be Flight to MCO…arrow_forwardFor your homework assignment, build a simple application for use by a local retail store. Your program should have the following classes: Item: Represents an item a customer might buy at the store. It should have two attributes: a String for the item description and a float for the price. This class should also override the __str__ method in a nicely formatted way. Customer: Represents a customer at the store. It should have three attributes: a String for the customer's name, a Boolean for the customer's preferred status, and a list of 5 indexes to hold Item objects. Include the following methods: make_purchase: accepts a String and a double as parameters to represent the name and price of an item this customer is purchasing. Create a new Item object with this info and append it to the internal list. If the customer is a preferred customer based on the Boolean attribute's value, take 10% off the total sale price. __str__: Override this method to print the customer's name and every…arrow_forwardCreating Enumerations In this section, you create two enumerations that hold colors and car model types. You will use them as field types in a Car class and write a demonstration program that shows how the enumerations are used. 1. Open a new file in your text editor, and type the following Color enumeration: enum Color {BLACK, BLUE, GREEN, RED, WHITE, YELLOW}; 2. Save the file as Color.java. 3. Open a new file in your text editor, and create the following Model enumeration: enum Model {SEDAN, CONVERTIBLE, MINIVAN}; 4. Save the file as Model.java. Next, open a new file in your text editor, and start to define a Car class that holds three fields: a year, a model, and a color. public class Car { private int year; private Model model; private Color color; 5. Add a constructor for the Car class that accepts parameters that hold the values for year, model, and color as follows: public Car(int yr, Model m, Color c) { year = yr; model = m; color = c; } 6. Add a display()…arrow_forward
- There are a number of national and state parks available to tourists. Create a Park class. Include datamembers such as name of park, location, type of (i.e., national, state, local) facility, fee, number ofemployees, number of visitors recorded for the past 12 months, and annual budget. Write separateinstance methods that a) return a string representing name of the park, the location and type of park;b) return a string representing the name of the park, the location and facilities available; c) computecost per visitor based on annual budget and the number of visitors during the last 12 months; and d)compute revenue from fees for the past year based on number of visitors and fee. Also include aToString( ) method that returns all data members with appropriate labels. Create a second class totest your Park class.arrow_forwardCreate a class that holds data about a job applicant. Include a name, a phone number, and four Boolean fields that represent whether the applicant is skilled in each of the following areas: word processing, spreadsheets, databases, and graphics. Include a constructor that accepts values for each of the fields. Also include a get method for each field. Create an application that instantiates several job applicant objects and pass each in turn to a Boolean method that determines whether each applicant is qualified for an interview. Then, in the main() method, display an appropriate method for each applicant. A qualified applicant has at least three of the four skills. Save the files as JobApplicant.java and TestJobApplicants.java.arrow_forwardPlease provide the whole JAVA source code for attached screenshot's assignment.arrow_forward
- Create a class for Subject containing the Name of the subject and score of the subject. There should be following methods: 1. set: it will take two arguments name and score, and set the values of the attributes. If score is less than 0 or greater than 100.0 then a message should be displayed “Incorrect score” and score should be set to Zero. 2. set: it will take one double value as argument and set the value of score only. If score is less than 0 or greater than 100.0 then a message should be displayed “Incorrect score” and score should be set to Zero. 3. display: it will display the name and score of the subject. Like “Name : Math, Score: 99.9” 4. getScore: it will return the value of score. 5. greaterThan: it will take subject’s object as argument, compare the calling object’s score with argument object’s score and return true if the calling object has greater score. Create a class “Main” having main method to perform following tasks. 1. Create two objects of Subject…arrow_forwardPYTHON ONLY PLZZZ Create a class object with the following attributes and actions: Class Name Class number Classroom Semester Level Subject Actions: Store a class list Print the class list as follows: Class name Class Number Semester Level Subject Test your object: Ask the user for all the information and to enter at least 3 classes test using all the actions of the object print using the to string action Describe the numbers and text you print. Do not just print numbers or strings to the screen explain what each number represents.arrow_forwardMicrosoft Visual C# 7th edition. need help, please. Thanks In previous chapters, you created applications for Marshall’s Murals. Now, modify the version of the MarshallsRevenue program created in Chapter 5 so that after mural data entry is complete, the user is prompted for the appropriate number of customer names for both the interior and exterior murals and a code for each that indicates the mural style: L for landscape S for seascape A for abstract C for children’s O for other When a code is invalid, re-prompt the user for a valid code continuously. For example, if Y is input, output Y is not a valid code, and re-prompt the user until a valid code is entered. After data entry is complete, display a count of each type of mural. For example the output should be in the following format with the correct number next to each mural type: The interior murals scheduled are: Landscape 1 Seascape 2 Abstract 1 Children's 3 Other 9 The exterior murals scheduled are: Landscape 4 Seascape 0…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,