Jeannie Kwa
Posts: 4
Nickname: kaw
Registered: Apr, 2002
|
|
Re: About Multidimensional Arrays
|
Posted: Apr 27, 2002 11:24 AM
|
|
Thomas,
I tried to work out on this qn. However there are some errors on it. Pls help me on it. And how and where can i make the function to calcuate on their grading and <u>average score</u>. Below is the source code for this program on Applet. Appreciate all the assistance on this program.
import java.awt.*; import java.awt.event.*; import java.io.*;
public class Smark extends Frame implements ActionListener {
Label lblTitle,lblSname,lblMark1,lblMark2,lblMark3; TextField txtSname,txtMark1,txtMark2,txtMark3; Button btnReset,btnExit,btnPrint; TextArea sta; public Smark() { setSize(500,550); setLayout(null); setLocation(null); setTextArea int (10,30);
lblTitle = new Label("RESULT CALCULATOR"); lblTitle.setLocation(200,30); lblTitle.setSize(150,30); add(lblTitle);
lblSname = new Label("Enter Name : ") ; lblSname.setLocation(150,40); lblSname.setSize(120,30); add(lblSname);
txtSname = new TextField("",10); txtSname.setLocation(150,40); txtSname.setSize(120,50); add(txtSname);
lblMark1 = new Label("Enter 1st Mark : ") ; lblMark1.setLocation(200,50); lblMark1.setSize(130,40); add(lblMark1);
txtMark1 = new TextField("",10); txtMark1 = new TextField("",10); add(txtMark1);
lblMark2 = new Label("Enter 2nd Mark : ") ; lblMark2.setLocation(200,50); lblMark2.setSize(130,40); add(lblMark2);
txtMark2 = new TextField("",10); txtMark2 = new TextField("",10); add(txtMark2); lblMark3 = new Label("Enter 3rd Mark : ") ; lblMark3.setLocation(200,50); lblMark3.setSize(130,40); add(lblMark2);
txtMark3 = new TextField("",10); txtMark3 = new TextField("",10); add(txtMark3);
btnPrint = new Button("PRINT"); btnPrint.addActionListener(this); add(btnPrint);
btnReset = new Button("RESET"); btnReset.addActionListener(this); add(btnReset);
btnExit = new Button("EXIT"); btnExit.setLocation(350,170); btnExit.setSize(80,30); btnExit.addActionListener(this); add(btnExit);
sta=new TextArea ("",10,30); setLocation(); setSize(500,550); sta.setEditable(false); add(sta); }
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == btnPrint) {
} // end of btnPrint
if (evt.getSource() == btnReset) {
} // end of btnReset
if (evt.getSource() == btnExit) { System.exit(0); } // end of btnExit
} // end of actionPerformed
public static void main (String args[]) { Smark fp = new Smark(); fs.show(); String Sname; int mark1, mark2, mark3; { Student [] students = double highestAvg = -1.0; double lowestAvg = 101.0;
for (int i = 0; i < students.length; i++) { double avg = (students .mark1 + students .mark2 + students .mark3) / 3.0;
if (avg > highestAvg) highestAvg = avg;
if (avg < lowestAvg) lowestAvg = avg;
System.out.print (students .name + " " + students .mark1 + " " + students .mark2 + " " + students .mark3 + " " + avg + " ");
if (avg < 40) System.out.println ("FAIL"); else if (avg < 60) System.out.println ("PASS"); else if (avg < 70) System.out.println ("CREDIT"); else System.out.println ("DISTINCTION"); }
System.out.println ();
System.out.println ("Highest Average = " + highestAvg); System.out.println ("Lowest Average = " + lowestAvg); } }
} // end of main
} // end of class
|
|