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

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
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…
For 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…
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