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

//MgaParametro.

java int ctr = 0, capacity;

import javax.swing.*; Font datafont;

import java.awt.*;

import java.awt.event.*; public MgaParametro()

import java.io.*; {

import java.text.*; setResizable(false);

import java.util.*; setTitle("Yahwazaf Grading System");

class MgaParametro extends Frame implements


ActionListener
blank = new Label("");
{ Label blank;
heading = new Label("YAHWAZAF Grading System
Button accept, cancel; Program");

TextField snum, sname, mgrade, atten, exe, quiz, numrecords = new Label("Number of Records
casestud, fnalexam; Written");

Label studentnumber, studentname, midtermgrade, studentnumber = new Label("Student Number");


attendance,
studentname = new Label("Student Name");
exercises, quizzes, casestudy, finalexam, numrecords,
heading, numrec; midtermgrade = new Label("Midterm grade");

String studno, studname, mid, attend, ex, qu, cs, fin, attendance = new Label("Attendace");
output = "", str, studno2 = "", str1; exercises = new Label("Exercises");
double midgrade, att, exers, qui, cstud, finalex, quizzes = new Label("Quizzes");
grade, totalfinalgrade;
casestudy = new Label("Case Study");
finalexam = new Label("Final Exam");

heading.setBounds(75,25,300,75);

numrec.setBounds(275,410,20,20);

numrec = new Label("0"); numrecords.setBounds(100,400,150,40);

snum = new TextField("##-#####-#",20);

sname = new TextField("lname,fname,M.I.",20); studentnumber.setBounds(100,100,100,30);

mgrade = new TextField("",20); snum.setBounds(220,100,100,20);

atten = new TextField("",20);

exe = new TextField("",20); studentname.setBounds(100,130,100,30);

quiz = new TextField("",20); sname.setBounds(220,130,100,20);

casestud = new TextField("",20);

fnalexam = new TextField("",20); midtermgrade.setBounds(100,160,100,30);

datafont = new Font("Font.Arial",Font.BOLD,16); mgrade.setBounds(220,160,100,20);

attendance.setBounds(100,190,100,30);

accept = new Button("Accept"); atten.setBounds(220,190,100,20);

cancel = new Button("Cancel"); exercises.setBounds(100,220,100,30);

exe.setBounds(220,220,100,20);

accept.setBounds(100,350,100,30); quizzes.setBounds(100,250,100,30);

cancel.setBounds(220,350,100,30); quiz.setBounds(220,250,100,20);
casestudy.setBounds(100,280,100,30); add(mgrade);

casestud.setBounds(220,280,100,20); add(attendance);

finalexam.setBounds(100,310,100,30); add(atten);

fnalexam.setBounds(220,310,100,20); add(exercises);

add(exe);

heading.setFont(datafont); add(quizzes);

add(quiz);

str1 = JOptionPane.showInputDialog("how many add(casestudy);


student data will you enter?");
add(casestud);
capacity = Integer.parseInt(str1);
add(finalexam);
add(heading);
add(fnalexam);
add(numrec);
add(accept);
add(numrecords);
add(cancel);

add(blank);
add(studentnumber);
accept.addActionListener(this);
add(snum);
cancel.addActionListener(this);
add(studentname);

add(sname);
addWindowListener(new ProgramTerminator());
add(midtermgrade);
} midgrade = Double.parseDouble(mid);

att = Double.parseDouble(attend);

public void actionPerformed(ActionEvent e) exers = Double.parseDouble(ex);

{ if(e.getSource()==accept) qui = Double.parseDouble(qu);

{ cstud = Double.parseDouble(cs);

try finalex = Double.parseDouble(fin);

PrintWriter outFile = new


PrintWriter("Record.dat");
grade = 0.00;

grade += att * .10;


studno = snum.getText();
grade += exers * .10;
studname = sname.getText();
grade += qui * .20;
mid = mgrade.getText();
grade += cstud * .20;
attend = atten.getText();
grade += finalex * .40;
ex = exe.getText();

qu = quiz.getText();
DecimalFormat twodecimal = new
cs = casestud.getText(); DecimalFormat("0.00");

fin = fnalexam.getText();
totalfinalgrade = (midgrade + grade)/2; casestud.setText("");

output += " "+studno+" fnalexam.setText("");


"+studname+"
"+twodecimal.format(totalfinalgrade);

outFile.printf("%s",output); snum.setEditable(false);

outFile.close(); sname.setEditable(false);

ctr+=1; mgrade.setEditable(false);

str = String.valueOf(ctr); atten.setEditable(false);

numrec.setText(str); exe.setEditable(false);

if(ctr==capacity) quiz.setEditable(false);

{ JOptionPane.showMessageDialog(null,"The casestud.setEditable(false);
class record is already full! "+capacity+" data(s) were fnalexam.setEditable(false);
written","Yahwazaf Grading
System",JOptionPane.INFORMATION_MESSAGE);

accept.setEnabled(false);

snum.setText(""); cancel.setEnabled(false);

sname.setText(""); }

mgrade.setText(""); }

atten.setText(""); catch(FileNotFoundException rhold)

exe.setText(""); { System.out.println(rhold.toString());

quiz.setText(""); }
}

if(e.getSource()==cancel)

{ snum.setText("");

sname.setText("");

mgrade.setText("");

atten.setText("");

exe.setText("");

quiz.setText("");

casestud.setText("");

fnalexam.setText("");

} //Frame

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;
System.exit(0);

class PangunahingPrograma }

{ public void windowActivated(WindowEvent e) {}

public static void main(String args[]) public void windowClosed(WindowEvent e) {}

{ MgaParametro frame = new MgaParametro(); public void windowDeactivated(WindowEvent e) {}

public void windowDeiconified(WindowEvent e) {}

frame.setVisible(true); public void windowIconified(WindowEvent e) {}

frame.setSize(450,500); public void windowOpened(WindowEvent e) {}

frame.setLocation(225,100); }

//Scanner object

import java.awt.event.*; import javax.swing.*;

import java.io.*;

class ProgramTerminator implements WindowListener import java.util.*;

{ public void windowClosing(WindowEvent e) public class TagapaglabasngFayl

{
{ public static void main(String args[]) throws for(int i=0;i<classnum;i++)
FileNotFoundException
{ snum = newFile.next();
{
sname = newFile.next();
Scanner newFile = new Scanner(new
FileReader("Record.dat")); grade = newFile.nextDouble();

PrintWriter outputFile = new PrintWriter("Grade


Record.doc"); output += " "+snum+ " "+sname+"
String ans; "+grade+"\n";

String snum; }

String sname;

double grade; JOptionPane.showMessageDialog(null,header1+he


ader2+header3+header4+"Student Number
int classnum; Student Name Final
Grade\n"+output,"Output",JOptionPane.INFORMATION_
String cnum, output = "" , header1 = " MESSAGE);
Polytechnic University of the Philippines \n", header2 =
" Quezon City Campus\n", header3 = "
Final Grades\n"
String lastheader = " "+header1+"
, header4 = " BSIT 2-1\n\n"; "+header2+" "+header3+" "+header4;

cnum = JOptionPane.showInputDialog("How many outputFile.printf(lastheader+" Student Number


student data did you enter?"); Student Name Final Grade\n"+output);

classnum = Integer.parseInt(cnum);
JOptionPane.showMessageDialog(null,"Output File
has been
written","output",JOptionPane.INFORMATION_MESSAGE
);

newFile.close();

outputFile.close();

System.exit(0);

//Running
PangunahingPrograma.java
//display of Frame

(input for the capacity of the record depending on the


number of students)

(indicates that the capacity has been reached and that


the data are already written on Record.dat )

(input of data)

//Running TagapaglabasngFayl.java
(asks how the number of data you previously entered)

(indicates that the contents of the previously showed


dialog box can now be seen in a Word Document)

(shows the data inside the file Record.dat)

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