Java Programming, Loose-Leaf Version
9th Edition
ISBN: 9781337685900
Author: FARRELL, Joyce
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
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.
- Define constructor
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 “m” is equal to “AIR”
- 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”
- Check “m” is equal to “AIR”
- Return the value
- Check “w” is less than “MEDWT”
-
- Check “m” is equal to “AIR”
- 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.
- Define the main method
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
Question 6
Create a set of classes and interface for the following scenario:
Define an interface called Classical Music, which contains a get Year method that
returns the year the classical album released.
Create an abstract class Called CD. This class contains the title as String, and
playingTime as integer (e.g. 60 minutes). Include a constructor to initialize all the data
fields. Create an abstract method called printPlayingTime to show the CD playing
details. Make sure all the data fields can be accessed directly from the child classes.
Create a class called Album that inherits from the CD and Classical Music. Include
a data field called year as integer type. Create a constructor to initialize all the data
members. Override the getYear method to return the released year. Override the
printPlayingTime method. If the CD title is more than 10 characters, this method
will print the first 10 characters, followed by the three ellipse dots and the playing
time. For example:
Thriller 60…
Create an Employee Class that will have
Two instance variable: name and workingPeriod
A class method named employeeByJoiningYear():
• To create an Employee object by joining year for calculating the working
period
o it will have two Parameter name and year
• A static method experienceCheck() to check if an Employee is experienced or not
o It will take working period and gender as parameter
o If an employee's working period is less than 3, he or she is not experienced
[You are not allowed to change the code below]
# Write your code here
employee1 = Employee('Dororo', 3)
employee2 = Employee.employeeByJoiningYear('Harry', 2016) 6
print(employee1.workingPeriod)
print(employee2.workingPeriod)
print(employee1.name)
print(employee2.name)
print(Employee.experienceCheck(2, "male"))
print(Employee.experienceCheck(3, "female"))
Оutput
3
Dororo
Harry
He is not experienced
She is experienced
Design a Ship class that has the following members:• A field for the name of the ship (a string).• A field for the year that the ship was built (a string).• A constructor and appropriate accessors and mutators.• A toString method that displays the ship's name and the year it was built.Disign a CruiseShip class that extends the Ship class. The CruiseShip class should have thefollowing members:• A field for the maximum number of passengers (an int).• A constructor and appropriate accessors and mutators.• A toString method that overrides the toString method in the base class. The CruiseShipclass's toString method should display only the ship's name and the maximum number ofpassengers.Design a CargoShip class that extends the Ship class. The CargoShip class should have thefollowing members:• A field for the cargo capacity in tonnage (an int).• A constructor and appropriate accessors and mutators.• A toString method that overrides the toString method in the base class. The CargoShipclass's…
Chapter 10 Solutions
Java Programming, Loose-Leaf Version
Knowledge Booster
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
- Create a class Course to describe a course according to the following requirements: A course has three attributes: courseName, courseCode, fees. Create a constructor without parameters to initialize all the instance variables to default values (0 for numbers and "" for a string). Create a constructor to initialize all the attributes to specific values. Add all setter and getter methods Create a tester class with the main method. The tester class must be named using your first and last In this class performs the following: Create a course object c1 using the default constructor. Create a course object c2 with the following information: courseName =” object oriented programing”, courseCode = “CS230” , fees = a value from your choice. Change the course fees of c2 to your age. Print the course information of c2 using getter methods I attached Typical run of the programarrow_forwardThis is the question - Create a class named Rock that acts as a superclass for rock samples collected and catalogued by a natural history museum. The Rock class contains the following fields: sampleNumber - of type int description - A description of the type of rock (of type String) weight - The weight of the rock in grams (of type double) Include a constructor that accepts parameters for the sample number and weight. The Rock constructor sets the description value to "Unclassified". Include get methods for each field. Create three child classes named IgneousRock, SedimentaryRock, and MetamorphicRock. The constructors for these classes require parameters for the sample number and weight. Search the Internet for a brief description of each rock type and assign it to the description field using a method named setDescription inside of the constructor. This is the code I have, the program does not like at all what I have - import java.util.*; public class DemoRock { public static…arrow_forwardThis is the question - Create a class named Rock that acts as a superclass for rock samples collected and catalogued by a natural history museum. The Rock class contains the following fields: sampleNumber - of type int description - A description of the type of rock (of type String) weight - The weight of the rock in grams (of type double) Include a constructor that accepts parameters for the sample number and weight. The Rock constructor sets the description value to "Unclassified". Include get methods for each field. Create three child classes named IgneousRock, SedimentaryRock, and MetamorphicRock. The constructors for these classes require parameters for the sample number and weight. Search the Internet for a brief description of each rock type and assign it to the description field using a method named setDescription inside of the constructor. I am only missing two checks and they seem to be with the rock, here is my code then I will copy one check - import java.util.*;…arrow_forward
- JAVA please help Design a class named Sandwich with data fields for description and price. Include a constructor that requires arguments for both fields and a method to display the data (example value for description is chicken). Create a subclass named DeliverySandwich that inherits from Sandwich and has a delivery fee and a delivery address as additional fields. The description, price, and delivery address are required as arguments to the subclass constructor. The delivery fee should be set to $3 if the sandwich ordered costs more than $15; otherwise it should be set to $5. Write an application that instantiates at least two objects of each type and displays their state (data).arrow_forwardCreate a class called Employee that contains two attributes: name and number. Next, write a class named Production Worker that is a subclass of the Employee class. The Production Worker class should add extra attributes called shift_number (an integer, either 1 or 2) and pay_rate. Write the appropriate accessor and mutator methods for each class. Once you have written the classes, write a program that creates an object of the Employee class and an object of the Production Worker class and prompts the user to enter data for each of the object's data attributes. Store the data in the object, then use the object's accessor methods to retrieve it and display it on the screen.arrow_forwardCreate an Employee Class that will have ● Two instance variable: name and workingPeriod ● A class method named employeeByJoiningYear(): o To create an Employee object by joining year for calculating the working period o It will have two Parameter name and year ● A static method experienceCheck() to check if an Employee is experienced or not o It will take working period and gender as parameter o If an employee’s working period is less than 3, he or she is not experienced [You are not allowed to change the code below] # Write your code here employee1 = Employee('Dororo', 3) employee2 = Employee.employeeByJoiningYear('Harry', 2016) print(employee1.workingPeriod) print(employee2.workingPeriod) print(employee1.name) print(employee2.name) print(Employee.experienceCheck(2, "male")) print(Employee.experienceCheck(3, "female")) Output 3 5 Dororo Harry He is not experienced She is experiencedarrow_forward
- Define a class named Employee with the following attributes: name, employee_id, department, and position. The Employee class should also have the following methods: __init__(self, name, employee_id, department, position): a constructor method that initializes an Employee object with name, employee_id, department, and position. get_details(self): a method that prints the details of the employee in the following format: "Name: John, ID: 001, Department: IT, Position: Software Engineer". Create a class named EmployeeManagement which will manage a list of Employee objects. This class should have the following methods: add_employee(self, employee): a method that takes an Employee object and adds it to the list of employees. remove_employee(self, employee_id): a method that takes an employee_id and removes the corresponding Employee object from the list. display_all_employees(self): a method that iterates over the list of employees and calls the get_details() method on each Employee…arrow_forwardDefine a class named Employee with the following attributes: name, employee_id, department, and position. The Employee class should also have the following methods: __init__(self, name, employee_id, department, position): a constructor method that initializes an Employee object with name, employee_id, department, and position. get_details(self): a method that prints the details of the employee in the following format: "Name: John, ID: 001, Department: IT, Position: Software Engineer". Create a class named EmployeeManagement which will manage a list of Employee objects. This class should have the following methods: add_employee(self, employee): a method that takes an Employee object and adds it to the list of employees. remove_employee(self, employee_id): a method that takes an employee_id and removes the corresponding Employee object from the list. display_all_employees(self): a method that iterates over the list of employees and calls the get_details() method on each Employee…arrow_forwardObject-oriented programming Create a class called Triangle that models triangles using three points (the vertices) for the x's and three points for the y's. The vertices will be of type double. It will have two constructors: one by default and one that creates a triangle from its three vertices. The class will also include a method to calculate the area and another to calculate the perimeter of the triangle. Attributes are of type public. Write here the class diagram and class code in Javaarrow_forward
- 1. Create an interface OnlineQuiz with the following details: Member variables: totalMarks=10 Member Methods: · nQuestions(): An abstract method that calculates and return the number of questions. Defined in subclass. · display(): An abstract method that displays all details. Defined in a subclass. 2. Create a class Staff that inherits OnlineQuiz with the following details: Member variables: · staffD // id of the staff string type · staffName // Name of the staff string type · nMCQ // Number of MCQ type questions int type · nTF // Number of true/false type questions int type · nMatch // Number of match type questions int type Member Methods: · Define the parameterized constructor to set the member variables. · Define the method nQuestions(): which calculate and return the total number of questions. Total number of question= nMCQ + nTF +…arrow_forwardJava - Constructors Create a class named Book that has the following attributes: Publisher - String Year Published - Integer Price - Double Title - String Create a constructor for the class Book that has the parameters from the attributes of the class. After, create a method for the class that displays all attributes. Ask the user for inputs for the attributes and use the constructor to create the object. Lastly, print the values of the attributes. Inputs 1. Publisher 2. Year Published 3. Price 4. Book Title XYZ Publishing 2020 1000.00 How to Win? Sample Output Published: ABC Publishing Year Published: 2022 Price: 150.00 Book Title: Stooping too low Stooping too low is published by ABC Publishing on 2022. It sells at the price of Php150.00.arrow_forwardCreate a class named Poem that contains the following fields: title - the name of the poem (of type String) lines - the number of lines in the poem (of type int) Include a constructor that requires values for both fields. Also include get methods to retrieve field values. Create three subclasses: Couplet, Limerick, and Haiku. The constructor for each subclass requires only a title; the lines field is set using a constant value. A couplet has two lines, a limerick has five lines, and a haiku has three lines. These are the provided classes and subclasses : public class Poem { // Define the Poem class here } public class Limerick { // Define the Limerick class here } public class Haiku { // Define the Haiku class here } public class Couplet { // Define the Couplet class here } import java.util.*; public class DemoPoems { publicstaticvoidmain(String[] args) { Poem poem1 =newPoem("The Raven",84); Couplet poem2 =newCouplet("True Wit"); Limerick poem3 =newLimerick("There was an…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
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