Java Programming, Loose-leaf Version
Java Programming, Loose-leaf Version
8th Edition
ISBN: 9781337685917
Author: Joyce Farrell
Publisher: Cengage Learning
bartleby

Concept explainers

bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 3, Problem 11PE

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...

Blurred answer
Students have asked these similar questions
My professor has given me additional information for this question:   Create a class named CollegeCourse that includes data fields that hold thedepartment (for example, ENG), the course number (for example, 101), thecredits (for example, 3), and the fee for the course (for example, $360). All of thefields are required as arguments to the constructor, except for the fee, which iscalculated at $120 per credit hour. Include a display() method that displaysthe course data. Create a subclass named LabCourse that adds $50 to the coursefee. Override the parent class display() method to indicate that the course isa lab course and to display all the data. Write an application named UseCoursethat prompts the user for course information. If the user enters a class in any ofthe following departments, create a LabCourse: BIO, CHM, CIS, or PHY. If theuser enters any other department, create a CollegeCourse that does not includethe lab fee. Then display the course data. Save the files as…
a. Create a class named Pizza. Data fields include a String for toppings (such as “pepperoni”), an integer for diameter in inches (such as 18), and a double for the price (such as P699.00). Include methods to get and set values for each of these fields. Save the class as Pizza.java. b. Create an application named TestPizza that instantiates one Pizza object and demonstrates the use of the Pizza set and get methods. Save this application as TestPizza.java.
Program #5: a. Create a class named Circle with fields named radius, diameter, and area. Include a constructor that sets the radius to 1 and calculates the other two values. Also include methods named setRadius()and getRadius(). The setRadius() method not only sets the radius but also calculates the other two values. (The diameter of a circle is twice the radius, and the area of a circle is pi multiplied by the square of the radius. Use the Math class PI constant for this calculation.) Save the class as Circle.java. b. Create a class named TestCircle whose main() method declares several Circle objects. Using the setRadius() method, assign one Circle a small radius value, and assign another a larger radius value. Do not assign a value to the radius of the third circle; instead, retain the value assigned at construction. Display all the values for all the Circle objects. Save the application as TestCircle.java. I forgot to include "b" on my initial question submission. Secondly - is "b"…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY