Question: HAVE JAVE CODE FOR TASK 1, NEED HELP WITH TASK 2(HAVE CODE FOR TASK 2 ALSO JUST NEED YOU RECHECK IT AND REMOVE ONE ERROR)
HAVE JAVE CODE FOR TASK 1, NEED HELP WITH TASK 2(HAVE CODE FOR TASK 2 ALSO JUST NEED YOU RECHECK IT AND REMOVE ONE ERROR) AND TASK 3:
Task 1:
Create a Student Class that encapsulates the concept of a student. The attributes of a student are:
id
a random integer in the range 0 to 9999999 (i.e. like an NDSU student ID number)
do NOT allow for duplicate id numbers
lname
a String of a random length between 10 and 15 random characters that represent the students last name
the first character should be an upper-case character
the remaining characters should be lower-case.
The strings do not have to resemble actual names
fname
a String of a random length between 5 and 10 random characters that represent the students first name
the first character should be an upper-case character
the remaining characters should be lower-case.
The strings do not have to resemble actual names
standinga string that represents the class standing of the student. The string must be one of the following (distributed as indicated):
senior 10%
junior 20%
sophomore 30%
freshman 40%
gpaa two decimal place floating point number in the range 0.00 to 4.00 (distributed as indicated):
4.00 5%
3.00 to 3.99 20%
2.00 to 2.99 50%
1.00 to 1.99 20%
0.00 to 0.99 5%
Task 2:
Create a class named Sort that will act as a container for the following generic array sorting algorithms:
simpleBubbleSort
a brute force bubble sort that just uses a pair of nested loops
this needs to be a generic bubble sort
this needs to be a stable sort
insertionSort
an iterative sort described on pages 524 and 525 of the Java Illuminated Text
modify this code to make it a generic sort
selectionSort
an iterative sort described on pages 524 and 525 of the Java Illuminated Text
modify this code to make it a generic sort
mergeSort
this should be the recursive mergeSort described in the textbook
quickSort
this should be the recursive quickSort described in the textbook
you may have to modify this code
radixSort
as described in lecture, not as described in the textbook
the generic radixSort should be written to support between two and four keys
the first parameter in the parameter list should be the array being sorted.
the remaining parameters in the parameter list should be the keys, ordered left to right from most significant to least significant
Task 3:
Create the necessary number of concrete comparators for each of the attributes of the Student class.
STUDENT CLASS :
public class Student { int ID; String Lname; String Fname; String Standing; float GPA; public Student(int id, String Lname, String Fname, String Standing,float GPA) { this.ID = id; this.Lname = Lname; this.Fname = Fname; this.Lname = Lname; this.Standing = Standing; this.GPA = GPA; } public Student() { this.ID = generateRandomNumber(); this.Lname = generateRandomLastName(); this.Fname = generateRandomFirstName(); this.Standing = generateRandomStanding(); this.GPA = generateRandomGPA(); } public float generateRandomGPA() { Random random = new Random(); float gpa = (float) (0.00 + random.nextFloat() * (4.00 - 0.00)); return gpa; } public String generateRandomStanding() { Random rand = new Random(); int number = rand.nextInt(4) + 1; HashMap standingMap = new HashMap(); standingMap.put(1, "senior"); standingMap.put(2, "junior"); standingMap.put(3, "sophomore"); standingMap.put(4, "freshman"); String standing = standingMap.get(number); return standing; } public String generateRandomFirstName() { char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray(); StringBuilder sb = new StringBuilder(); Random random = new Random(); for (int i = 0; i < 15; i++) { char c = chars[random.nextInt(chars.length)]; sb.append(c); } String firstName = sb.toString().substring(0, 1).toUpperCase() + sb.toString().substring(1); return firstName; } public int generateRandomNumber() { Random rand = new Random(); int number = rand.nextInt(9999999) + 0; return number; } public String generateRandomLastName() { char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray(); StringBuilder sb = new StringBuilder(); Random random = new Random(); for (int i = 0; i < 15; i++) { char c = chars[random.nextInt(chars.length)]; sb.append(c); } String lastName = sb.toString().substring(0, 1).toUpperCase() + sb.toString().substring(1); return lastName; } public int getID() { return ID; } public String getLname() { return Lname; } public String getFname() { return Fname; } public String getStanding() { return Standing; } public float getGPA() { return GPA; } }
SORT CLASS :
public class Sort { public static void simpleBubbleSort(K[]data,Comparatorcomp){ for ( int i =0;i for(int j=i+1;j { if(comp.compare(data[i], data[j])<0) { K temp=data[i]; data[i]=data[j]; data[j]=temp ; } } } public static void slectionSort(K[]data,Comparatorcomp){ K temp; int indexOfMax; for(int i=0;i indexOfMax = indexOfLargestElement(data,data.length-i,comp); temp = data[indexOfMax]; data[indexOfMax]=data[data.length-i-1]; data[data.length-i-1]=temp; } } public static void insertionSort(K[]data, Comparator comp){ int j; K temp; for(int i =1;i j=i; temp = data[i]; while(j!=0 && comp.compare(data[j-1], temp)<0){ data[j] = data[j-1]; j--; } data[j]=temp; } } public static void mergeSort(K[]S,Comparatorcomp){ int n=S.length; if(n<2) return; int mid = n/2; K[]S1 = Arrays.copyOfRange(S, 0, mid); K[]S2 = Arrays.copyOfRange(S, mid, n); mergeSort(S1,comp); mergeSort(S2,comp); merge(S1,S2,S,comp); } public staticvoid quickSortInPlace(K[]S,Comparatorcomp,int a, int b){ if(a>=b) return; int left=a; int right = b-1; K pivot = S[b]; K temp; while(left<=right){ // scan until reaching value equal or larger than pivot(or right marker) while(left <= right && comp.compare(S[left], pivot) > 0) left++; // scan until reaching value equal or smaller than pivot(or left marker) while(left <= right && comp.compare(S[right],pivot) > 0) // (96) > 50 comp: -1 < 0 true right-- ; if(left<=right){ temp = S[left]; S[left]=S[right]; S[right]=temp; left++; right--; } } temp = S[left]; S[left]=S[right]; S[right]=temp; quickSortInPlace(S,comp,a,left-1); quickSortInPlace(S,comp,left+1,b); } public static void radixSort(K[]data,ArrayBag>compList){ int lowKeyIndex = compList.getCurrentSize()-1; mergeSort(data,compList.get(lowKeyIndex)); mergeSort(data,compList.get(lowKeyIndex-1)); mergeSort(data,compList.get(lowKeyIndex-2)); } /** private static int indexOfLargestElemnet(K[]array,int size, Comparatorcomp){ int index = 0; for(int i=0;i if(comp.compare(array[i], array[index])<0) ascending order; A-Z array[index].value, then index=i; } } private static void merge(K[] S1, K[]S2, K[] S,Comparator comp) { int i = 0; int j = 0; while(i+j < S.length) { if(j== S2.length || (i < S1.length && comp.compare(S1[i],S2[j])>0)) {// if element at S1(11) > el @ S2(10)--> -1 > 0 false; S[i+j] = S1[i++]; }// copy ith element of S1 and increment i; else S[i+j] = S2[j++]; // copty jth element and increment j } }*/
private static
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
