There are some errors in "TestSL.java"
Below are some classes to help you to correct the "TestSL.java".
// class Student (abstracted class)
abstractpublicclass Student
{
protected String name;
protecteddouble mark;
public Student(String name)
{
this.name = name;
mark = 0.0;
}
public String getName()
{
return name;
}
publicvoid setName(String inName)
{
name = inName;
}
publicdouble getMark()
{
return mark;
}
publicabstractvoid calcMark();
publicchar grade()
{
if (mark < 50)
return'F';
elseif (mark < 65)
return'D';
elseif (mark < 75)
return'C';
elseif (mark < 85)
return'B';
else
return'A';
}
publicboolean equals(Object obj)
{
if (!(objinstanceof Student))
returnfalse;
Student s = (Student) obj;
return this.name.equalsIgnoreCase(s.name);
}
// can only be displayed after mark is known
public String toString()
{
return name +" scored " + getMark() +", grade = " + grade();
}
}
// StudentList.java
/**
* The StudentList class implements a growable array of Student objects.
*/
publicclass StudentList
{
privatestaticfinalint DEFAULT_SIZE = 5;
private Student[] array;
privateint count;
/**
* Constructs an empty StudentList with the specified initial capacity.
*/
public StudentList(int capacity)
{
if (capacity > 0)
array =new Student[capacity];
else
array =new Student[DEFAULT_SIZE];
count = 0;
}
/**
* Constructs an empty StudentList so that its internal data array has size 5.
*/
public StudentList()
{
this(DEFAULT_SIZE);
}
/**
* Appends the specified element to the end of this list.
*/
publicvoid add(Student s)
{
add(s, count);
}
/**
* Inserts the specified element at the specified position in this list.
* Shifts the element currently at that position (if any) and any subsequent
* elements to the right (adds one to their indices).
*/
publicboolean add(Student s,int index)
{
// check for valid index
if (index >= 0 && index <= count)
{
if (count == array.length)
array = resize(array.length * 2, array);
// move students up
for (int i = count; i > index; i--)
array[i] = array[i-1];
array[index] = s;
count ++;
returntrue;// success
}
returnfalse;// failure
}
/**
* Returns the element at the specified position in this list.
*/
public Student get(int index)
{
if (index >= 0 && index < count)
return array[index];
returnnull;
}
/**
* Removes the first occurrence of the specified element in this list. If
* the list does not contain the element, it is unchanged.
*/
publicboolean remove(Student s)
{
// search for student
int pos = find(s.getName());
if (pos != -1)// found
{
remove(pos);// invoke remove(int)
returntrue;
}
else
returnfalse;
}
/**
* Removes the element at the specified position in this list, shifts any
* subsequent elements to the left (subtracts one from their indices).
* Returns the element that was removed from the list.
*/
public Student remove(int index)
{
if (index >= 0 && index < count)
{
Student temp = array[index];
for (int i = index+1; i < count; i++)
array[i-1] = array[i];
count --;
return temp;
}
returnnull;
}
/**
* Search for a specific Student object given the student's name.
*/
public Student search(String name)
{
int index = find(name);
return index != -1? array[index]:null;
}
/**
* Search for a specific Student object and returns its index if found.
*/
privateint find(String name)
{
for (int i = 0; i < count; i++)
if (array[i].getName().equalsIgnoreCase(name))// checks for name
return i;
return -1;
}
/**
* Resize the array when its capacity is reaching the limit by double
* the size for the new return array.
*/
private Student[] resize(int newSize, Student[] s)
{
int numToCopy = Math.max(newSize, s.length);
Student[] temp =new Student[newSize];
for (int i = 0; i < s.length; i++)
temp[i] = s[i];
return temp;
}
/**
* Returns the number of components in this list.
*/
publicint size()
{
return count;
}
/**
* Returns the current capacity of this array.
*/
publicint capacity()
{
return array.length;
}
/**
* Returns an array containing all of the elements in this list in the
* correct order.
*/
public Student[] toArray()
{
Student[] temp =new Student[count];
for (int i = 0; i < count; i++)
temp[i] = array[i];
return temp;
}
}
// StudentADP.java
publicclass StudentADPextends Student{
privatedouble assign;// 15%
privatedouble midTermE, finalE;// mid-term - 35%, final - 50%
public StudentADP(String name,double a,double mTE,double fE){
super(name);
assign = a;
midTermE = mTE;
finalE = fE;
calcMark();// immediately called to set mark
}
publicvoid calcMark(){
mark = 0.15 * assign + 0.35 * midTermE + 0.5 * finalE;
}
}
// StudentBus.java
publicclass StudentBusextends Student{
privatedouble assign1, assign2;// 1st - 15%, 2nd - 25%
privatedouble finalE;// 60%
public StudentBus(String name,double a1,double a2,double fE){
super(name);
assign1 = a1;
assign2 = a2;
finalE = fE;
calcMark();// immediately called to set mark
}
publicvoid calcMark(){
mark = 0.15 * assign1 + 0.25 * assign2 + 0.6 * finalE;
}
}
//StudentIT.java
publicclass StudentITextends Student{
privatedouble assign1, assign2, assign3;// 1st - 15%, 2nd - 10% ,
privatedouble finalE;// 3rd - 20%, final - 55%
public StudentIT(String name,double a1,double a2,double a3,double fE){
super(name);
assign1 = a1;
assign2 = a2;
assign3 = a3;
finalE = fE;
calcMark();// immediately called to set mark
}
publicvoid calcMark(){
mark = 0.15 * assign1 + 0.10 * assign2 + 0.25 * assign3 + 0.6 * finalE;
}
}
//EasyIn.java - allows the user to type in.
import java.io.*;
publicabstractclass EasyIn
{
publicstatic String getString()
{
boolean ok =false;
String s =null;
while(!ok)
{
byte[] b =newbyte[512];
try
{
System.in.read(b);
s =new String(b);
s = s.trim();
ok =true;
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
return s;
}
publicstaticint getInt()
{
int i = 0;
boolean ok =false;
String s ;
while(!ok)
{
byte[] b =newbyte[512];
try
{
System.in.read(b);
s =new String(b);
i = Integer.parseInt(s.trim());
ok =true;
}
catch(NumberFormatException e)
{
System.out.println("Make sure you enter an integer");
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
return i;
}
publicstaticbyte getByte()
{
byte i = 0;
boolean ok =false;
String s ;
while(!ok)
{
byte[] b =newbyte[512];
try
{
System.in.read(b);
s =new String(b);
i = Byte.parseByte(s.trim());
ok =true;
}
catch(NumberFormatException e)
{
System.out.println("Make sure you enter a byte");
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
return i;
}
publicstaticshort getShort()
{
short i = 0;
boolean ok =false;
String s ;
while(!ok)
{
byte[] b =newbyte[512];
try
{
System.in.read(b);
s =new String(b);
i = Short.parseShort(s.trim());
ok =true;
}
catch(NumberFormatException e)
{
System.out.println("Make sure you enter a short integer");
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
return i;
}
publicstaticlong getLong()
{
long l = 0;
boolean ok =false;
String s ;
while(!ok)
{
byte[] b =newbyte[512];
try
{
System.in.read(b);
s =new String(b);
l = Long.parseLong(s.trim());
ok =true;
}
catch(NumberFormatException e)
{
System.out.println("Make surre you enter a long integer");
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
return l;
}
publicstaticdouble getDouble()
{
double d = 0;
boolean ok =false;
String s ;
while(!ok)
{
byte[] b =newbyte[512];
try
{
System.in.read(b);
s =new String(b);
d = Double.parseDouble(s.trim());
ok =true;
}
catch(NumberFormatException e)
{
System.out.println("Make sure you enter a decimal number");
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
return d;
}
publicstaticfloat getFloat()
{
float f = 0;
boolean ok =false;
String s;
while(!ok)
{
byte[] b =newbyte[512];
try
{
System.in.read(b);
s =new String(b);
f = Float.parseFloat(s.trim());
ok =true;
}
catch(NumberFormatException e)
{
System.out.println("Make sure you enter a decimal number");
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
return f;
}
publicstaticchar getChar()
{
char c =' ';
boolean ok =false;
String s;
while(!ok)
{
byte[] b =newbyte[512];
try
{
System.in.read(b);
s =new String(b);
if(s.trim().length()!=1)
{
System.out.println("Make sure you enter a single character");
}
else
{
c = s.trim().charAt(0);
ok =true;
}
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
return c;
}
publicstaticvoid pause()
{
boolean ok =false;
while(!ok)
{
byte[] b =newbyte[512];
try
{
System.in.read(b);
ok =true;
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
}
publicstaticvoid pause(String messageIn)
{
boolean ok =false;
while(!ok)
{
byte[] b =newbyte[512];
try
{
System.out.print(messageIn);
System.in.read(b);
ok =true;
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
}
}
Finally, this is the Java class (TestSL.java) which contains some errors. Can you help me?
/**
* A program to test the StudentList class. (TestSL.java)
*
* Written by Lam Chou Yin @ Edwin
* Written on 17 October 2004
*/
publicclass TestSL
{
publicstatic Student[] s;
publicstatic Student student;
publicstatic StudentList sl;
publicstaticint size;
publicstaticvoid main(String[] args)
{
int choice;
System.out.println("Maximum number of students in list? ");
size = EasyIn.getInt();
// create generic list
s =new Student[size];
// offer menu for a student list
do
{
System.out.println();
System.out.println("1. Add a new student to the collection.");
System.out.println("2. Add a new student to a specific location.");
System.out.println("3. Delete a student from the list given the name.");
System.out.println("4. Delete a student in a specific location.");
System.out.println("5. Search a student given the name.");
System.out.println("6. Search a student at a given location.");
System.out.println("7. Update a student.");
System.out.println("8. Display the number of students in the collection.");
System.out.println("9. Display the information of all students in the collection.");
System.out.println("10. Quit the application.");
System.out.println();
System.out.print("Enter choice [1 - 10]: ");
choice = EasyIn.getInt();
System.out.println();
// process choice
switch (choice)
{
case 1:
{
addStudent();
break;
}
case 2:
{
addStudentIndex();
break;
}
case 3:
{
removeStudent();
break;
}
case 4:
{
removeStudentIndex();
break;
}
case 5:
{
searchStudent();
break;
}
case 6:
{
getStudent();
break;
}
case 7:
{
updateStudent();
break;
}
case 8:
{
displaySize();
break;
}
case 9:
{
displayAllStudents();
break;
}
case 10:
{
break;
}
default:
{
System.out.println("Invalid entry");
break;
}
}
}
while (choice != 10);
}
publicstaticvoid addStudent()
{
int choose;
do
{
choose = department();
switch (choose)
{
case 1:
{
addADPStudent();
break;
}
case 2:
{
addBusStudent();
break;
}
case 3:
{
addITStudent();
break;
}
case 4:
{
break;
}
default:
{
System.out.println("Invalid entry");
break;
}
}
}
while (choose != 4);
}
publicstaticvoid addStudentIndex()
{
int c;
do
{
c = department();
switch (c)
{
case 1:
{
addADPStudentIndex();
break;
}
case 2:
{
addBusStudentIndex();
break;
}
case 3:
{
addITStudentIndex();
break;
}
case 4:
{
break;
}
default:
{
System.out.println("Invalid entry");
}
}
}
while (c != 4);
}
publicstaticvoid removeStudent()
{
System.out.print("Enter a student name: ");
String name = EasyIn.getString();
student = sl.remove(name);
if (student !=null)
{
System.out.println("Student is removed successful.");
}
else
{
System.out.println("No such name.");
}
}
publicstaticvoid removeStudentIndex()
{
System.out.print("Enter position to remove: ");
int position = EasyIn.getInt();
student = sl.remove(position);
if (student !=null)
{
System.out.println("Student is removed successful.");
}
else
{
System.out.println("No such position.");
}
}
publicstaticvoid searchStudent()
{
System.out.print("Enter a student name: ");
String name = EasyIn.getString();
student = sl.search(name);
if (student !=null)
{
System.out.println(student);
}
else
{
System.out.println("No such name.");
}
}
publicstaticvoid getStudent()
{
System.out.print("Enter position to search: ");
int position = EasyIn.getInt();
student = sl.get(position);
if (student !=null)
{
System.out.println(student);
}
else
{
System.out.println("No such position.");
}
}
publicstaticvoid updateStudent()
{
System.out.print("Enter a student name: ");
String name = EasyIn.getString();
student = sl.search(name);
if (student !=null)
{
System.out.print("Enter the new name: ");
String inName = EasyIn.getString();
student.setName(inName);
System.out.println("Update successfully.");
}
else
{
System.out.println("No student with name " + name +"!");
}
}
publicstaticvoid displaySize()
{
System.out.println("The total number of students is " + sl.size());
}
publicstaticvoid displayAllStudents()
{
for (int i = 0; i < s.length; i++)
{
System.out.println(s[i]);
}
System.out.println("");
}
publicstaticint department()
{
System.out.println();
System.out.println("1. American Degree Program");
System.out.println("2. Business");
System.out.println("3. Information Technology");
System.out.println("4. Return to menu.");
System.out.println();
System.out.print("Enter choice [1 - 4]: ");
int ch = EasyIn.getInt();
return ch;
}
publicstaticvoid addADPStudent()
{
System.out.print("Enter a student name: ");
String name = EasyIn.getString();
System.out.print("Enter an assignment\'s mark: ");
double assign = EasyIn.getDouble();
System.out.print("Enter a mid-term examination\'s mark: ");
double midTermE = EasyIn.getDouble();
System.out.print("Enter a final examination\'s mark: ");
double finalE = EasyIn.getDouble();
for (int i = 0; i < s.length; i++)
{
s[i] =new StudentADP(name, assign, midTermE, finalE);
sl =new StudentList();
if (sl.add(s[i])
{
System.out.println("Student is added successful.");
}
else
{
System.out.println("Can\'t add to a full list.");
}
}
}
publicstaticvoid addBusStudent()
{
System.out.print("Enter a student name: ");
String name = EasyIn.getString();
System.out.print("Enter the first assignment\'s mark: ");
double assign1 = EasyIn.getDouble();
System.out.print("Enter the second assignment\'s mark: ");
double assign2 = EasyIn.getDouble();
System.out.print("Enter a final examination\'s mark: ");
double finalE = EasyIn.getDouble();
for (int i = 0; i < s.length; i++)
{
s[i] =new StudentBus(name, assign1, assign2, finalE);
sl =new StudentList();
if (sl.add(s[i])
{
System.out.println("Student is added successful.");
}
else
{
System.out.println("Can\'t add to a full list.");
}
}
}
publicstaticvoid addITStudent()
{
System.out.print("Enter a student name: ");
String name = EasyIn.getString();
System.out.print("Enter the first assignment\'s mark: ");
double assign1 = EasyIn.getDouble();
System.out.print("Enter the second assignment\'s mark: ");
double assign2 = EasyIn.getDouble();
System.out.print("Enter the third assignment\'s mark: ");
double assign3 = EasyIn.getDouble();
System.out.print("Enter a final examination\'s mark: ");
double finalE = EasyIn.getDouble();
for (int i = 0; i < s.length; i++)
{
s[i] =new StudentIT(name, assign1, assign2, assign3, finalE);
sl =new StudentList();
if (sl.add(s[i])
{
System.out.println("Student is added successful.");
}
else
{
System.out.println("Can\'t add to a full list.");
}
}
}
publicstaticvoid addADPStudentIndex()
{
System.out.print("Enter a student name: ");
String name = EasyIn.getString();
System.out.print("Enter an index: ");
int index = EasyIn.getInt();
System.out.print("Enter an assignment\'s mark: ");
double assign = EasyIn.getDouble();
System.out.print("Enter a mid-term examination\'s mark: ");
double midTermE = EasyIn.getDouble();
System.out.print("Enter a final examination\'s mark: ");
double finalE = EasyIn.getDouble();
for (int i = 0; i < s.length; i++)
{
s[i] =new StudentADP(name, assign, midTermE, finalE);
sl =new StudentList();
if (sl.add(s[i], index)
{
System.out.println("Student is added successful.");
}
else
{
System.out.println("The index of " + index +" cannot be found or full.");
}
}
}
publicstaticvoid addBusStudentIndex()
{
System.out.print("Enter a student name: ");
String name = EasyIn.getString();
System.out.print("Enter an index: ");
int index = EasyIn.getInt();
System.out.print("Enter the first assignment\'s mark: ");
double assign1 = EasyIn.getDouble();
System.out.print("Enter the second assignment\'s mark: ");
double assign2 = EasyIn.getDouble();
System.out.print("Enter a final examination\'s mark: ");
double finalE = EasyIn.getDouble();
for (int i = 0; i < s.length; i++)
{
s[i] =new StudentBus(name, assign1, assign2, finalE);
sl =new StudentList();
if (sl.add(s[i], index)
{
System.out.println("Student is added successful.");
}
else
{
System.out.println("The index of " + index +" cannot be found or full.");
}
}
}
publicstaticvoid addITStudentIndex()
{
System.out.print("Enter a student name: ");
String name = EasyIn.getString();
System.out.print("Enter an index: ");
int index = EasyIn.getInt();
System.out.print("Enter the first assignment\'s mark: ");
double assign1 = EasyIn.getDouble();
System.out.print("Enter the second assignment\'s mark: ");
double assign2 = EasyIn.getDouble();
System.out.print("Enter the third assignment\'s mark: ");
double assign3 = EasyIn.getDouble();
System.out.print("Enter a final examination\'s mark: ");
double finalE = EasyIn.getDouble();
for (int i = 0; i < s.length; i++)
{
s[i] =new StudentIT(name, assign1, assign2, assign3, finalE);
sl =new StudentList();
if (sl.add(s[i], index)
{
System.out.println("Student is added successful.");
}
else
{
System.out.println("The index of " + index +" cannot be found or full.");
}
}
}
}
TestSL.java:')' expected at line 295, 320, 347, 374, 401, 430
TestSL.java: Illegal start of expression at line 302, 327, 354, 381, 408, 437
Hope to reply soon.

