Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 8, Problem 11E
Derive a class BulkDiscount from DiscountPolicy, as described in the previous exercise. It should have a constructor that has two parameters, minimum and percent. It should define the method computeDiscount so that if the quantity purchased of an item is more than minimum, the discount is percent percent.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
An airport van shuttles passengers between the terminal and the parking garage. After 4 trips, the tank is empty, and the van needs to drive to the gas station. After it has been refilled, it will drive to the terminal. The behavior of the car depends on two states: its location (terminal, garage, or gas station), and the tank level (empty or not). Complete the following class. The constructor yields a van in the garage with a full tank.
An airport van shuttles passengers between the terminal and the parking garage. After 4 trips, the tank is empty, and the van needs to drive to the gas station. After it has been refilled, it will drive to the terminal. The behavior of the van depends on two states: its location (terminal, garage, or gas station), and the tank level (empty or not). Complete the following class. The constructor yields a van in the garage with a full tank.
Create an interface Wheel with methods setWheels (int c) and getWheels () and a class Vehicle with abstract methods getColor () and getBrand (). Now, create a concrete class Taxi with additional method setDriver (String name) that inherits both Wheel and Vehicle. (Note: Concrete classes don’t have any abstract method)
Chapter 8 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 8.1 - Prob. 1STQCh. 8.1 - Suppose the class SportsCar is a derived class of...Ch. 8.1 - Suppose the class SportsCar is a derived class of...Ch. 8.1 - Can a derived class directly access by name a...Ch. 8.1 - Can a derived class directly invoke a private...Ch. 8.1 - Prob. 6STQCh. 8.1 - Suppose s is an object of the class Student. Base...Ch. 8.2 - Give a complete definition of a class called...Ch. 8.2 - Add a constructor to the class Student that sets...Ch. 8.2 - Rewrite the definition of the method writeoutput...
Ch. 8.2 - Rewrite the definition of the method reset for the...Ch. 8.2 - Can an object be referenced by variables of...Ch. 8.2 - What is the type or types of the variable(s) that...Ch. 8.2 - Prob. 14STQCh. 8.2 - Prob. 15STQCh. 8.2 - Consider the code below, which was discussed in...Ch. 8.2 - Prob. 17STQCh. 8.3 - Prob. 18STQCh. 8.3 - Prob. 19STQCh. 8.3 - Is overloading a method name an example of...Ch. 8.3 - In the following code, will the two invocations of...Ch. 8.3 - In the following code, which definition of...Ch. 8.4 - Prob. 23STQCh. 8.4 - Prob. 24STQCh. 8.4 - Prob. 25STQCh. 8.4 - Prob. 26STQCh. 8.4 - Prob. 27STQCh. 8.4 - Prob. 28STQCh. 8.4 - Are the two definitions of the constructors given...Ch. 8.4 - The private method skipSpaces appears in the...Ch. 8.4 - Describe the implementation of the method drawHere...Ch. 8.4 - Is the following valid if ShapeBaSe is defined as...Ch. 8.4 - Prob. 33STQCh. 8.5 - Prob. 34STQCh. 8.5 - What is an advantage of having the main...Ch. 8.5 - What Java construct allows us to define and...Ch. 8 - Consider a program that will keep track of the...Ch. 8 - Implement your base class for the hierarchy from...Ch. 8 - Draw a hierarchy for the components you might find...Ch. 8 - Suppose we want to implement a drawing program...Ch. 8 - Create a class Square derived from DrawableShape,...Ch. 8 - Create a class SchoolKid that is the base class...Ch. 8 - Derive a class ExaggeratingKid from SchoolKid, as...Ch. 8 - Create an abstract class PayCalculator that has an...Ch. 8 - Derive a class RegularPay from PayCalculator, as...Ch. 8 - Create an abstract class DiscountPolicy. It should...Ch. 8 - Derive a class BulkDiscount from DiscountPolicy,...Ch. 8 - Derive a class BuyNItemsGetOneFree from...Ch. 8 - Prob. 13ECh. 8 - Prob. 14ECh. 8 - Create an interface MessageEncoder that has a...Ch. 8 - Create a class SubstitutionCipher that implements...Ch. 8 - Create a class ShuffleCipher that implements the...Ch. 8 - Define a class named Employee whose objects are...Ch. 8 - Define a class named Doctor whose objects are...Ch. 8 - Create a base class called Vehicle that has the...Ch. 8 - Create a new class called Dog that is derived from...Ch. 8 - Define a class called Diamond that is derived from...Ch. 8 - Prob. 2PPCh. 8 - Prob. 3PPCh. 8 - Prob. 4PPCh. 8 - Create an interface MessageDecoder that has a...Ch. 8 - For this Programming Project, start with...Ch. 8 - Modify the Student class in Listing 8.2 so that it...Ch. 8 - Create a JavaFX application that uses a TextField...Ch. 8 - Prob. 10PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
The following table gives the parameters for a number of different caches. For each cache, fill in the missing ...
Computer Systems: A Programmer's Perspective (3rd Edition)
A pet store sells dogs, cats, birds, and hamsters. Write a declaration for an enumerated data type that can rep...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Using an example of a component that implements an abstract data type such as a stack or a list, show why it is...
Software Engineering (10th Edition)
____ variables are defined outside all functions and are accessible to any function within their scope.
Starting Out with C++: Early Objects (9th Edition)
We have defined four binary logical connectives. a. Are there any others that might be useful? b. How many bina...
Artificial Intelligence: A Modern Approach
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
- Implement the Seller class as a derived class of Person class. Create the seller.h and seller.cppfiles for this class. The Seller class contains additional data members that hold a seller’s:o average star rating received from the buyers, ando total number of items sold.These data should be accessible by its derived classes. (should these data be private, public, orprotected?) The following methods are included in the seller class:• A default constructor and a copy constructor• A constructor that receives all of the data for a seller.(for the constructors, make sure to call the base class constructor as appropriate)• Appropriate get and set functions for the new data in this class• print() – overrides the base class print() to print the base class data and print all additionalseller data with appropriate messages. Make sure to call the base class print to print thebase class data.• read() – overrides the base class read() to read the base class data and reads all additionalseller data…arrow_forwardWrite a class that implements Employee class that is described in UML diagram given below. The method “ raiseSalary(percent) " increases the salary by the given percentage. Write a test program that will generate at least 3 accounts and test each method that you write. Employee -id:int -firstName:String -lastName:String -salary:int +Employee(id:int, firstName:String, lastName:String, salary:int) +getID():int +getFirstName():String +getLastName():String +getName():String +getSalary():int +setSalary(salary:int):void +getAnnualSalary():int • +raiseSalary(int percent):int +tostring():String. "firstName Llastname" salary * 12 Increase the salary by the percent and return the new salary "Employee[id=?,name=firstName lastname,salary=?]"arrow_forwardplease asaparrow_forward
- Design and implement a class called Car that contains instance data that represents the make, model, and year of the car (as a String, String and int value respectively). Define the Car constructor to initialize these values (in that order). Include getter and setter methods for all instance data, and a toString method that returns a one-line description of the car of the form make-model (year)for example:Ford-Thunderbird (1955)arrow_forwardNOTE: READ CAREFULLY Design a class named Person and a subclasses named Employee. Make Teacher a subclass of Employee. A Person has a name, address, and e-mail address. An Employee has an office, salary. A Teacher has office hours and a subject they teach. They also have a tenure status. Define the tenure status as a constant. The tenure status is either Senior or Junior, and is represented as an integer, where Senior is equal to 1, and Junior is equal to 2. Each class should have a Default constructor, and a constructor that accepts all arguments. There should be appropriate calls to the superclass within the constructors. Each class should also have getters and setters for each member variable. Each class should have a toString method. Note: You do NOT need to run this in a test program. Just create the classes as indicated above.arrow_forwardPrograming language is Java. Define a class Person that represents a person. People have a name, an age, anda phone number. Since people always have a name and an age, your class shouldhave a constructor that has those as parameters. Define a toString() method whichdisplays all of the relevant information using a format like this: “Jim Lahey - Age 57- Phone 9025555555”.arrow_forward
- Create a class BeautyProduct with name, color, brand. Provide Constructors, getters, setters and also write toString method. Now create a class Lipstick which extends the class BeautyProduct as Lipstick is-a Beauty Product it has totalVolume, remainingVolume, price, texture (gloss, matt) as private data members. Provide Constructors, getters, setters and an apply() method whenever this method is called a beauty item is applied and its volume decreases by 10.This should also check that volume must not be zero if it then u have to throw exception. Also write toString method which prints all details like name, color, brand, price, texture and volume. Create another class foundation having totalVolume, remainingVolume, price, texture (liquid, cake) and lastingTime (number of hours foundation remain intact on face and does not crease) as private data members. This also extends the base class i.e. BeautyProduct. Provide Constructors, getters, setters and an apply() method whenever this…arrow_forwardDefine a class named Employee. This class should extend the Person class from the previous question. The class should have a constructor, which takes the name, age, employer (String) and salary (int) as parameters (in that order). The first two parameters should be passed to the constructor of the superclass and the value of the last two parameters should be stored in instance variables. The class should define the methods, getSalary which returns the salary of the employee and getEmployer which returns the name of the employer. Any methods from the previous question that need to be overridden should be overridden! Use super and instanceof as appropriate. I.e., for the following methods you should be able to call the method in the superclass for specific situations (e.g. the compareTo method in the superclass can be called if you receive anything other than an Employee, and this also holds for the equals method). The toString method only needs to append details and as such can also…arrow_forwardCreate an abstract class called Employee that has an abstract method called calculatePay() which calculates the total pay per employee using the rate per hour = R100. The method should accept the number of hours the employee has worked. Create a child class called employeeChild and provide the implementation. In the main method invoke that method and get the number of hours worked from the user and pass it to the called method.arrow_forward
- Create a Right Triangle class that has two sides. Name your class rightTraingle. Code getter and setters for the base and the height. (Remember class variables are private.) The class should include a two-argument constructor that allows the program to set the base and height. The constructor should verify that all the dimensions are greater than 0. before assigning the values to the private data members. If a side is not greater than zero, set the value to -1. The class also should include two value-returning methods. One value-returning method should calculate the area of a triangle, and the other should calculate the perimeter of a triangle. If either side is -1, these functions return a -1. The formula for calculating the area of a triangle is 1/2 * b*h, where b is the base and h is the height. The formula for calculating the perimeter of a triangle is b+h+sqrt (b*b+h*h). Be sure to include a default constructor that initializes the variables of the base, height to -1. To test…arrow_forwardCan you implement the Derived Class Parameterized constructor? A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first. Implement the constructor Dell(String name) of the Derived Class Dell which takes a string, name. We have already implemented the Base Class Laptop with the member function getName() and a parameterized constructor. Input# Laptop name is being passed through the parameterized constructor. Output# getName() method is returing Laptop name. Sample Input# Dell dell = new Dell("Dell Inspiron"); Sample Output# "Dell Inspiron"arrow_forwardTake the tax program from the last homework assignment and implement it using classes and objects instead. To do so, create a class definition for a class called Customer with attributes income and tax. It should also have a set method for income, and a calcTax() method to assign tax and return it. As a reminder, the tax is calculated as follows: Income Tax Due $0 - $50,000 5% $50,000-$100,000 $2,500 + 10% of (income > $50,000) > $100,000 $7,500 + 15% of (income > $100,000) Create a Customer object in main, have the user enter the income and assign this to the income variable of the Customer object, and then call the calcTax() method for the Customer object and print the tax due.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License