Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 10.9, Problem 10.27CP
Explanation of Solution
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...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Create an interface named Playable that defines a method play requiring no return value. Play just displays the string “Play me.” Create a class named Instrument that implements playable that contains a private member name but does not implement the play of Playable.
a. define setter and getter for name
b. define a constructor that accepts a String name argument to be assigned to the name attribute of the class
c. override equals of the object for this class
d. override toString of an object for this class
3. Implement a concrete subclass of an instrument named Guitar.
a. Create a constructor similar to the default constructor provided by the system. See to it that the superclass object is created.
b. See to it that the abstract method is also implemented
c. override equals of the object for this class
d. override toString of the object for this class
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 a class called ship that incorporates a ship’s serial number and location. Create another class angle which has two variables latitude and longitude. A member function of the ship class should get a position from the user and store it. Create object that should report the serial number and position. Write a main () program that creates three ships, asks the user to input the position of each, and then displays each ship’s serial number and position.Identify all the classes implement inheritance between them.
(language cpp)
Chapter 10 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 10.1 - Here is the first line of a class declaration....Ch. 10.1 - Look at the following class declarations and...Ch. 10.1 - Class B extends class A. (Class A is the...Ch. 10.2 - Prob. 10.4CPCh. 10.2 - Look at the following classes: public class Ground...Ch. 10.3 - Under what circumstances would a subclass need to...Ch. 10.3 - How can a subclass method call an overridden...Ch. 10.3 - If a method in a subclass has the same signature...Ch. 10.3 - If a method in a subclass has the same name as a...Ch. 10.3 - Prob. 10.10CP
Ch. 10.4 - When a class member is declared as protected, what...Ch. 10.4 - What is the difference between private members and...Ch. 10.4 - Why should you avoid making class members...Ch. 10.4 - Prob. 10.14CPCh. 10.4 - Why is it easy to give package access to a class...Ch. 10.6 - Look at the following class definition: public...Ch. 10.6 - When you create a class, it automatically has a...Ch. 10.7 - Recall the Rectangle and Cube classes discussed...Ch. 10.8 - Prob. 10.19CPCh. 10.8 - If a subclass extends a superclass with an...Ch. 10.8 - What is the purpose of an abstract class?Ch. 10.8 - If a class is defined as abstract, what can you...Ch. 10.9 - Prob. 10.23CPCh. 10.9 - Prob. 10.24CPCh. 10.9 - Prob. 10.25CPCh. 10.9 - Prob. 10.26CPCh. 10.9 - Prob. 10.27CPCh. 10.9 - Prob. 10.28CPCh. 10 - In an inheritance relationship, this is the...Ch. 10 - In an inheritance relationship, this is the...Ch. 10 - This key word indicates that a class inherits from...Ch. 10 - A subclass does not have access to these...Ch. 10 - This key word refers to an objects superclass. a....Ch. 10 - In a subclass constructor, a call to the...Ch. 10 - The following is an explicit call to the...Ch. 10 - A method in a subclass that has the same signature...Ch. 10 - A method in a subclass having the same name as a...Ch. 10 - These superclass members are accessible to...Ch. 10 - Prob. 11MCCh. 10 - With this type of binding, the Java Virtual...Ch. 10 - This operator can be used to determine whether a...Ch. 10 - When a class implements an interface, it must...Ch. 10 - Prob. 15MCCh. 10 - Prob. 16MCCh. 10 - Abstract classes cannot ___________. a. be used as...Ch. 10 - You use the __________ operator to define an...Ch. 10 - Prob. 19MCCh. 10 - Prob. 20MCCh. 10 - You can use a lambda expression to instantiate an...Ch. 10 - True or False: Constructors are not inherited.Ch. 10 - True or False: in a subclass, a call to the...Ch. 10 - True or False: If a subclass constructor does not...Ch. 10 - True or False: An object of a superclass can...Ch. 10 - True or False: The superclass constructor always...Ch. 10 - True or False: When a method is declared with the...Ch. 10 - True or False: A superclass has a member with...Ch. 10 - True or False: A superclass reference variable can...Ch. 10 - True or False: A subclass reference variable can...Ch. 10 - True or False: When a class contains an abstract...Ch. 10 - True or False: A class may only implement one...Ch. 10 - True or False: By default all members of an...Ch. 10 - // Superclass public class Vehicle { (Member...Ch. 10 - // Superclass public class Vehicle { private...Ch. 10 - // Superclass public class Vehicle { private...Ch. 10 - // Superclass public class Vehicle { public...Ch. 10 - Write the first line of the definition for a...Ch. 10 - Look at the following code, which is the first...Ch. 10 - Write the declaration for class B. The classs...Ch. 10 - Write the statement that calls a superclass...Ch. 10 - A superclass has the following method: public void...Ch. 10 - A superclass has the following abstract method:...Ch. 10 - Prob. 7AWCh. 10 - Prob. 8AWCh. 10 - Look at the following interface: public interface...Ch. 10 - Prob. 1SACh. 10 - A program uses two classes: Animal and Dog. Which...Ch. 10 - What is the superclass and what is the subclass in...Ch. 10 - What is the difference between a protected class...Ch. 10 - Can a subclass ever directly access the private...Ch. 10 - Which constructor is called first, that of the...Ch. 10 - What is the difference between overriding a...Ch. 10 - Prob. 8SACh. 10 - Prob. 9SACh. 10 - Prob. 10SACh. 10 - What is an. abstract class?Ch. 10 - Prob. 12SACh. 10 - When you instantiate an anonymous inner class, the...Ch. 10 - Prob. 14SACh. 10 - Prob. 15SACh. 10 - Employee and ProductionWorker Classes Design a...Ch. 10 - ShiftSupervisor Class In a particular factory, a...Ch. 10 - TeamLeader Class In a particular factory, a team...Ch. 10 - Essay Class Design an Essay class that extends the...Ch. 10 - Course Grades In a course, a teacher gives the...Ch. 10 - Analyzable Interface Modify the CourseGrades class...Ch. 10 - Person and Customer Classes Design a class named...Ch. 10 - PreferredCustomer Class A retail store has a...Ch. 10 - BankAccount and SavingsAccount Classes Design an...Ch. 10 - Ship, CruiseShip, and CargoShip Classes Design a...
Knowledge Booster
Similar questions
- T/F 1. Interface classes cannot be extended but classes that implement interfaces can be extended.arrow_forward1. Why do you need to implement all the methods of an interface in class which implements an interface?arrow_forward1. 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_forward
- I have multiple constructors defined in a class. Is it possible to call a constructor from another constructor’s body?arrow_forwardCreates a class called Member with two integer x and y. a. Add a constructor able to create a Member object with tow integers and the default values 0,0; b. Add the methods setX and setY to modify the attributes x and y; c. Add the method display able to display the attributes,arrow_forward1. Create abstract class Pet , which is the abstract super class of all animals.1. Declare an integer attribute called legs, which records the number of legs for this animal.2. Define a constructor that initializes the legs attribute.3. Declare an abstract method eat.4. Declare a concrete method walk that prints out something about how the animals walks (include the number of legs).2. Create the Dog class that implements Pet class.1. This class must include a String attribute to store the name and food of the pet2. Define a default constructor that calls the super class constructor to specify that all dogs have 4 legs and name.3. override the eat and walk method.3. Create the Cat class that Implements Pet class.1. This class must include a String attribute to store the name of the pet, and a string to save food .2. Define a constructor that takes one String parameter that specifies the cat's name. This constructor must also call the super class constructor to specify that all cats have…arrow_forward
- Create abstract class Pet , which is the abstract superclass of all animals.Declare a integer attribute called legs, which records the number of legs for this animal.Define a constructor that initializes the legs attribute.Declare an abstract method eat.Declare a concrete method walk that prints out something about how the animals walks (include the number of legs).Create the Dog class.The Dog class extends the Pet class.This class must include a String attribute to store the name and food of the petDefine a default constructor that calls the superclass constructor to specify that all dogs have 4 legs and name.override the eat and walk method.Create the Cat class that extends Pet.This class must include a String attribute to store the name of the pet, and a string to save food .Define a constructor that takes one String parameter that specifies the cat's name and food. This constructor must also call the superclass constructor to specify that all cats have four legs.Override walk…arrow_forwardDesign 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_forward1. Design a new Triangle class that extends the abstract GeometricObject class. Write a test program that prompts the user to enter three sides of the triangle, a color, and a Boolean value to indicate whether the triangle is filled. The program should create a Triangle object with these sides and set the color and filled properties using the input. The program should display the area, perimeter, color, and true or false to indicate whether it is filled or not.arrow_forward
- The Critter class is a base class with some basic functionality for running simulations of different kinds of critters. Critters can move, act, and remember their history. A typical simulation contains a number of critters of different types. In each step of the simulation, the act member function will be called on each critter. Define a class Sloth derived from Critter that simulates a sloth. Sloths alternate between eating and sleeping. Add the word "eat" or "sleep" to the history each time the act function is called. The implementation of the Critter class is not shown. Complete the following file: sloth_Tester.cpp #include <iostream>using namespace std; #include "critter.h" /**A sloth eats and sleeps.*/class Sloth : public Critter{public:Sloth();. . .private:. . .}; Sloth::Sloth(){. . .} void Sloth::act(){if (...) {add_history("eat");...}else{add_history("sleep");... }} int main(){Sloth sloth;sloth.act();cout << sloth.get_history() << endl;cout <<…arrow_forwardDesign a class named Employee. The class should keep the following information infields:• Employee name• Employee number in the format XXX-L, where each X is a digit within the range0-9 and the Lis aletter within the range A-M.• Hire date* Write one or more constructors and the appropriate accessor and mutator methods for theclass.Next, write a class named ProductionWorker that extends the Employee class. TheProductionWorker class should have fields to hold the following information:• Shift (an integer)• Hourly pay rate (a double)The workday is divided into two shifts: day and night. The shift field will be an integer valuerepresenting the shift that the employee works. The day shift is shift 1 and the night shift isshift 2. Write one or more constructors and the appropriate accessor and mutator methodsfor the class. Demonstrate the classes by writing a program that uses a ProductionWorkerobject. have to use beginner code because this is an intro class.arrow_forwardAssume that Automobile is an interface. We want to write a class Called Car that implements the interface Automobile. Which of the following is the correct heading of class Car: public class Car extends Automobile public class Car abstract Automobile public class Car interface Automobile public class Car implements Automobilearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage