Write a java program that creates two interfaces named test1 and test2. In interface test1 the member function is square. In interface test2 the member function is cube. Implement these two interfaces in "Arithmetic" class. Create one new class called ToTestInt in this class use the object of arithmetic class.
Java Code:
interface test1 //interface test1
{
abstract int square(int x);
}
interface test2 //interface test2
{
abstract int cube(int x);
}
class Arithmetic implements test1,test2{ //class Arithmetic
public int square(int x) //implementing square method
{
return x*x;
}
public int cube(int x) //implementing cube method
{
return x*x*x;
}
}
public class ToTestInt
{
public static void main(String[] args) {
Arithmetic a=new Arithmetic(); //creating an object of
Arithmetic class
int square=a.square(9); //using object of Arithmetic
class to call square method
int cube=a.cube(9); //using object of Arithmetic class
to call cube method
System.out.println(square);
//printing the square result
System.out.println(cube);
//printing the cube result
}
}

Output:

Note:
Please save the above program in a file name "ToTestInt.java" and then compile and execute it.
Please comment if you face any difficulty.
Write a java program that creates two interfaces named test1 and test2. In interface test1 the...
Java program. Code the following interfaces, implement them, and use the interface as a parameter, respectively: a. An interface called Printable with a void print() method. b. An interface called EmployeeType with FACULTY and CLASSIFIED integer data. The value of FACULTY is 1 and CLASSIFIED is 2. a. A class called Employee to implement the two interfaces. Its constructor will initialize three instance data as name, employeeType, and salary. Implementation of method print() will display name, employeeType, and salary; salary...
In JAVA: For this question, you need to create two interface programs in a package and import them to the class where you implement the methods. You can create a new package in your assignment4 project (or package) to contain the two interface programs. One of the interface program has two methods ( countOne(), countTwo() ) and the other interface program has only one method (countThree ( ) ). In a separate package, write a class to implement the two...
(The interface class-like) Assume you have the Edible interface with its abstract method. Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make implement the Edible interface. howToEat() and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML diagram for the classes and the interface 2. Use Arraylist class to create an...
You will write a single java program called MadLibs. java. This file will hold and allow access to the values needed to handle the details for a "MadLibs" game. This class will not contain a maino method. It will not ask the user for any input, nor will it display (via System.out.print/In()) information to the user. The job of this class is to manage information, not to interact with the user.I am providing a MadLibsDriver.java e^{*} program that you can...
Design an interface named Colorable with a void method named howToColor(). Every class of a colorable object must implement the Colorable interface. Design a class named Square that extends GeometricObjectand implements Colorable. Design another class named Trianglethat extends GeometricObjectand implements Colorable. Implement howToColor inSquareto display the message Color all four sides. ImplementhowToColor inTriangleto display the message Color all three sides. Draw a UML diagram that involves Colorable, Square, Triangle, and GeometricObject. Write a test program that creates an array of...
JAVA INTERFACE 1.Suppose you want to design a class that is given numbers one at a time. The class computes the smallest, second smallest, and average of the numbers that have been seen so far. Create an interface for the class. Create a class that implements the interface. 2. Create an interface Measurable with methods getarea( )and getperimeter(). Implement it in two classes Circle, and Square . Both the classes should have Constructor for initializing the dimensions, and define the...
-please use java 3. Interface: Implement a program that creates an Interfacecalled Vehiclewith the following abstract methods(getters): getMake(), getModel(), getYear(), and creates a Classcalled Carthatimplements the Vehicleinterface. The Carclass also contains instance data that represents the make, model, and year of the carand the constructor to initialize these values.Create a driver class called CarTest, whose main method instantiates a Carobject with the following information: Chevrolet, Impala, 2019, and test the getter methods you implement. 4. Abstract Class: Implement the above...
Exercise 8 (The interface class-like) Assume you have the Edible interface with its abstract method Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make Chicken and Cow as subclasses of Dairy. The Sheep and Dairy classes implement the Edible interface. howToEat) and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML...
Write a java program to create a class named shape. In this class we have two sub classes circle and square.
Please teach me how to use function interface by java ● Write a functional interface StringOperator with the method performOperation that takes two references to String objects as parameters. ● In a driver program, use lambda expressions to create two different objects that implement the StringOperator interface. ○ One of them concatenates the two Strings, returning the new String ○ One of them sets the first String to all uppercase and the second String to all lowercase and then concatenates...