Question: 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

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 {

private ArrayList num = new ArrayList<>(); static MyList list = new MyList<>(); public ArrayList getNum() { return num; } public void setNum(ArrayList num) { this.num = num; } public T Largest() { T high=(T) list.getNum().get(0); for(Number a:num) { if(a.longValue()>high.longValue()) { high=(T) a; } } return high; } public T Smallest() { T low=(T) list.getNum().get(0); for(Number a:num) { if(a.longValue() void add(T a) { list.getNum().add(a);

}

public static void main(String args[]) { add(new BigDecimal(1)); add(new BigDecimal(5)); add(new BigDecimal(-1)); add(new BigDecimal(9)); System.out.println("Largest:"+list.Largest()); System.out.println("Lowest:"+list.Smallest()); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!