a) Write the code for an extension (subclass) of Clock called SecClock that represents a clock that has a second-hand. Be sure to override the tick() method so that a second is added to the time instead of a minute. b) Implement the Comparable interface for SecClock where the a clock storing the later time in the day is considered larger.
Q: How do you define an interface and how do you use it in Java. what happens if an abstract class…
A: An interface is like a blueprint of a class. It consists of static variables and abstract methods.…
Q: Our AbstractHashMap class maintains a load factor λ ≤ 0.5. Reimplement that class to allow the user…
A: Answer is given below .
Q: Write a generic class of Shape with the attribute of center and operation to calculate area. Inherit…
A: Note: The below program is written in Java programming language. File name: “Shape.java” //Create an…
Q: Does the use of Interfaces over abstract classes have an impact on their performance?
A: Given: In contrast, an interface simply allows you to declare functionality but not to actually…
Q: Fill in the missing keyword to indicate a class inheriting from a interface: public class MyClass…
A: Here, I have to provide an answer to the above question.
Q: Multiple inheritance is not supported in Java (extending multiple superclasses into one subclass).…
A: This is done in order to avoid misunderstanding
Q: 8) Explain the difference between implementing an interface and a derived class.
A: Answer: While implementing an interface, we need to implement all the methods declared in the…
Q: In Java 1. Can a derived class have two base classes? Can it implement two interfaces? 2.Can an…
A: You can derive a category from any variety of base categories. explanation category|a category} from…
Q: Create a subclass of the Employee class from Question 2 named ShiftSupervisor. Add the salary and…
A: class ShiftSupervisor(Employee): def __init__(self, name, idnumber, salary, bonus):…
Q: Inform me about your preference for interfaces versus abstract classes.
A: Introduction:Computer programming is the process of creating a set of instructions that tells a…
Q: In terms of performance, what are the benefits of Interfaces over abstract classes?
A: Introduction: The benefits of Interfaces over abstract classes
Q: Declare an interface IA with two method Me() and You() in JAVA . Define two classes CA and CB which…
A: Objective: Given a problem statement to demonstrate runtime polymorphism in Java. Here an interface…
Q: What are the primary distinctions between abstract classes and interfaces?
A: InterfaceAn interface is a class like construct that contains only constants and abstract methods.…
Q: hich can be used to check the validity of reference before attempting down-casting from superclass…
A: A Java operator that can be used to check the validity of reference before attempting down-casting…
Q: A reference to a superclass cannot be used to reference a subclass object. Is this argument correct…
A: Please find the answer to the above question below:
Q: Create an inheritance hierarchy of Rodent: Mouse, Gerbil, Hamster, etc. In the base class, provide…
A: As per our company guidelines, we are supposed to answer only one question per question and kindly…
Q: Abstract classes need their subclasses to implement their abstract methods. Is it true?
A: Abstract classes cannot be instantiated but they can be subclassed.
Q: When should an abstract class be used, when should an interface be used, and when should both be…
A: According to the provided information: We need to define the use of an abstract class, interface…
Q: For your application, explain the benefits of interfaces over abstract classes.
A: To accomplish abstraction, where we can declare the abstract methods, both abstract classes and…
Q: Describe a benefit from requiring class to implement an interface.
A: It is used to achieve total abstraction
Q: The parent class is A, and the subclasses are B and C. The parent class is A, and the subclasses are…
A: An interface and a class are different and as mentioned in the first line, A is a class but and not…
Q: Anonymous inner classes must implement interfaces or extend other classes in order to be considered…
A: Regular classes can implement any number of interfaces, while anonymous inner classes can only…
Q: A subclass of an abstract class must provide concrete implementations for each of the parent class's…
A: Please find the detailed answer in the following steps.
Q: When should you use an abstract class, when an interface, and when both?
A: According to the provided information: We need to define the use of an abstract class, interface…
Q: In Java 1. Can you have a variable of an interface type? Can you have a parameter of an interface…
A: Can you have a variable of an interface type? Can you have a parameter of an interface type?…
Q: Create java classes for concrete geometric shapes such as Circle, Rectangle, Triangle, etc. with…
A: It is defined as the programs can be asked from control statements, array, string, oops etc. Java…
Q: Why do you need to implement all the methods of an interface in class which implements an interface?
A: 1. In java Interface is nothing but a blue print of class has abstract methods and static final…
Q: The parent class is A, and its subclasses are B and C. Now, B and C share several characteristics…
A: Introduction: Abstraction is a technique for concealing some implementation details from the user.…
Q: Declare an interface IA with two method Me() and You (). Define two classes CA and CB which…
A: Program Approach: Define the interface named IA with two abstract methods Me() and You(). Define…
Q: Describe one advantage of requiring a class to implement an interface.
A: Interface is a user-defined data type which consists of abstract methods. It is used when different…
Q: 1. A Java interface can contain only constants and abstract methods. 2. A class that implements an…
A: Java is a programming language. It contains extensive libraries (package). It can be used to create…
Q: Discuss the difference of the Inheritance, Polymorphism and Encapsulation. In what aspects that…
A: Refer to step 2 for the answer.
Q: Write the difference between interface and abstract class
A: Interfaces and abstract classes are features of object-oriented programming languages (Java, C#) The…
Q: To implement an interface, a concrete class must implement AT LEAST ONE method heading
A: The answer:
Q: Write the abstract super class Transaction, and two of its subclasses, Payment and Sale (you do not…
A: public class Main { public static void main(String[] args) { /* * Instantiating Four…
Q: Explain why you prefer interfaces over abstract classes.
A: Introduction: Interface: It is a blueprint/template of the class that has abstract methods and…
Q: When a function Object() { [native code] } from a subset is invoked, the no-arg function Object() {…
A: When a function Object() { [native code] } from a subset is invoked, the no-arg function Object() {…
Q: Write a Java operator/keyword, which can be used to check the validity of reference before…
A: Note-Since your question contain multiple question but we can answer only one at a time for you due…
Q: Write the difference between interface and abstract class.
A: Basic Interface Class Abstract Class implementations Method interface can't have implementation…
Q: What are the differences between abstract classes and interfaces?
A: Abstract class and interface both are utilized to accomplish deliberation where we can proclaim the…
Q: A is a parent class whereas B and C are subclasses of A. Now, B and C share some common attributes…
A: Abstraction is a way to hide certain details of the implementation from the user. Both abstract…
Q: B and C are its subclasses, and A is the parent class. Now, B and C have certain similar features…
A: Abstraction is a method for concealing some implementation details from the user. Both abstract…
Java
Please help
Step by step
Solved in 2 steps
- 1/ Write a BankAccountTester class whose main method constructs a bank account, deposits $1,000, withdraws $500, withdraws another $400, and then prints the remaining balance. Also print the expected result 2/ Implement a class Employee. An employee has a name (a string) and a salary (a double). Provide a constructor with two arguments public Employee(String employeeName, double currentSalary) and methods public String getName() public double getSalary() public void raiseSalary(double byPercent) These methods return the name and salary, and raise the employee's salary by a certain percentage. Sample usage: Employee harry = new Employee("Hacker, Harry", 50000); harry.raiseSalary(10); // Harry gets a 10 percent raise Supply an EmployeeTester class that tests all methods. 3/Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon or liters/km—pick one) and a certain amount of fuel in the gas tank. The efficiency is specified in…In Java Programming: Example, 8-8, defined the class Person to store the name of a person. The methods that we included merely set the name and print the name of a person. Redefine the class Person so that, in addition to what the existing class does, ypu can: 1. Set the last name only. 2. Set the first name only. 3 Set the middle name. 4. Check whether a given last name is the same as the last name of this person. 5. Check wether a given first name is the same as the first name of this person. 6. Check whether a given middle name is the same as the middle name of thi person. 7. Add the method equals that returns true if two objects contain the same first, middle, and last name. 8. Add the method makeCopy that copies the instance variables of a Person object into another Person object. 9. Add the method getCopy that creates and returns the address of the object, which is a copy of another Person object. 10. Add a copy constructor. 11. Write the definitions of the methods of the class…use Java. Given the following class. public class FamilyMember { public String drink( ) {return “cup”;} public String eat( ) {return “fork”;} } Write a Baby class that is derived from the FamilyMember class. The Baby class has an instance variable for the age, a default constructor, and a constructor that accepts an integer. Include any other necessary methods. If a baby is older than 3 years, print that “it eats with its fork”; otherwise, “it eats with its hands”.
- Please solve this using java and attach output screenshot and implementation screenshot. Using this clock class please: public class Clock { private int hr; private int min; private int sec; public Clock() { setTime(0, 0, 0); } public Clock(int hours, int minutes, int seconds) { setTime(hours, minutes, seconds); } public void setTime(int hours, int minutes, int seconds) { if (0 <= hours && hours < 24) hr = hours; else hr = 0; if (0 <= minutes && minutes < 60) min = minutes; else min = 0; if(0 <= seconds && seconds < 60) sec = seconds; else sec = 0; } public int getHours() { return hr; } public int getMinutes() { return min; } public int getSeconds() { return sec; } public void printTime() { if (hr < 10) System.out.print("0"); System.out.print(hr + ":"); if (min < 10) System.out.print("0"); System.out.print(min + ":"); if (sec < 10) System.out.print("0"); System.out.print(sec); } public void incrementSeconds() { sec++; if (sec >…In Java please. Implement a class that simulates a traffic light. The next method advances the color in the usual way, from green to yellow to red, then again to green. Provide two constructors, as described in the documentation of the public interface. Also supply a method that yields the number of times that this traffic light has been red. Help me with this code (fill in /* Your code goes here */): /** A simulated traffic light.*/public class TrafficLight{ private String color; private int reds; /** Constructs a green traffic light. */ public TrafficLight() { /* Your code goes here */ } /** Constructs a traffic light. @param initialColor the initial color "green", "yellow", or "red" */ public TrafficLight(String initialColor) { /* Your code goes here */ } /** Moves this traffic light to the next color. */ public void next() { /* Your code goes here */ } /** Returns the current color of this traffic…An arithmetic progression is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, the sequence 5, 7, 9, 11, 13, 15 is an arithmetic progression with a common difference of 2.Given the class IntNumber:1 public class IntNumber2 {3 public final int value;45 public IntNumber(int number) {6 this.value = number;7 }8 }where value is an immutable field, that can be directly accessed (public), implement a class called ArithmeticProgressionthat implements the following methods:•1 public static IntNumber getArithmeticProgressionDifference(ArrayList<IntNumber> list)which returns the difference between terms of the arithmetic progression (as an object of type IntNumber) if thevalues of the IntNumber objects are an arithmetic progression. The method returns null in any other case.•1 public static void printIsArithmeticProgression(ArrayList<IntNumber> list)which prints on the console:The list is an arithmetic progression with difference =…
- Implement a class that simulates a traffic light. The next method advances the color in the usual way, from green to yellow to red, then again to green. Provide two constructors, as described in the documentation of the public interface. Also supply a method that yields the number of times that this traffic light has been red. /** A simulated traffic light.*/public class TrafficLight{ private String color; private int reds; /** Constructs a green traffic light. */ public TrafficLight() { /* Your code goes here */ } /** Constructs a traffic light. @param initialColor the initial color "green", "yellow", or "red" */ public TrafficLight(String initialColor) { /* Your code goes here */ } /** Moves this traffic light to the next color. */ public void next() { /* Your code goes here */ } /** Returns the current color of this traffic light. @return the current color */ public String getColor() {…Consider the following design for a Product class that keep track of product inventory: public class Product { public Product(String name, double qty){} public double getQty(){} public void reduce(double qty){} public void increase(double qty){} private String prodName; private double qtyOnHand; /* Data */ } Write the code for a main() method that models the following: A grocer starts the day with 50 Hard Rolls and 25 Soft Rolls. She sells 20 Hard Rolls and 10 Soft Rolls. The next morning about half of the Soft Rolls have turned into Hard Rolls. A shipment of 50 Soft Rolls comes in. She sells 30 Soft Rolls and 20 Hard Rolls. The storeowner wants a printout telling how many of each product she now has on hand.In Java code: Write the class encapsulating the concept of money, assuming that money has the following attributes: dollars, cents In addition to the constructors, the accessors and mutators, write the following methods: public Money() public Money(int dollars, int cents) public Money add(Money m) public Money substract(Money m) public Money multiply(int m) public static Money[] multiply(Money[] moneys, int amt) public boolean equals(Money money) public String toString() private void normalize() // normalize dollars and cents field Add additional helper methods if necessary. Use the following test driver program to test your Money class: public class MoneyTester{public static void main(String[] args){Money m1 = new Money(8, 75); // set dollars to 8 and cents to 75Money m2 = new Money(5, 80); // set dollars to 5 and cents to 80 MoneyMoney m3 = new Money(); // initialize dollars to 0 and cents to 0System.out.println("\tJane Doe " + "CIS35A Spring 2021 Lab 4"); // useyour…
- FOR JAVA, PLEASE WRITE THE CODE IN 50 MINUTES ! ! ! Part I Create Philosopher and Pasta classes. Write proper attributes, constructors, and get&set methods required for the rest of the questions. Part II Create a method for allowing the Philosopher to eat the Pasta. Part III Create a method for allowing multiple Philosophers to eat the same Pasta at the same time. Part IV Test your methods with different parameters.Define a method printAll() for class PetData that prints output as follows with inputs "Fluffy", 5, and 4444. Hint: Make use of the base class' printAll() method. Name: Fluffy, Age: 5, ID: 4444 // ===== Code from file AnimalData.java =====public class AnimalData {private int ageYears;private String fullName; public void setName(String givenName) {fullName = givenName;} public void setAge(int numYears) {ageYears = numYears;} // Other parts omitted public void printAll() {System.out.print("Name: " + fullName);System.out.print(", Age: " + ageYears);}}// ===== end ===== // ===== Code from file PetData.java =====public class PetData extends AnimalData {private int idNum; public void setID(int petID) {idNum = petID;} // FIXME: Add printAll() member function /* Your solution goes here */ }// ===== end ===== // ===== Code from file BasicDerivedOverride.java =====import java.util.Scanner; public class BasicDerivedOverride {public static void main(String[] args) {Scanner scnr = new…Consider a class PersonAddress that represents an entry in an address book. Its attributes are The first name of the person The last name of the person The e-mail address of the person The telephone number of the person It will have methods to Access each attribute Change the e-mail address Change the telephone number Test whether two instances are equal based solely on name Write a method heading for each method. Write preconditions and postconditions for each method. Write some Java statements that test the class. Implement the class.