Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
11th Edition
ISBN: 9780134694511
Author: Liang, Y. Daniel
Publisher: Pearson Education Canada
expand_more
expand_more
format_list_bulleted
Question
Chapter 13.5, Problem 13.5.2CP
Program Plan Intro
abstract class:
An abstract class is a class which may or may not include abstract methods and cannot be instantiated but rather can be sub classed.
The conditions for a class to be considered as legal abstract class are mentioned below:
- If a class includes abstract methods, then the class must be declared as abstract.
- The abstract method that is declared within the abstract class must be declared without braces and followed by a semicolon.
Interface:
Interface is a reference type in Java, which contains a collection of abstract methods.
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
A. Writing an Interface
In this problem you will first write an interface and then modify classes to implement the interface. Write an interface, GeometricSolid, which has one method, volume. The volume method takes no arguments and returns a double.
You are provided with three classes: Cylinder, Sphere, and RightCircularCone Modify the classes so that they implement the GeometricSolid interface. Supply the appropriate method for each class. You can use Google search to find the formula for the volume. Make sure that you use Math.PI in your calculations.
Notice in InterfaceRunner that the objects are added to an ArrayList of GeometricSolids.
since I couldn't fit all images with two screen shots I left the link here
link: https://codecheck.it/files/18040616319p6jy6gzkdzuq08nmlp81251t
only in java not in java c++
1. Define an interface named Shape with a single method named area that calculates the area of the geometric shape: public double area();
2. Implement the Shape interface for Rectangle, Circle and Triangle class.
3. Implement a class CalculateAreas that has a function that takes shape type array of objects and builds an array of (double values) values for each corresponding shapes
Java-
Suppose that Vehicle is a class and Car is a new class that extends Vehicle. Write a description of which kind of assignments are permitted between Car and Vehicle variables.
Chapter 13 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
Ch. 13.2 - Prob. 13.2.1CPCh. 13.2 - The getArea() and getPerimeter() methods may be...Ch. 13.2 - True or false? a.An abstract class can be used...Ch. 13.3 - Prob. 13.3.1CPCh. 13.3 - Prob. 13.3.2CPCh. 13.3 - Prob. 13.3.3CPCh. 13.3 - What is wrong in the following code? (Note the...Ch. 13.3 - What is wrong in the following code? public class...Ch. 13.4 - Can you create a Calendar object using the...Ch. 13.4 - Prob. 13.4.2CP
Ch. 13.4 - How do you create a Calendar object for the...Ch. 13.4 - For a Calendar object c, how do you get its year,...Ch. 13.5 - Prob. 13.5.1CPCh. 13.5 - Prob. 13.5.2CPCh. 13.5 - Prob. 13.5.3CPCh. 13.5 - Prob. 13.5.4CPCh. 13.6 - Prob. 13.6.1CPCh. 13.6 - Prob. 13.6.2CPCh. 13.6 - Can the following code be compiled? Why? Integer...Ch. 13.6 - Prob. 13.6.4CPCh. 13.6 - What is wrong in the following code? public class...Ch. 13.6 - Prob. 13.6.6CPCh. 13.6 - Listing 13.5 has an error. If you add list.add...Ch. 13.7 - Can a class invoke the super.clone() when...Ch. 13.7 - Prob. 13.7.2CPCh. 13.7 - Show the output of the following code:...Ch. 13.7 - Prob. 13.7.4CPCh. 13.7 - What is wrong in the following code? public class...Ch. 13.7 - Show the output of the following code: public...Ch. 13.8 - Prob. 13.8.1CPCh. 13.8 - Prob. 13.8.2CPCh. 13.8 - Prob. 13.8.3CPCh. 13.9 - Show the output of the following code: Rational r1...Ch. 13.9 - Prob. 13.9.2CPCh. 13.9 - Prob. 13.9.3CPCh. 13.9 - Simplify the code in lines 8285 in Listing 13.13...Ch. 13.9 - Prob. 13.9.5CPCh. 13.9 - The preceding question shows a bug in the toString...Ch. 13.10 - Describe class-design guidelines.Ch. 13 - (Triangle class) Design a new Triangle class that...Ch. 13 - (Shuffle ArrayList) Write the following method...Ch. 13 - (Sort ArrayList) Write the following method that...Ch. 13 - (Display calendars) Rewrite the PrintCalendar...Ch. 13 - (Enable GeometricObject comparable) Modify the...Ch. 13 - Prob. 13.6PECh. 13 - (The Colorable interface) Design an interface...Ch. 13 - (Revise the MyStack class) Rewrite the MyStack...Ch. 13 - Prob. 13.9PECh. 13 - Prob. 13.10PECh. 13 - (The Octagon class) Write a class named Octagon...Ch. 13 - Prob. 13.12PECh. 13 - Prob. 13.13PECh. 13 - (Demonstrate the benefits of encapsulation)...Ch. 13 - Prob. 13.15PECh. 13 - (Math: The Complex class) A complex number is a...Ch. 13 - (Use the Rational class) Write a program that...Ch. 13 - (Convert decimals to fractious) Write a program...Ch. 13 - (Algebra: solve quadratic equations) Rewrite...Ch. 13 - (Algebra: vertex form equations) The equation of a...
Knowledge Booster
Similar questions
- T/F1. Interface classes cannot be extended but classes that implement interfaces can be extended.arrow_forwardWrite a Program in Java Create an interface EnhancedShape that extends Shape and also requires a method public double perimeter( ) to be implemented by any class that uses the interface. (Note: Interfaces can inherit other interface just like a class by using extends keyword. Create a class file, an interface ehancedshape extends shape, and an interface shape file).arrow_forward1. Why do you need to implement all the methods of an interface in class which implements an interface?arrow_forward
- Write a Program in java Define an interface named Shape with a single method named area that calculates the area of the geometric shape: public double area(); Implement the Shape interface for Rectangle, Circle and Triangle class. Implement a class CalculateAreas that has a function that takes shape type array of objects and builds an array of (double values) values for each corresponding shapesarrow_forwardQuestion2: You are asked to develop a system for an HR Department in a company. You should note the following: The Employees’ info needs to be stored: employee ID, name, salary, rating. There are two types of employees: part time and full time. A bonus of 5% will be given to part time employees, and a bonus of 10% will be given to full time employees. Both classes should implement an interface Deduction which deducts 1% of salaries for unemployment. Design a UML class diagram for the above application. Implement your answer in Java, make sure to use the correct OOP techniques to solve the problem. Then create a test class, ask the employee to enter his details, then call the appropriate methods to display all info. Very Urgent plzzz.arrow_forwardUse inheritance and classes to represent a deck of playing cards. Create a Cardclass that stores the suit (e.g. Clubs, Diamonds, Hearts, Spades), and name (e.g. Ace, 2, 10, Jack) along with appropriate accessors, constructors, and mutators. Next, create a Deck class that stores a vector of Card objects. The default constructor should create objects that represent the standard 52 cards and store them in the vector. The Deck class should have functions to: • Print every card in the deck • Shuffle the cards in the deck. You can implement this by randomly swapping every card in the deck. • Add a new card to the deck. This function should take a Card object as a parameter and add it to the vector. • Remove a card from the deck. This removes the first card stored in the vector and returns it. • Sort the cards in the deck ordered by name. Next, create a Hand class that represents cards in a hand. Hand should be derived from Deck. This is because a hand is like a more specialized version of a…arrow_forward
- The following statement is valid in Java: public interface Shape extends Cloneable, Comparable{ //code goes here } Select one: True Falsearrow_forwardQuestion: Modify the Firm example such that it accomplishes its polymorphism using an interface called Payable. I got an error (attached image). How can I solve it? Firm.java: public class Firm{//-----------------------------------------------------------------// Creates a staff of employees for a firm and pays them.//----------------------------------------------------------------- public static void main (String[] args) { Staff personnel = new Staff(); personnel.payday(); }} Clark.java: public class Clark implements Payable{ public static void main (String[] args) { public void wages(); { System.out.println("Wages can be paid to the clerks"); } }} Payable.java: public interface Payable { public void wages(); }arrow_forwardonly in java not in java c++ Create an interface EnhancedShape that extends Shape and also requires a method public double perimeter( ) to be implemented by any class that uses the interface. Create a class file, an interface ehancedshape extends shape, and an interface shape file.arrow_forward
- Please solve it fast using JAVAarrow_forwardWrite a program namedAveragesthat includes a method that accepts any number ofnumeric parameters, displays them, and displays their average. Demonstrate that theprogram works correctly when passed one, two, or three numbers, or an array ofnumbers.arrow_forwardJavaarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT