We have written the following Class1 class:
class Class1 implements SecretInterface {
// instance variable
private int x = 0;
// constructor
public Class1(int x) {
this.x = x;
}
// instance methods
public double myMethod1(double x, double y) {
return x - y;
}
public void myMethod2(int x) {
System.out.println(x);
}
public String myMethod3(String x) {
return "hi " + x;
}
}
We have also written the following Class2 class:
class Class2 implements SecretInterface {
// instance variable
private int x = 1;
// constructor
public Class2(int x) {
this.x = x;
}
// instance methods
public double myMethod1(double a, double b) {
return a + b;
}
public void myMethod2(double x) {
System.out.println(x);
}
public String myMethod3(Object o) {
return "hello";
}
}
TASK: Write the SecretInterface interface such that it contains the most possible attributes/methods possible given the implementations of Class1 and Class2 above.
Answer :
interface SecretInterface{
double myMethod1(double x,double y);
}
only the myMethod1 is common between the Class1 and Class 2
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
We have written the following Class1 class: class Class1 implements SecretInterface { // instance variable private...
We have written the following Node class: class Node { // instance variables private int value; private Node next; // constructor public Node(int value) { this.value = value; } // get the 'next' variable public Node getNext() { return this.next; } // get the 'value' variable public int getValue() { return this.value; } // set the 'next' variable public void setNext(Node next) { this.next = next; } } TASK: Create a class called List that has the following properties: It...
4. Command pattern //class Stock public class Stock { private String name; private double price; public Product(String name, double price) { this.name = name; this.price = price; } public void buy(int quantity){ System.out.println(“BOUGHT: “ + quantity + “x “ + this); } public void sell(int quantity){ System.out.println(“SOLD: “ + quantity + “x “ + this); } public String toString() { return “Product [name=” + name + “, price=” + price + “]”; } } a. Create two command classes that...
You are to create a class Appointment.java that will have the following: 5 Instance variables: private String month private int day private int year private int hour private int minute 1 default constructor public Appointment() 1 non-default constructor that accepts arguments for all instance variables, your constructor must call the setter methods below to set the values of the instance variables public Appointment(String monthPassed, int dayPassed, int yearPassed, int hourPassed, int minutePassed) 5 setter methods (one for each instance variable)...
Which of the following is true about interfaces: An interface can have only non abstract methods. All methods in an interface must be abstract. A class can only implement one interface. None of the items listed. Can not contain constants but can have variables. What is the rule for a super reference in a constructor? It must be in the parent class' constructor. You cannot use super in a constructor. It must be the last line of the constructor in...
QUESTION 1 If we run the following code: A a = new A(1); B b = new B(2); System.out.println(b); Select all of the following pieces of code that would compile and run with no errors, printing the value of 1 followed by the value of 2, each on separate lines. A. public class A { private int y; public A(int y) { this.y = y; } public int getY() { return y; }...
q2: Write a public class named MythMouseListener that implements the Mouselistener interface. This class will have a public constructor that takes a JTextArea and a JLabel as parameters and stores these in instance variables. Override the mouseEntered method to . display the text from the JTextArea on the JLabel in all upper case letters. Then, override the mouseReleased method to display the text from the JTextArea on the JLabel in all lower case letters. The other three methods from the...
public class Car { /* four private instance variables*/ private String make; private String model; private int mileage ; private int year; // /* four argument constructor for the instance variables.*/ public Car(String make) { super(); } public Car(String make, String model, int year, int mileage) { super(); this.make = make; this.model...
public class Item implements Comparable { private String name; private double price; /** * Constructor for objects of class Item * @param theName name of item * @param thePrice price of item */ public Item(String theName, double thePrice) { name = theName; price = thePrice; } /** * gets the name * @return name name of item */ public String getName() { return name; } /** * gets price of item * @return price price of item */...
GIVEN CODES
*****Boat.java*****
import java.util.HashSet;
import java.util.Set;
public class Boat {
private String name; //private instance variable name of type String
private String boatClass; //private instance variable boatClass of type String
private int regNum; //private instance variable regNum of type int
private Set<String> crew = new HashSet<String>();
public void setName(String name) {
this.name = name;
}
public void setBoastClass(String boatClass) {
this.boatClass = boatClass;
}
public void setRegNum(int regNum) {
this.regNum = regNum;
}
public String getName() {
return name;...