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
Expert Solution & Answer
Chapter 8, Problem 14E
Explanation of Solution
Definition of the interface “DiscountPolicy”:
Definition of the “DiscountPolicy” interface is given below:
- • Declare the “computeDiscount” method along with the two parameters “count” and “itemCost”...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
This example asks you to write an interface. Then define three classes that implement this interface. 1) Create an interface Discount Policy. It should have a single abstract method called computeDiscount that will return the discount for the purchase of a given number of a single item. The method has two parameters, count and item Cost. This interface has no other method. 2) Define a class Bulk Discount that implements the interface Discount Policy, as de- scribed above. 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. 3) Define another class Buy NItemsGetOneFree that implements Discount Policy as de- scribed in part 1. The class should have a constructor that has a single parameter n. In addition, the class should define the method computeDiscount so that every nth item is free. For ex- ample, the following table…
In Java, which of the following is false?
An abstract class may implement an interface.
A class that contains an abstract method must be declared abstract itself or a compiler message will result.
A class may implement multiple interfaces.
A class that extends another class may implement only one interface.
Explain the difference between the following implementations of class A.a. extending class A from class Bb. extending class A from parent abstract class Cc. class A implementing interface D
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
Knowledge Booster
Similar questions
- Do it in C# windows application form.arrow_forwardYou cannot instantiate an interface but you can do so to an abstract class. True Falsearrow_forwardGive me a code example where you can decouple the classes with the help of Interface? II. Give a code example to show the difference between an abstract class and Interface? III. Give a code example to show the implementation of Abstraction Principle?arrow_forward
- Consider the following scenario: A chicken, eagle and duck are birds. A dog, cat, cow,and lion are animals. Human and Birds are also animals. Peas, carrots, and grass areplants. Chicken, duck, cow, and plants are edible. Draw a class diagram for the abovescenario. You can use classes, inheritance, interfaces, and associations (includingcomposition or aggregation) when needed. You shouldn’t use operations.arrow_forwardWrite the Talker interface, Animal abstract class, plus the Dog, Cat, Fish, and Radio classes for this Java Program. Talker.java - the interface Talker, which has just one void method called speak() Animal.java - the abstract class Animal, which stores an animal's name. (No abstract methods). It should contain 2 methods: a constructor with 1 argument (the name) a method getName() which returns the name. Dog.java - the class Dog, which extends Animal and implements Talker. It should contain 3 methods: a constructor with no arguments, giving the dog a default name of "Fido" a constructor with 1 argument (the name) a speak() method that prints "Woof" on the screen. Use @Override Cat.java - the class Cat, which extends Animal and implements Talker. It should contain just 2 methods: a constructor with 1 argument (the name) (no default name like dogs have) a speak() method that prints "Meow" on the screen. Use @Override Fish.java - the class Fish, which is an Animal that…arrow_forward1. Define an interface Measurable. It has a single abstract method: double getArea(); 2. Define an abstract class Shape which has two fields: type and name both of type Strin a. Provide constructor with a single input parameter: name. b. Provide accessor methods for both fields. C. Provide setter method for name. d. Provide toString() method that simply returns the "(type): (name)" e. Shape class implements Measurable interface without implementing its only abs method. 3.arrow_forward
- Design a console program that will print details of prescribed textbooks of students. Make use of an abstract class Book with variables that will store the author, title, category and price of a book. Create a constructor that accepts the author, title and category through parameters and assign these to the class variables. Create an abstract set method for the price of a book; also create get methods for the variables.Create a subclass TextBook that extends the Book class and implements an iPrintable interface. The interface that must be added is shown below:public interface iPrintable { String DisplayDetails();}The TextBook subclass has a private variable named yearPrescribed for which a get method must be written. The constructor of the TextBook class must accept the author, title, category and yearPrescribed through parameters. Write the code for the setPrice() and DisplayDetails() methods.Write a useBook class and instantiate 2 objects of the TextBook class.arrow_forwardIn what scenarios would you choose to use an abstract class over an interface, and vice versa?arrow_forwardInstructions: Write your answer on a piece of paper with your name on top. Take a picture and submit within the allocated time limit. «interface Payable «abstract Person idno, name, age Student course, tuition, balance public double pay(double amount); Employee department, salary Given the class hierarchy: 1. Define the interface Payable. 2. Define the class Person that implements Payable and encapsulate. Override toString and equals. 3. Define Student and encapsulate. Override toString and equals. Implement pay(). pay() - deducts amount from balance and returns the new balance. 4. Define class Test. Declare an array of 10 Persons. Assume that Employee had already been implemented. Ask the user whether to create a student or an employee object.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,
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,