In: Computer Science
Write a program in Java for:
Starting a brand new term, you decide you want to make a good impression on your instructor. To do this, you want to create an application that helps process midterm exam scores, letting the instructor know which student(s) earned the lowest score so the instructor can suggest some extra help resources.
To begin, initialize two parallel arrays (hardcoding the values):
Once you have initialized the parallel arrays with values, display the lowest score and the student(s) with that score. Note more than one student may be “tied” for the lowest score. Your application should handle this.
An example run of the program, assuming usage of the data identified above is:
Example Run:
The lowest midterm score was 42.5.
The student(s) that earned this score:
Karen
Christopher
The student(s) may benefit from extra help.
Note: Make sure your application uses good design practices, such as using methods other than main().
For output, you must use the JOptionPane class.
import javax.swing.JOptionPane;
public class findinglowestscore{
public static ArrayList<String> findnames(double[]
marksarray,double lowestmarks,String[] namesarray)
{ArrayList<String> namesofstudents=new
ArrayList<String>();
for(int i=0;i<marksarray.length;i++)
{if(marksarray[i]==lowestmarks)
namesofstudents.add(namesarray[i]);
}
return namesofstudents;
}
public static void main(String[] args){
String[] names=new String[]
{"joey","Lisa","Karen","Mark","Christopher"};
double[] marks=new double[] {78.5,97.0,42.5,86.5,42.5};
double minmarks=Integer.MAX_VALUE;
for(int j=0;j<marks.length;j++)
{minmarks=Math.min(marks[j],minmarks);
}
ArrayList<String> name=findnames(marks,minmarks,names);
String s="";
for(String na:name)
s=s+na+"\n";
JOptionPane.showMessageDialog(null, "The lowest midterm score
was"+minmarks+".\nThe student(s) that earned this
score:\n"+s);
}
}