Mindtap Programming, 1 Term (6 Months) Printed Access Card For Farrell's Java Programming, 9th
Mindtap Programming, 1 Term (6 Months) Printed Access Card For Farrell's Java Programming, 9th
9th Edition
ISBN: 9781337397117
Author: FARRELL, Joyce
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
D. S. Malik, Data Structures Using C++, 2nd Edition, 2010
Methods (Ch6) - Review 1. (The MyRoot method) Below is a manual implementation of the Math.sqrt() method in Java. There are two methods, method #1 which calculates the square root for positive integers, and method #2, which calculates the square root of positive doubles (also works for integers). public class SquareRoot { public static void main(String[] args) { } // implement a loop of your choice here // Method that calculates the square root of integer variables public static double myRoot(int number) { double root; root=number/2; double root old; do { root old root; root (root_old+number/root_old)/2; } while (Math.abs(root_old-root)>1.8E-6); return root; } // Method that calculates the square root of double variables public static double myRoot(double number) { double root; root number/2; double root_old; do { root old root; root (root_old+number/root_old)/2; while (Math.abs (root_old-root)>1.0E-6); return root; } } Program-it-Yourself: In the main method, create a program that…
I would like to know the main features about the following 3 key concepts:1. Backup Domain Controller (BDC)2. Access Control List (ACL)3. Dynamic Memory
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
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
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