EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
8th Edition
ISBN: 9781305480537
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
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
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.
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
a - Create a FitnessTracker class that includes data fields for a fitness activity, the number of minutes spent participating, and the date. The class includes methods to get each field. In addition, create a default constructor that automatically sets the activity to running, the minutes to 0, and the date to January 1 of the current year. Save the file as FitnessTracker.java. Create an application that demonstrates each method works correctly, and save it as TestFitnessTracker.java. b - Create an additional overloaded constructor for the FitnessTracker class you created in Exercise 3a. This constructor receives parameters for each of the data fields and assigns them appropriately. Add any needed statements to the TestFitnessTracker application to ensure that the overloaded constructor works correctly, save it, and then test it. c - Modify the FitnessTracker class so that the default constructor calls the three-parameter constructor. Save the class as FitnessTracker2.java. Create an…
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