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
Concept explainers
Question
Chapter 13.7, Problem 13.7.2CP
Program Plan Intro
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.
Object Cloning:
Object cloning is the process of creating an exact copy of the object with different name. The clone() method present in the object class is use to create clone.
Cloneable Interface:
The Cloneable interface is an interface that specifies that specifies than an object can be cloned.
Syntax:
The Cloneable interface is can be defined as follows:
package java.lang;
public interface cloneable
{
//interface body
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In JAVA complete the reference-based implementation of the ADT List including a main method and verify methods such as
a constructor, "create()", "add()", "get()", "remove()", "isEmpty()", "size()", "removeAll()" and exception handling
by implementing a test program.
Show that the ADT List works.
Use Netbeans to run the following decorator pattern code. Provide screenshot to prove that the code runs successfully.
Design a UML class diagram to model the program and fully explain the class diagram.
import java.util.List;
public interface Spaceship
{
void name();
void size() throws Exception ;
}
class EbonHawk implements Spaceship
{
public void name()
{
System.out.println("EbonHawk Spaceship");
}
public void size()
{
System.out.println("Spaceship size");
}
public void loadPassangers(List passangers)
{
}
public void unloadPassangers(List passangers)
{
}
public int rangeFinder(int destination, int source)
{
return destination-source;
}
}
class Enemy implements Spaceship
{
public void name()
{
System.out.println("Enemy Spaceship");
}
public void size()
{
System.out.println("Enemy size");
}
public boolean isLaserGunEnabled()
{
return true;
}…
Explain the use of the java.util.Comparators class and its role in creating custom comparators for objects that implement the Comparable interface.
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
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Modify the RationalNumber class so that it implements the Comparable interface. To perfom the comparison, compute an equivalent floating point value from the numerator and denominator for both RationalNumber objects, then compare them using a tolerance value of 0.0001. Write a main driver to test your modifications. (Java)arrow_forwardWhat are the practical benefits, if any, of importing a specific class rather than an entire package (e.g. import java.net.* versus import java.net.Socket)?arrow_forwardJAVA I am trying to figure out how to connect the PaymentBatchProcessor Class (generic) to the Payment Class(interface). Can you explain the relationship and how I can populate payment.getamount() for my test. Does the paymentBatvhPossser also have to implement the Payment Class ? The other two classes are Check and IOU that implements the payment class. package cop2251.fall23.week4.sullivan; import java.util.ArrayList; import java.util.List; ///PaymentBatchProcessor to work with any of the three types shown above. The PaymentBatchProcessor //class should maintain a list of payments (using an ArrayList), //based upon the type it was instantiated to work with. //a method named add that adds the appropriate payment type to the ArrayList. //a method named getMax() that returns the payment with the largest amount //a method named getTotal() that returns the sum of all the payments //a method named getSize(), that returns how many payments are in the ArrayList.…arrow_forward
- This is a java question do what in the question says please and do it on your own dont plagarise or copy from other sites thank youarrow_forwardimport java.util.Scanner; public class LabProgram { public static Roster getInput(){ /* Reads course title, creates a roster object with the input title. Note that */ /* the course title might have spaces as in "COP 3804" (i.e. use nextLine) */ /* reads input student information one by one, creates a student object */ /* with each input student and adds the student object to the roster object */ /* the input is formatted as in the sample input and is terminated with a "q" */ /* returns the created roster */ /* Type your code here */ } public static void main(String[] args) { Roster course = getInput(); course.display(); course.dislayScores(); }} public class Student { String id; int score; public Student(String id, int score) { /* Student Employee */ /* Type your code here */ } public String getID() { /* returns student's id */…arrow_forwardPlease broadly explain what the code in the driver class does for both of them. What do you think about the two driver class file? Which one was better? public class PersonFoodListDriver { public static void main(String[] args) { PersonFoodList myList = new PersonFoodList(); myList.addNode(new PersonFoodNode(new PersonFood("Emilia","Lemon Pudding Cake"))); System.out.println(myList.stringByName()); System.out.println(myList.stringByFood()); PersonFood friend2 = new PersonFood("Peter", "Ramen"); PersonFoodNode friendPeter = new PersonFoodNode(friend2); myList.addNode(friendPeter); System.out.println(myList.stringByName()); System.out.println(myList.stringByFood()); myList.addNode(new PersonFoodNode(new PersonFood("Isaac","Ziti"))); System.out.println(myList.stringByName()); System.out.println(myList.stringByFood()); myList.addNode(new PersonFoodNode(new PersonFood("Isaac","Mac & Cheese"))); System.out.println(myList.stringByName()); System.out.println(myList.stringByFood());…arrow_forward
- Is there a particular reason why I do not get the right answer after I choose my option? Entering student ID ( that was previously entered ) and then displayed something different? This is the code : import java.util.ArrayList;import java.util.Iterator;import java.util.Scanner;class UniversityPersonnelManagement {public static void main(String[] args) {ArrayList<Student> studentList= new ArrayList<Student>();ArrayList<Faculty> facultyList= new ArrayList<Faculty>();System.out.println("Welcome to my Personal Management Program");for(;;){int input=0;System.out.println(" Choose one of the options:");System.out.println("1- Add a new Faculty member");System.out.println("2- Add a new Student");System.out.println("3- Print tuition invoice for a student");System.out.println("4- Print information of a faculty");System.out.println("5- Exit Program");System.out.print(" Enter your selection: ");Scanner s=new Scanner(System.in);try{input=s.nextInt();}catch (Exception e)…arrow_forwardBelow we have class diagrams with three classes for a simple java based parking management class. Use the classes below to write java code for classes :a parking observer class (that implements an observer pattern) , a transaction manager class and a parking lot class(subject to the observer). Use the class diagram and java class to implement it. You should use an observer pattern to implement your code.The main goal is to implement the following - Once a car enters (in an entry-scan only lot) or leaves (in an entry-scan and exit-scan lot), then the ParkingObserver will be updated, and then can register the charge with the parking system via the TransactionManager’s park() methodarrow_forwardAnswer the given question with a proper explanation and step-by-step solution. USING JAVA: ---Sorting the Invoices via dates--- Another error that will still be showing is that there is not Comparable/compareTo() method setup on the Invoice class file. That is something you need to fix and code. Implement the use of the Comparable interface and add the compareTo() method to the Invoice class. The compareTo() method will take a little work here. We are going to compare via the date of the invoice. The dates of the Invoice class are by default saved in a MM-DD-YYYY format. So they have a dash '-' between each part of the date. So you will need to split the date of the current invoice AND split the date of the object sent to the method. We have three things to compare against here. First we need to check the year. If the years are the same then you should go another step forward and compare the months. If the months are the same then you will lastly have to compare the day. Use whatever…arrow_forward
- Explain why it makes no sense to define a clone() method on an immutable class! (in Java) No code required just simple explanation.arrow_forwardIn Java: -Using a BST Interface (Binary Search Tree) -Create a class Disk. Disk contains four fields: model (String), size (int), measure (String, for GB or TB), and performance index (int). -Disk needs a constructor to initialize all fields, a toString method, and an equals. Make the class Comparable and write a compareTo method that compares Disks based on the size of the disk. Make sure your comparison accounts for the fact that some numbers are in GB and some are in TB. Write a method that will return true if the disk is the same size as the parms; parms are the size and measure("GB" or "TB"). Also write a method to create a Comparator which compares Disks based on the performance rating. -The client code should do the following: Write a function called build, which will open the disks.txt file, read in each disk and add it to the BST. For each disk the model is on the first line, and the second line contains the size, measure, and performance index. The BST is passed to build as…arrow_forwardFrom Big Java 6th edition P9.7: "In this problem, you will model a circuit consisting of an arbitrary configuration of resistors. Provide a superclass Circuit with a instance method getResistance. Provide a subclass Resistor representing a single resistor. Provide subclasses Serial and Parallel, each of which contains an ArrayList<Circuit>. A Serial circuit models a series of circuits, each of which can be a single resistor or another circuit. Similarly, a Parallel circuit models a set of circuits in parallel; using Ohm's Law to compute the combined ressistance." I managed to create appropriate subclasses off of the Circuit superclass. But from here, I'm stuck! How do I compute the combined resistance? and how would I get the method to read the values off of the ArrayList<Circuit>? And does that Circuit refer to the Circuit Class I created, or would that require input for resister amounts?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