Java Programming
Java Programming
8th Edition
ISBN: 9781305981829
Author: Joyce Farrell
Publisher: Cengage Limited
bartleby

Concept explainers

bartleby

Videos

Question
Book Icon
Chapter 4, Problem 5PE

a.

Program Plan Intro

Bread

Program Plan:

Bread.java:

  • Define the class “Bread”.
    • Declare and initialize the required variable.
    • Definition of constructor.
      • Assign the “bread” and “cal” to the “breadName” and “calories”.
      • Definition of “getBreadType()”.
        • Return the value of “breadName”.
      • Definition of method “getCaloriesPerSlice()”
        • Return the value of “calories”

BreadTest.java:

  • Define the class “BreadTest”.
    • Define the main method.
      • Create an object for bread.
      • Call the method bread.
    • Definition of method “display()”.
      • Get the type of bread and calories per slice by calling the method “getBreadType()” and “getCaloriesPerSlice()”.
      • Print the result.

b.

Program Plan Intro

SandwichFilling.java

Program Plan:

SandwichFilling.java:

  • Define the class “SandwichFilling”.
    • Declare and initialize the required variable.
    • Definition of constructor.
      • Assign the “fill” and “calories” value to the variables.
    • Definition of method “getSandwichFilling()”.
      • Return the value filling.
    • Definition of method “getCalories()”.
      • Return the value calories.

TestSandwichFilling.java:

  • Define the class “TestSandwichFilling”.
    • Define the main method.
      • Create an object for “SandwichFilling”.
      • Call the method “display()”.
    • Definition of method “display()”.
      • Get the type of sandwich filling and calories per slice by calling the method “getSandwichFilling()” and “getCalories()”.
      • Print the result.

c.

Program Plan Intro

Sandwich.java

Program Plan:

Sandwich.java:

  • Define the class “SandwichFilling”.
    • Declare and initialize the required variable.
    • Definition of constructor.
      • Assign the “Bread” and “Sandwich” value to the variables.
    • Definition of method “getBread()”.
      • Return the value filling.
    • Definition of method “getSandwich()”.
      • Return the value calories.

TestSandwichFilling.java:

  • Define the class “TestSandwich”.
    • Define the main method.
      • Create an object for “Sandwich”.
      • Call the method “display()”.
    • Definition of method “display()”.
      • Declare the variable “SLICE”.
      • Create an object for “Bread”.
      • Create an object for “SandwichFilling”.
      • Print the details of bread.
      • Print the details of “sandwichFilling”.
      • Print the details of “sandwich”

Blurred answer
Students have asked these similar questions
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 15
Create 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.
Mick’s Wicks makes candles in various sizes. Create a class for the business named Candle that contains the following data fields: color - of type String height - of type int price - of type double Create get methods for all three fields. Create set methods for color and height, but not for price. Instead, when height is set, determine the price as $2 per inch. Create a child class named ScentedCandle that contains an additional data field named scent (of type String) and methods to get and set it. In the child class, override the parent’s setHeight() method to set the price of a ScentedCandle object at $3 per inch.
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:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
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
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