Task 1:
1. Write a generic class named MyList, with a type parameter T. The type parameter T should be constrained to an upper bound: the Number class. The class should have as a field an ArrayList of type T. Write the class constructor to create the ArrayList.
2. Write a public method named add, which accepts a parameter of type T. When an argument is passed to the method, add it to the ArrayList.
3. Write a public method display to display all items in the list for testing purpose. Test your class with an instance of type Integers and one of type Double.
4. Write two other methods, largest and smallest, which return the largest and smallest values in the ArrayList.
5. Test the class and its three methods in a program that creates one instance of MyList to store Integers. Demo your program for credit.
Task 2:
1. Modify the MyList class that you wrote in Task 1 so the type parameter T should accept any type that implements the Comparable interface.
2. Test the class in a program that creates one instance of MyList to store Integers, another instance to store Strings, and one instance to store objects of a class type that you define separately (e.g. Employee or Customer etc). Demo your program for credit.
import java.util.ArrayList;
public class MyList<T extends Number> {
ArrayList<T> mylist;
MyList() {
mylist = new ArrayList<T>();
}
public void add(T t) {
mylist.add(t);
}
public T min() {
T min = mylist.get(0);
for (T i : mylist) {
if (i.doubleValue() < min.doubleValue())
min = i;
}
return min;
}
public T max() {
T max = mylist.get(0);
for (T i : mylist) {
if (i.doubleValue() > max.doubleValue())
max = i;
}
return max;
}
public String toString() {
return mylist.toString();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
MyList<Double> list = new MyList<Double>();
list.add(2.0);
list.add(8.4);
System.out.println(list.toString());
System.out.println(list.max());
System.out.println(list.min());
MyList<Integer> Ilist = new MyList<Integer>();
Ilist.add(2);
Ilist.add(8);
System.out.println(Ilist.toString());
System.out.println(Ilist.max());
System.out.println(Ilist.min());
}
}
=====================================================================
See Image for TASK 1

=================================================================================
2)
import java.util.ArrayList;
public class MyList<T extends Comparable<T>> {
ArrayList<T> mylist;
MyList() {
mylist = new ArrayList<T>();
}
public void add(T t) {
mylist.add(t);
}
public T min() {
T min = mylist.get(0);
for (T i : mylist) {
if (i.compareTo(min) < 0)
min = i;
}
return min;
}
public T max() {
T max = mylist.get(0);
for (T i : mylist) {
if (i.compareTo(max) > 0)
max = i;
}
return max;
}
public String toString() {
return mylist.toString();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
MyList<String> list = new MyList<String>();
list.add("Chegg");
list.add("123");
System.out.println(list.toString());
}
}
=------------------------------------------------------------------------------------------------------------------------------------

Task 1: 1. Write a generic class named MyList, with a type parameter T. The type...
Please Do It With Java. Make it copy paste friendly so i can
run and test it.
Thnak You.
Write programs for challenges 1 and 2 and 6 at the end of the chapter on Generics. 1) Write a generic class named MyList, with a type parameter T. The type parameter T should be constrained to an upper bound: the Number class. The class should have as a field an ArrayList of T. Write a public method named add, which...
2)- MyList Modification (Java) Modify the MyList class that you wrote for Programming Challenge 1 so that the type parameter T should accept any type that implements the Comparable interface. Test the class in a program that creates one instance of MyList to store Integers, and another instance to store Strings. Mylist.java import java.util.*; import java.math.BigDecimal; public class MyList <T extends Number> { private ArrayList <T> num = new ArrayList<>(); static MyList<Number> list = new MyList<>(); public...
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...
(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...
Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look approximately like this: Enter the name for score #1: Suzy Enter the score for score #1: 600 Enter the name for score...
Assume a class exists named MyList that has contained in it a data attribute of type MyNode that is named head. The class MyList represents a singly-linked list. In the MyNode class, there is a getter method named getNext() that returns he next node in the linked list. Implement an instance method named print() that takes no formal parameters, returns nothing, and prints out the string representation of each node in the linked list from head to tail, with each...
DIRECTIONS FOR THE WHOLE PROJECT BELOW BigInt class The purpose of the BigInt class is to solve the problem using short methods that work together to solve the operations of add, subtract multiply and divide. A constructor can call a method called setSignAndRemoveItIfItIsThere(). It receives the string that was sent to the constructor and sets a boolean variable positive to true or false and then returns a string without the sign that can then be processed by the constructor to...
Write a generic array list class. Task Description Your goal for this lab is to write a generic ArrayList class similar to the one in the given lecture notes on array lists. The ArrayList Class The public constructors and methods required for the ArrayList class are listed here. The type E is the generic type of an element of the list. ArrayList() Construct an empty ArrayList object. int size() Return the size (number of items) in this ArrayList. boolean isEmpty()...
Write a class named PhoneBookEntry that has fields for a person's name and phone number.The class should have a constructor and appropriate accessor and mutator methods. Thenwrite a program that creates at least five PhoneBookEntry objects and stores them in anArrayLitt. Use a loop to display the contents of each object in the ArrayList.
The first programming project involves writing a program that computes the minimum, the maximum and the average weight of a collection of weights represented in pounds and ounces that are read from an input file. This program consists of two classes. The first class is the Weight class, which is specified in integer pounds and ounces stored as a double precision floating point number. It should have five public methods and two private methods: 1. A public constructor that allows...