0% found this document useful (0 votes)
2 views2 pages

COS202 Assignment Solution (1)

Uploaded by

sonateloveth757
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

COS202 Assignment Solution (1)

Uploaded by

sonateloveth757
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

NAME: KOLAWOLE JOSEPH AYOBAMI

MATRIC: SCI/23/24/0577
COURSE: COS 202 (COMPUTER PROGRAMMING II : USING JAVA PROGRA
DEPARTMENT: MATHEMATICAL SCIENCE

Task 1 (a)
Question: Write a GUI Java program (which uses applets) that reads the name and matriculation

number of a student. It then asks for the student's scores on five exams. The program should

display the student's average grade on the five exams.

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class StudentAverageApplet extends Applet implements ActionListener {


TextField nameField, matricField, score1, score2, score3, score4, score5;
Button calculateButton;
Label resultLabel;

public void init() {


setLayout(new GridLayout(9, 2));

add(new Label("Student Name:"));


nameField = new TextField();
add(nameField);

add(new Label("Matric Number:"));


matricField = new TextField();
add(matricField);

add(new Label("Score 1:"));


score1 = new TextField();
add(score1);

add(new Label("Score 2:"));


score2 = new TextField();
add(score2);

add(new Label("Score 3:"));


score3 = new TextField();
add(score3);

add(new Label("Score 4:"));


score4 = new TextField();
add(score4);
add(new Label("Score 5:"));
score5 = new TextField();
add(score5);

calculateButton = new Button("Calculate Average");


add(calculateButton);
calculateButton.addActionListener(this);

resultLabel = new Label("Average: ");


add(resultLabel);
}

public void actionPerformed(ActionEvent e) {


int s1 = Integer.parseInt(score1.getText());
int s2 = Integer.parseInt(score2.getText());
int s3 = Integer.parseInt(score3.getText());
int s4 = Integer.parseInt(score4.getText());
int s5 = Integer.parseInt(score5.getText());

double average = (s1 + s2 + s3 + s4 + s5) / 5.0;


resultLabel.setText("Average: " + average);
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy