Kód: Vybrat vše
import javax.swing.JDialog;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JOptionPane;
import java.awt.Color;
import java.awt.Font;
public class HomeworkTRIAL
{
public static void main(String args[])
{
int choice=0, first=0, second=0, third=0, fourth = 0, fifth = 0, sixth=0;
double equiGrade=0, equi1=0, equi2=0, equi3=0, equi4=0, equi5=0, equi6=0;
String top1 = "";
String top2 = "";
String top3 = "";
String top4 = "";
String top5 = "";
String top6 = "";
String dialog = "";
JDialog.setDefaultLookAndFeelDecorated(true);
JTextArea coronaArea = new JTextArea(30,60);
JScrollPane ducutPane = new JScrollPane(coronaArea);
/*do{
JOptionPane.showInputDialog(" TOP FIVE STUDENTS\n" + "===============================\n" +
" 1 = BEGIN\n 2 = EXIT");
switch(choice){
case 1:*/
int students = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter Number of Students :","STUDENTS",JOptionPane.WARNING_MESSAGE));
for(int i = 1; i <= students; i++)
{
String name = JOptionPane.showInputDialog(null, dialog + "Enter Student's Name : [" + i + " of " + students + "]","STUDENT NAME ENTRY",JOptionPane.INFORMATION_MESSAGE);
int grade = Integer.parseInt(JOptionPane.showInputDialog(null, dialog + "Enter " + name + "'s Grade :","STUDENT GRADE ENTRY",JOptionPane.INFORMATION_MESSAGE));
if(grade >= 60)
{
if(grade <= 63)
equiGrade=1.00;
else if(grade <= 67)
equiGrade=1.25;
else if(grade <= 70)
equiGrade=1.50;
else if(grade <= 73)
equiGrade=1.75;
else if(grade <= 76)
equiGrade=2.00;
else if(grade <= 79)
equiGrade=2.25;
else if(grade <= 82)
equiGrade=2.50;
else if(grade <= 85)
equiGrade=2.75;
else if(grade <= 88)
equiGrade=3.00;
else if(grade <= 91)
equiGrade=3.25;
else if(grade <= 94)
equiGrade=3.50;
else if(grade <= 97)
equiGrade=3.75;
else if(grade <= 100)
equiGrade=4.00;
}
else
equiGrade=0.00;
dialog = dialog + " " + i + ".) " + name + " = " + grade + "\n";
if(grade >= first)
{
equi2 = equi1;
equi1 = equiGrade;
top2 = top1;
top1 = name;
second = first;
first = grade;
}
else if(grade >= second)
{
equi3 = equi2;
equi2 = equiGrade;
top3 = top2;
top2 = name;
third = second;
second = grade;
}
else if(grade >= third)
{
equi4 = equi3;
equi3 = equiGrade;
top4 = top3;
top3 = name;
fourth = third;
third = grade;
}
else if(grade >= fourth)
{
equi5 = equi4;
equi4 = equiGrade;
top5 = top4;
top4 = name;
fifth = fourth;
fourth = grade;
}
else if(grade >= fifth)
{
equi6 = equi5;
equi5 = equiGrade;
top6 = top5;
top5 = name;
sixth = fifth;
fifth = grade;
}
else
{
equi6 = equiGrade;
top6 = name;
sixth = grade;
}
}
coronaArea.setBackground(Color.black);
coronaArea.setForeground(Color.white);
coronaArea.setFont(new Font("Century Gothic", Font.BOLD, 14));
coronaArea.setText("\n" + dialog +
"\n\n\t\t ITCS122L - COMPUTER PROGRAMMING 2\n\t\t\t PRELIMINARY\n\t\t\tTOP FIVE STUDENTS\n" +
"=========================================================================================================\n" +
"\tNAMES\t\tGRADE\t\tEQUIVALENT\n" +
"=========================================================================================================\n" +
"\t"+ top1 + "\t\t " + first + "\t\t " + equi1 +
"\n\t" + top2 + "\t\t " + second + "\t\t " + equi2 +
"\n\t" + top3 + "\t\t " + third + "\t\t " + equi3 +
"\n\t" + top4 + "\t\t " + fourth + "\t\t " + equi4 +
"\n\t" + top5 + "\t\t " + fifth + "\t\t " + equi5);
JOptionPane.showMessageDialog(null,ducutPane);
/*break;
case 2: break;
default: JOptionPane.showInputDialog(" IVALID OPTION!"); break;
}//switch bracket
}while(choice != 2);//while bracket*/
}
}