Question
Generic Method Exercise 1 1- Create class Student that has the following data: id(int), name(string), gpa (double), generate constructor, setter/getter and toString methods. 2- Create
Generic Method Exercise 1
1- Create class Student that has the following data: id(int), name(string), gpa (double), generate constructor, setter/getter and toString methods.
2- Create class Car that has the following data: plateNo(int), brand(String), generate constructor, setter/getter and toString methods.
3- Create a new class, call it GM_Test, in the class create
a- generic method called swapFirstLast, it receives a generic type array, and swaps the last element in the array with the first one.
b- generic method called reverse, it receives a generic type array, and reverse the order of the elements in the array.
c- Generic method shift that receives an a generic type array and shifts its element one position to the left as depicted by the following figure S
d- Generic method print that receives a generic type array and prints its elements.
e- Create main method, and in the method create the following arrays and fill them with elements:
Array of students (3 elements)
Array of cars (4 elements)
f- In the main method, call the methods in a,b,c on the array of students and cars. Each time, print the array before you call the method, then print it after calling the method to see its effects.
g- Create the following arrays: int intArray[]={4,1,7,9};
char chArray[]={a,b,c,d};
call the methods in a,b,c on the array of intArray and chArray. Each time, print the array before you call the method, then print it after calling the method to see its effects.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started