Question: Create an interface named InterfaceI with a generic type T. Create an abstract method named methodA that returns a type T. Create a default method
Create an interface named InterfaceI with a generic type T.
Create an abstract method named methodA that returns a type T.
Create a default method named methodB that returns void and prints methodB.
Create a static method named methodC that returns void and prints methodC.
Create a record named RecordA with generic type T and has an attribute of type T name t and implements InterfaceI with generic type T.
Create a method named methodA that returns the attribute t. Create a record named RecordB with generic type T and has an attribute of type T name t and implements InterfaceI with generic type T.
Create a method named methodA that returns the attribute t.
Create a record named RecordC with two attributes: Optional optional1, Optional optional2.
Create a constructor method RecordC which has one statement this( Optional.empty(), Optional.of(1) );
Create a Main class with a main method that instantiates the Main class and calls the go method.
Create an int variable named integer1 with the value 5. Create a double variable name double1 with the value 10.
Instantiate a variable of type RecordA and generic type of Integer and passing it integer1.
Instantiate a variable of type RecordB and generic type of Double and passing it double1.
Instantiate a variable of type RecordC.
Instantiate a variable of type Scanner named in to refer to System.in.
Create a String named menu using a Block String the prints a blank denoted by the \040: Main Menu 1. RecordA 2. RecordB 3. RecordC 9. Exit >\040
Using an endless loop that prints the menu.
Read a character from the keyboard named opt.
Use an enhanced switch on opt.
The case 1 should print the value returned by the recordA methodA, call the recordA methodB, and the InterfaceI methodC.
The case 2 should print the value returned by the recordB methodA, call the recordB methodB, and the InterfaceI methodC.
The case 3 should print have two statements: printOptional(recordC.optional1()); printOptional(recordC.optional2());
The case 9 should print Goodbye and call System.exit(0).
The otherwise case should print invalid response.
Create a printOptional method like this: private void printOptional(Optional optional) { System.out.println(optional); System.out.println(optional.orElse(-1)); System.out.println(); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
