Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 13.5, Problem 13.5.1CP
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
IN JAVA.
Any help is appreciated! Thank you!
PART 1 : Automobiles
Create a data class named Automobile that implements the Comparable interface. Give the class data fields for make, model, year, and price. Then add a constructor, all getters, a toString method that shows all attribute values, and implement Comparable by using the year as the criterion for comparing instances.
Write a program named TestAutos that creates an ArrayList of five or six Automobiles. Use a for loop to display the elements in the ArrayList. Sort the Arraylist of autos by year with Collections.sort(). Finally, use a foreach loop to display the ArrayList sorted by year.
Create a class Animal Create a class Cat, and a class Dog, and a class Bearded Dragon which extend Animal. Add to your Animal class: Member: name Methods: Public Animal (String name) //constructor public void makes Sound () with the implementation printing out a generic animal sound. Next, override (add) the makes Sound() method to your Cat and Dog class, with the implementation specific to each animal (i.e, cat says purr..). Do not override the makesSound() for your Dragon (bearded dragons don't make sounds!) Note, you'll also need a constructor in each of your subclasses which calls super(name) to initialize the common 'name' member of Animal. Next (in your test harness) create a List of different Animals ( a couple cats, a dog, a dragon... ) and add these Animals to your list. Iterate through your list & call makeSound on each. (you should observe the makeSound method called will be: cat -> from Cat class, dog-> from Dog class, bearded Dragon -> from Animal class ) EC:…
Chapter 13 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
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
- Identify the steps need to be taken in the correct orderarrow_forwardpublic interface Rational { /** Determines whether this Rational object represents a value less than one. * @return true if this Rational is less than 1, false else public boolean islessThanOne (); } Write the class Goo that implements this interface. Goo must use an array. Your answer must include all necessary fields and any additional private methods as needed for your implementation. You may not use ArrayList, or any similar class.arrow_forwardComplete the Course class by implementing the courseSize() method, which returns the total number of students in the course. Given classes: Class LabProgram contains the main method for testing the program. Class Course represents a course, which contains an ArrayList of Student objects as a course roster. (Type your code in here.) Class Student represents a classroom student, which has three fields: first name, last name, and GPA. Ex. For the following students: Henry Bendel 3.6 Johnny Min 2.9 the output is: Course size: 2 public class LabProgram { public static void main (String [] args) { Course course = new Course(); // Example students for testing course.addStudent(new Student("Henry", "Bendel", 3.6)); course.addStudent(new Student("Johnny", "Min", 2.9)); System.out.println("Course size: " + course.courseSize()); } } public class Student { private String first; // first name private String last; // last name private…arrow_forward
- Car herCar = new Car();Car hisCar = new Car(); Car myCar = hisCar;hisCar = null;myCar = herCar;herCar = hisCar; suppose the following obejexts created in the class car, How many "null reference" can you see in this code? How many "unreachable objects" can you see in this code, which will be subject to garbage collection? How many "active object reference" can you see in this code? How many "reachable objects" can you see in this code?arrow_forwardTask 1:The first task is to make the maze. A class is created called Maze, in which a 2D array for the maze is declared. Your job is to implement the constructor according to the given javaDoc. When you completed this task, write a set of Junit test case to test your code.As you probably noticed, the maze is defined as a private variable. The second job for you is to write an accessor(getter) method that returns the maze. Other information about what is expected for this method is given in the starter code. public class PE1 { MazedogMaze; /** * This method sets up the maze using the given input argument * @param maze is a maze that is used to construct the dogMaze */ publicvoidsetup(String[][]maze){ /* insert your code here to create the dogMaze * using the input argument. */ }arrow_forwardPlease solve it fast using JAVAarrow_forward
- in Javaarrow_forwardwrite code in python languagearrow_forward1- Why are the methods getlndexOf and removeEntry in the class ArrayBag private instead of public? 2- Implement a method replace for the ADT bag that replaces and returns a specified object currently in a bag with a given object. 3- Suppose that a bag contains Comparable objects such as strings. A Comparable object belongs to a class that implements the standard interface Comparable, and so has the method compareTo. Implement the following methods for the class ArrayBag: The method getMin that returns the smallest object in a bag The method getMax that returns the largest object in a bag The method removeMin that removes and returns the smallest object in a bag The method removeMax that removes and returns the largest object in a bagarrow_forward
- In Java, declaring a class abstract is useful ... When it doesn't make sense to have objects of that class. To prevent developers from further extending the class. When default implementations of some methods are not desirable. When it makes sense to have objects of that class.arrow_forwardNeed help on java homework assignment, It says Create a class Vehicle. A Vehicle has a single instance variable of type String named "vehicleType" that describes the vehicle. It has an abstract method getTires that takes no parameters and returns an ArrayList<Tire> object that describes each Tire of the vehicle. A Tire class has been provided. Vehicle has a single constructor that takes the vehicle type as a parameter.Create a class Bicycle that extends Vehicle that has two Tires, both of type "skinny". Bicycle should have a single default constructor.Create a class Dragster that extends Vehicle and has four Tires, two of type "slick" and two of type "medium". Dragster should have a single default constructor.Write a tester program to test Bicycle and Dragster objects. Use declarations such as Vehicle b = new Bicycle();in your tester. Here is the code provided : public class Tire { private String size; public Tire(String siz) { size = siz; } public String…arrow_forwardAssume the existence of a Widget class that implements the Comparable interface and thus has a compareTo method that accepts an Object parameter and returns an int. Write an efficient static method, getWidgetMatch, that has two parameters. The first parameter is a reference to a Widget object. The second parameter is a potentially very large array of Widget objects that has been sorted in ascending order based on the Widget compareTo method. The getWidgetMatch searches for an element in the array that matches the first parameter on the basis of the equals method and returns true if found and false otherwise.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