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
Question
Chapter 8.4, Problem 23STQ
Program Plan Intro
Interface:
Interface is a reference type in Java, which contains a collection of abstract methods. It is very similar to class, but it cannot be instantiated, rather it is implemented by other classes.
An interface needs to the follow certain conditions such as:
- • One cannot instantiate an interface.
- • Interfaces do not contain any constructors.
- • All methods present in the interface are abstracts.
- • An interface does not contain any instance field.
- • An interface cannot be extended by a class.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
The following is a class definition for a simple Ebook. Two instance variables and one parameterless constructor are provided.
Part 1: Write a second constructor that takes a String array of pages as input and sets the String array instance variable equal to the input. Continue to default the current page number to zero.
Part 2: Write a getter and a setter method for the page number variable. The setter should check to make sure that the input is a valid page number and only update the variable if the new value is valid.
Part 3: Write a getCurrentPage method that returns the String of the current page indexed by current_page.
public class Ebook{ private String[] pages; private int current_page; //constructor public Ebook() { this.pages = {"See Spot.", "See Spot run.", "Run, Spot, run."}; this.current_page = 0; }}
Write a complete program for the description given below.
Consider a Billing class that implements an interface Payable having a method getTotalPayment Amount(). Besides this, you have a Doctor class with private instance variables (docID, docName, and docFee) and a public getDoc() method, Patient class with private instance variables (pName, pID. pDisease), Medicine class with private instance variables (medID, medName, medQty, medPrice), and Medical Test class with private instance variables (testID, testName, testPrice). Each of these classes has the toString() method to display the information of its object. The Billing class is having "Has A" relationship with the other four classes (Doctor, Patient, Medicine, and MedicalTest) mentioned above. The getPayment Amount() method of Billing class returns the total billing amount that includes doc fee, medicine cost, and medical test fee that a patient has to pay. After implementing these classes, you are required to do the following in…
Do this.
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
- Copy your previous class definition for RectangularSolid from the previous problem, including both methods. Provide mutators (setters) and accessors (getters) for each of the three parameters. Use the naming convention for these methods that is demonstrated in your textbook (i.e. do not use the property function or decorators). These methods should allow a program using your code to modify the parameter values after creation and to read individual parameter values.arrow_forwardCreate a TestCard project with a TestCard class and a Card class. Data members for the Card class should be two numeric values representing the suit of the Card and the card's number. The Card class also has a constructor and methods for setting and getting the card information. See UML model. In the TestCard class within main(), deal two cards at a time by constructing two card objects. One card is the user's. The other is the computer's. Show both cards. Add a point to whoever had the higher card. Show who won the trick and the score. Scores don't change if a tie. Keep dealing until user wants to quit or 26 pairs have been dealt. UML for Card class -suit: int the number that corresponds to the suit of the card. 0 Hearts, 1 Diamonds, 2 Clubs, 3 Spades -value: int the value of the card. Ace is 1, 2 is 2, ..., Jack is 11, Queen 12, King 13. +Card() Default constructor. Sets the suit and number to random values +getValue(): int Returns the value of the…arrow_forwardWrite a Rectangle class. A Rectangle has properties of width and length. You construct a Rectangle object by providing the width and length in that order. If no width and length are provided to the constructor, construct a Rectangle with width 0.0 and length 0.0. We want to be able to get and set both the width and the length independently. We also want to be able to ask for the area of the rectangle and the perimeter of the rectangle. What will the object need to remember? width and length - those are the instance variables. Rectangle class has these constructors : public Rectangle() - Constructs a new rectangle with width and length of 0.0. public Rectangle(double width, double length) - Constructs a new rectangle with the given width and length. Remember that the job of the constructor is to initialize the instance variables. It has these methods. public double getWidth() - Gets the width of this Rectangle public double getLength() - Gets the length of this Rectangle public void…arrow_forward
- Write a Rectangle class to represent rectangles, with two data fields (width, height) and four methods (input data, display data, calculate and return area, calculate and return perimeter). Write another class to test all methods of the Rectangle class.arrow_forwardPlease look at the images for the programming question. I am not sure sure where I should start on this. All coding is done in Java, using IntelliJ Idea.arrow_forwardGiven a class student that represents names and grades of a class: 1. How would we implement the Comparable interface in our class so we can compare the scores of individual students? Write the complete Class Header implementing this interface. 2. Write the complete Method Header for the Student class's compareTo method. You do not need to write the body of the method.arrow_forward
- Create a class Square derived from DrawableShape, as described in theprevious exercise. A Square object should know the length of its sides. Theclass should have an accessor method and a mutator method for this length.It should also have methods for computing the area and perimeter of thesquare. Although characters are taller than they are wide—so the number ofcharacters in the vertical sides will differ from the number in the horizontalsides—you need not worry about this detail when drawing the square.arrow_forwardNot all dogs like to bark, but some like to make a lot of noise! In this exercise we have a Dog superclass and a LoudDog subclass. You do not need to modify the Dog class. Your task is to write two override methods in the LoudDog class. You will override the speak method to return BARK!. You will then override the toString so that it returns Clover is loud and likes to BARK! where Clover is replaced by the name variable. Create and print at least one Dog and one LoudDog to test. public class DogTester{public static void main(String[] args){// Start here}} public class Dog{private String name;public Dog(String name){this.name = name;}public String getName(){return name;}public String speak(){return "Bark!";}public String toString(){return name + " likes to " + speak();}} public class LoudDog extends Dog{public LoudDog(String name){super(name);}// Override the speak method here//Override the toString here.//Remember, you can access the name using super.getName()}arrow_forwardAssume B is a subclass of A. Which of the statements about the following assignment is false? A a = new B(); We can assign anything to variable a that has a subtype of B. We can call on a any method defined in A. We can call on a any method defined in B. We can assign anything to variable a that has a subtype of A.arrow_forward
- Can we have two methods in a class with the same name?arrow_forwardCreate 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)arrow_forwardplease may you : create a Python class named Animal with properties for name, age, and a method called speak. also include an initializer method for the class and demonstrate how to create an instance of this class. and extend the Animal class by adding a decorator for one of its properties (e.g., age). please include both a getter and a setter for the property, and demonstrate error handling.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