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 10, Problem 7PE
Program Plan Intro

Shipping cost

Program plan:

Filename: “InsuredPackage.java”

  • Define of “InsuredPackage” class
    • Define constructor
      • Call the “super” method
      • Declare the constant variables with the values.
      • Check “getCost ()” is less than “LOWCOST”
        • Set “i” is “LOWINS”
      • Check “getCost ()” is less than “MEDCOST”
        • Set “i” is “MEDINS”
      • Otherwise, set “i” is “HIGHINS”
      • Call the “increaseCost()” method.

Filename: “Package.java”

  • Define the “Package” class
    • Declare the required private variables
    • Define the parameterized constructor
      • Set the values
      • Call the method
    • Define the “calculateCost” method
      • Declare the variable
      • Check “w” is less than “LOWWT”
        • Check “m” is equal to “AIR”
          • Set “c” is “LOWAIR”
        • Otherwise, check “m” is equal to “TRUCK”
          • Set “c” is “LOWTRUCK”
        • Otherwise, set “c” is “LOWMAIL”
            • Check “w” is less than “MEDWT”
              • Check “m” is equal to “AIR”
                • Set “c” is “MEDAIR”
              • Otherwise, check “m” is equal to “TRUCK”
                • Set “c” is “MEDTRUCK”
              • Otherwise, set “c” is “MEDMAIL”
            • Check “w” is less than “HIGHWT”
              • Check “m” is equal to “AIR”
                • Set “c” is “HIGHAIR”
              • Otherwise, check “m” is equal to “TRUCK”
                • Set “c” is “HIGHTRUCK”
              • Otherwise, set “c” is “HIGHMAIL”
            • Return the value
    • Define the “display” method
      • Display the result
    • Define the “getCost” method
      • Return the cost
    • Define the “increaseCost” method
      • Calculate the cost value

Filename: “UsePackage.java”

  • Define the “UsePackage” class
    • Define the main method
      • Create three objects for “Package” class with different values
      • Create three objects for “InsuredPackage” class with different values
      • Call the “display” method with different objects of “Package” and “InsuredPackage” classes.

Blurred answer
Students have asked these similar questions
Write a class encapsulating the concept of the weather forecast, assuming that it has the following attributes: the temperature and the sky conditions (e.g. sunny, snowy, cloudy, rainy, etc.).  Include a default constructor, an overloaded constructor, accessors and mutators, and the methods, toString() and equals(). Temperature, in Fahrenheit, should be between -50 and +150; the default value is 70, if needed. The default sky condition is sunny. In Addition, include a method that converts Fahrenheit to Celsius. Celsius temperature = (Fahrenheit temperature – 32) * 5/9. Also include a boolean method that checks whether the weather attributes are consistent (there are two cases where they are not consistent: when the temperature is below 32 and it is not snowy, and when the temperature is above 100 and it is not sunny). Write a client class to test all the methods in your class.
Write a class named Vehicle with vehicleType, manufactureYear(int) and cost(double) as private data fields. [Hint: VehcleType could be "truck", "4WD", "Bus"] . Add a constructor with any two parameters of the superclass. Write a class named Car which inherits the Vehicle class. Add a non-static private string variable called companyName. Add a constructor in the subclass and a toString() method that prints the Car's data fields in the order VehicleType, manufactureYear, companyName [Hint: Add a toString( ) method in the superclass as well]. Create objects of Vehicle and Car class. Can the object of Vehicle class be stored in an object of Car Class? If yes, write the code. If No, Explain why? ***Student Instruction *** You need to write the complete code as mentioned below: i) The main class with necessary codes. ii) The subclass with necessary codes.iii) The Test class with necessary codes.
Part A: Create a class named Insect, which includes the following: 1. Attributes including:      a. A String named species      b. A double named weight 2. Get and Set methods for both attributes 3. A default constructor that initializes species to "NA" and weight to 0.0 4. A non-default constructor that takes a String and double argument and defines the corresponding attributes as those values. 5. A method named eat, which increases the weight by 1.   Part B: Create a subclass of the class Insect named Butterfly. 1. Include another double attribute named maxWeightToFly 2. Include get and set methods for this new attribute 3. Include a default constructor that initializes species to "NA", weight to 0.0, and maxWeightToFly to 0.0 4. Include a non-default constructor that takes a String and two double arguments and defines the corresponding attributes to those values. 5. Override the eat method so that it increases the weight by 0.5 instead of 1 6. Include a new method named isAbleToFly…
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
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