Вы находитесь на странице: 1из 7

UNIVERSITI UTARA

MALAYSIA
____________________________________
COLLEGE OF ARTS AND SCIENCES

STIA 1023
ADVANCE PROGRAMMING
(Group D)

LAB EXERCISE 6 GUI II

NAME : MOHD NAZRI BIN OTHMAN


I/C NUMBER : 900914-08-6511
MATRIX NUMBER : 203542
LECTURER NAME : PUAN NORAZILA BINTI ALI
Lab Exercise 6
GUI II
1. Write and compile the following Student class:
public class Student {
private String name,matricNo,gender,college,level;
private double totalQuizes,totalAssignment,totalTest,totalFinal,
totalProject, totalMarks;
private String grade;

public Student(){
totalMarks=0;
grade="";
}
public void setStudent(String name,String matricNo,String gender,String
college,String level){
this.name=name;
this.matricNo=matricNo;
this.gender=gender;
this.college=college;
this.level=level;
}
public void setMark(double totalQuizes,double totalAssignment,double
totalProject, double totalTest,double totalFinal){
this.totalQuizes=totalQuizes;
this.totalAssignment=totalAssignment;
this.totalProject=totalProject;
this.totalTest=totalTest;
this.totalFinal=totalFinal;
}
public void computeTotalMarks(){
totalMarks = totalQuizes + totalAssignment+ totalTest+totalFinal;
}

public void defineGrade(){


if(totalMarks >=85)
grade = "A";
else if (totalMarks >=60)
grade = "B";
else if (totalMarks >=50)
grade = "C";
else if (totalMarks >=40)
grade = "D";
else
grade = "F";
}
public String getGrade(){
return grade;
}
public String toString(){
return "\nName : " + name + "\nMatric No : " + matricNo + "\nCollege : "
+ college + "\nProgramme Level : " + level + "\nGender : " + gender +
"\nTotal Marks : " + totalMarks + "\nGrade : " + grade;
}
}

1. By using the solution of the previous lab exercise (Lab Exercise 5), you are required
to modify the GUI program so that the concepts of menu and event-handing can be
applied. The program to be developed should make use the above Student class by
calling the appropriate method(s) to accomplish certain tasks. Declare an object
reference of the type Student as a data member of the class and instantiate the
object of Student in a constructor. Please follow the following instructions:
a. Add menu and menu item as shown below:
b. When the “Calculate Grade” button is pressed, the program will display a grade in
the text field that is provided on the interface. The grade is defined based on
summation of the mark of quizzes, assignments, mid test, project and final
exam. Appropriate method (s) from the above Student class should be
invoked to manage this task.
c. When the user presses “Reset” button, all text fields will be reset.
d. When the “Display Details” button is pressed, the program will display a student’s
details in the text area as shown in the figure below. The student’s details are
captured from the interface of the application based on the user input. You
are also required to invoke appropriate method (s) from the above Student
class to manage this task.

e. When the user presses “Exit” menu item or “Exit” button, the program will
eventually be terminated.
Answer:
//data member

Student stud;

//add this statement in constructor

stud = new Student();


private void btnExitActionPerformed(java.awt.event.ActionEvent evt)
{
// TODO add your handling code here:
System.exit(0);
}

private void btnResetActionPerformed(java.awt.event.ActionEvent evt)


{
// TODO add your handling code here:
txtName.setText("");
txtMatric.setText("");
txtQuiz.setText("");
txtAssignment.setText("");
txtMidExam.setText("");
txtProject.setText("");
txtFinal.setText("");
cboCollege.setSelectedIndex(0);
txtGrade.setText("");
txtOutput.setText("");

private void btnCalculateActionPerformed(java.awt.event.ActionEvent


evt) {
// TODO add your handling code here:

double quiz=Double.parseDouble(txtQuiz.getText());
double asg=Double.parseDouble(txtAssignment.getText());
double mid=Double.parseDouble(txtMidExam.getText());
double project=Double.parseDouble(txtProject.getText());
double fin=Double.parseDouble(txtFinal.getText());
stud.setMark(quiz, asg, project, mid, fin);
stud.computeGrade();
String grade=stud.getGrade();
txtGrade.setText(grade);
}
private void btnDisplayActionPerformed(java.awt.event.ActionEvent
evt) {
// TODO add your handling code here:
String name=txtName.getText();
String matric=txtMatric.getText();
String gender=””;
if(rdMale.isSelected()==true)
gender="Male";
else
gender="Female";
String level=””;
if(rdUnderGraduate.isSelected()==true)
level="Undergraduate";
else
level="Postgraduate";
String college=(String)cboCollege.getSelectedItem();
stud.setInfo(name, matric, gender, college,level);
txtOutput.setText(stud.toString());
}

Вам также может понравиться