Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

a *I need the user manual and design for for the following Java code:* import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; import

a

*I need the user manual and design for for the following Java code:*

import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

import java.util.ArrayList;

public class STIA1123Asg3 {

private JFrame frame;

private JTextField choicefield;

public STIA1123Asg3()

{

initialize();

}

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

STIA1123Asg3 window = new STIA1123Asg3();

window.frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

private void initialize() {

frame = new JFrame();

frame.getContentPane().setFocusable(false);

frame.getContentPane().setFocusTraversalKeysEnabled(false);

frame.getContentPane().setEnabled(false);

frame.getContentPane().setName("SIS");

frame.setTitle("*$$$Welcome to the Student Information System$$**");

frame.setBounds(400, 300, 700, 550);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().setLayout(null);

JLabel lblNewLabel = new JLabel("[1]ENter Student");

JLabel lblNewLabel2 = new JLabel("[2]Display All Students");

JLabel lblNewLabel3 = new JLabel("[3]Search for a specific Student");

JLabel lblNewLabel4 = new JLabel("[4]Delete");

JLabel lblNewLabel5 = new JLabel("[5]Edit");

JLabel lblNewLabel6 = new JLabel("[6]Add to file");

JLabel lblNewLabel7 = new JLabel("[7]Retrive from file");

JLabel lblNewLabel8 = new JLabel("[8]Exit");

lblNewLabel.setBounds(90, 30, 200, 200);

lblNewLabel2.setBounds(90, 50, 200, 200);

lblNewLabel3.setBounds(90, 70, 200, 200);

lblNewLabel4.setBounds(90, 90, 200, 200);

lblNewLabel5.setBounds(90, 110, 200, 200);

lblNewLabel6.setBounds(90, 130, 200, 200);

lblNewLabel7.setBounds(90, 150, 200, 200);

lblNewLabel8.setBounds(90, 170, 200, 200);

frame.getContentPane().add(lblNewLabel);

frame.getContentPane().add(lblNewLabel2);

frame.getContentPane().add(lblNewLabel3);

frame.getContentPane().add(lblNewLabel4);

frame.getContentPane().add(lblNewLabel5);

frame.getContentPane().add(lblNewLabel6);

frame.getContentPane().add(lblNewLabel7);

frame.getContentPane().add(lblNewLabel8);

choicefield = new JTextField();

choicefield.setBounds(90, 310, 100, 25);

frame.getContentPane().add(choicefield);

choicefield.setColumns(10);

JButton btnCompute = new JButton("Ok");

btnCompute.setBounds(90, 340, 100, 25);

frame.getContentPane().add(btnCompute);

//Student[] student = new Student[9999];

ArrayList student1 = newArrayList();

//final int[] count = {0};

btnCompute.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e) {

int choice= Integer.parseInt(choicefield.getText());;

switch (choice)

{

case 1:

int type;

do {

type = Integer.parseInt(JOptionPane.showInputDialog(

"\t[1]Undergraduate " +

"\t[2]Postgraduate " +

"\tChoose type: "));

} while (type != 1 && type != 2 );

String name = JOptionPane.showInputDialog("Enter name: ");

while(name.isEmpty()||!Character.isAlphabetic(name.charAt(0)))

{

name = JOptionPane.showInputDialog("Enter name: ");

}

Stringmatric_num= JOptionPane.showInputDialog("Enter matric: ");

while(matric_num .isEmpty()||!Character.isDigit(matric_num.charAt(0)))

{

matric_num = JOptionPane.showInputDialog("Enter matric: ");

}

String courseWork =JOptionPane.showInputDialog("Enter course work score: ");

while(courseWork .isEmpty()||!Character.isDigit(courseWork.charAt(0)))

{

courseWork =JOptionPane.showInputDialog("Enter course work score: ");

}

String finalExam = JOptionPane.showInputDialog("Enter final exam score: ");

while(finalExam.isEmpty()||!Character.isDigit(finalExam.charAt(0)))

{

finalExam = JOptionPane.showInputDialog("Enter final exam score: ");

}

if (type == 1)

{

Student s = new UnderGraduateStudent(name, Integer.parseInt(matric_num), Double.parseDouble(courseWork), Double.parseDouble(finalExam));

student1.add(s);

}

else

{

String supervisor = JOptionPane.showInputDialog("Enter supervisor name: ");

while(supervisor.isEmpty()||!Character.isAlphabetic(supervisor.charAt(0)))

{

supervisor = JOptionPane.showInputDialog("Enter supervisor name: ");

}

Student s = new PostGraduateStudent(supervisor,name,Integer.parseInt(matric_num), Double.parseDouble(courseWork), Double.parseDouble(finalExam));

student1.add(s);

}

//count[0]++;

JOptionPane.showMessageDialog(null, "Student successfully added.", "Exit", JOptionPane.PLAIN_MESSAGE);

break;

case 2:

StringBuilder allStudents = new StringBuilder();

for (int i = 0; i < student1.size(); i++) {

allStudents.append(student1.get(i).display());

}

JTextArea textArea = new JTextArea("MatricNameCourse WorkFinal ExamGrade " + allStudents);

textArea.setFont(new Font("Arial", Font.BOLD, 18));

JOptionPane.showMessageDialog(null, textArea, "Student details", JOptionPane.PLAIN_MESSAGE);

break;

case 3:

int flag = 0;

String Search= JOptionPane.showInputDialog("Enter matric to search: ");

while(Search.isEmpty()||!Character.isDigit(Search.charAt(0)))

{

Search = JOptionPane.showInputDialog("Enter matric to search: ");

}

int matricSearch=Integer.parseInt(Search);

StringBuilder searchresult = new StringBuilder();

for (int i = 0; i < student1.size(); i++)

{

if (student1.get(i).Search(matricSearch) != null)

{

searchresult.append(student1.get(i).Search(matricSearch));

textArea = new JTextArea("MatricNameCourse WorkFinal ExamGradeType " + searchresult);

textArea.setFont(new Font("Arial", Font.BOLD, 18));

JOptionPane.showMessageDialog(null, textArea, "Student details", JOptionPane.PLAIN_MESSAGE);

flag = 1;

break;

}

}

if (flag == 0)

{

JOptionPane.showMessageDialog(null, "Sorry this Student's info was not found...", "Exit", JOptionPane.PLAIN_MESSAGE);

}

break;

case 4:

int flag1= 0;

String matricdelete= JOptionPane.showInputDialog("Enter matric to delete: ");

while(matricdelete.isEmpty()||!Character.isDigit(matricdelete.charAt(0)))

{

Search = JOptionPane.showInputDialog("Enter matric to delete: ");

}

int delete=Integer.parseInt(matricdelete);

for (int i = 0; i < student1.size(); i++)

{

if (student1.get(i).Search(delete) != null)

{

student1.remove(i);

flag1=1;

JOptionPane.showMessageDialog(null, "Student Record deleted", "Exit", JOptionPane.PLAIN_MESSAGE);

}

}

if (flag1 == 0) {

JOptionPane.showMessageDialog(null, "Student not found...", "Exit", JOptionPane.PLAIN_MESSAGE);

}

break;

case 5:

int flag2= 0;

int type1;

do {

type1 = Integer.parseInt(JOptionPane.showInputDialog(

"\t[1]Under graduate " +

"\t[2]Post graduate " +

"\tChoose the type: "));

}

while (type1 != 1 && type1 != 2);

String matricedit= JOptionPane.showInputDialog("Enter matric to delete: ");

while(matricedit.isEmpty()||!Character.isDigit(matricedit.charAt(0)))

{

Search = JOptionPane.showInputDialog("Enter matric to delete: ");

}

int edit=Integer.parseInt(matricedit);

for (int i = 0; i < student1.size(); i++) {

if (student1.get(i).Search(edit) != null)

{

flag2=1;

student1.remove(i);

name = JOptionPane.showInputDialog("Enter name: ");

while(name.isEmpty()||!Character.isAlphabetic(name.charAt(0)))

{

name = JOptionPane.showInputDialog("Enter name: ");

}

courseWork =JOptionPane.showInputDialog("Enter course work score: ");

while(courseWork .isEmpty()||!Character.isDigit(courseWork.charAt(0)))

{

courseWork =JOptionPane.showInputDialog("Enter course work score: ");

}

finalExam = JOptionPane.showInputDialog("Enter final exam score: ");

while(finalExam.isEmpty()||!Character.isDigit(finalExam.charAt(0)))

{

finalExam = JOptionPane.showInputDialog("Enter final exam score: ");

}

Student s = new UnderGraduateStudent(name, edit, Double.parseDouble(courseWork), Double.parseDouble(finalExam));

student1.add(s);

if (type1 == 2)

{

String supervisor = JOptionPane.showInputDialog("Enter supervisor name: ");

while(supervisor.isEmpty()||!Character.isAlphabetic(supervisor.charAt(0)))

{

supervisor = JOptionPane.showInputDialog("Enter supervisor name: ");

}

Student s1 = new PostGraduateStudent(supervisor, name, edit,Double.parseDouble(courseWork), Double.parseDouble(finalExam));

student1.add(s1);

}

JOptionPane.showMessageDialog(null, "Student successfully added.", "Exit", JOptionPane.PLAIN_MESSAGE);

break;

}

}

if (flag2 == 0)

{

JOptionPane.showMessageDialog(null, "Student not found...", "Exit", JOptionPane.PLAIN_MESSAGE);

}

break;

case 6:

String filename ;

filename = JOptionPane.showInputDialog("Enter name: ");

while(filename.isEmpty()||!Character.isAlphabetic(filename.charAt(0)))

{

filename = JOptionPane.showInputDialog("Enter name: ");

}

try{

FileWriter fw=new FileWriter(filename+".txt");

StringBuilder all= new StringBuilder();

for (int i = 0; i < student1.size(); i++)

{

all.append(student1.get(i).display()+System.lineSeparator());

}

fw.write(all.toString());

fw.close();

}

catch(Exception ex)

{

System.out.println(ex);

}

JOptionPane.showMessageDialog(null, "Student Information successfully added into file "+ filename+ ".txt", "Exit", JOptionPane.PLAIN_MESSAGE);

break;

case 7:

StringBuffer sb=new StringBuffer();

try

{

String filename2 ;

filename2 = JOptionPane.showInputDialog("Enter name: ");

while(filename2.isEmpty()||!Character.isAlphabetic(filename2.charAt(0)))

{

filename2 = JOptionPane.showInputDialog("Enter name: ");

}

File file=new File(filename2+".txt");//creates a new file instance

FileReader fr=new FileReader(file);//reads the file

BufferedReader br=new BufferedReader(fr);//creates a buffering character input stream

//constructs a string buffer with no characters

String line;

while((line=br.readLine())!=null)

{

sb.append(line);//appends line to string buffer

sb.append(" ");//line feed

}

fr.close();//closes the stream and release the resources

}

catch(IOException ex)

{

ex.printStackTrace();

}

JTextArea textArea2 = new JTextArea("MatricNameCourse WorkFinal ExamGrade " + sb);

textArea2.setFont(new Font("Arial", Font.BOLD, 18));

JOptionPane.showMessageDialog(null, textArea2, "Student details", JOptionPane.PLAIN_MESSAGE);

break;

case 8:

System.exit(0);

}

}

});

}

}

class Student {

String name;

int matric_num;

double course_Work;

double final_Exam;

double total_Mark;

String grade;

public Student() {

}

public Student(String name, int matric, double courseWork, double finalExam) {

this.name = name;

this.matric_num = matric;

this.course_Work = courseWork;

this.final_Exam = finalExam;

setGrade();

}

public String getName() {

return name;

}

//here are our setters

public void setName(String name) {

this.name = name;

}

public int getMatric() {

return matric_num;

}

public void setMatric(int matric) {

this.matric_num = matric_num;

}

public double getCourseWork() {

return course_Work;

}

public void setCourseWork(double courseWork) {

this.course_Work = courseWork;

}

public double getFinalExam() {

return final_Exam;

}

public double Mark() {

return total_Mark;

}

public String getGrade() {

return grade;

}

// This method is used to calculate grade

public void setGrade() {

total_Mark = course_Work + final_Exam;

if (total_Mark >= 90)

grade = "A+";

else if (total_Mark >= 80)

grade = "A";

else if (total_Mark >= 75)

grade = "A-";

else if (total_Mark >= 70)

grade = "B+";

else if (total_Mark >= 65)

grade = "B";

else if (total_Mark >= 60)

grade = "B-";

else if (total_Mark >= 55)

grade = "C+";

else if (total_Mark >= 50)

grade = "C";

else

JOptionPane.showMessageDialog(null, "We are sorry to inform that you have failed", "Exit", JOptionPane.PLAIN_MESSAGE);

}

public String display() {

return String.format("%-12d%-28s%-16.2f%-16.2f %s ", getMatric(), getName(),

getCourseWork(), getFinalExam(), getGrade());

}

public String Search(int m) {

if (getMatric() == m) {

return String.format("%-12d %-28s%-16.2f%-16.2f %s ", getMatric(), getName(),

getCourseWork(), getFinalExam(), getGrade());

}

return null;

}

}

class UnderGraduateStudent extends Student {

public UnderGraduateStudent() {

}

public UnderGraduateStudent(String name, int matric, double courseWork, double finalExam) {

super(name, matric, courseWork, finalExam);

}

@Override

public String Search(int m) {

if (getMatric() == m) {

return String.format("%-12d %-28s%-16.2f%-16.2f %s %s ", getMatric(), getName(),

getCourseWork(), getFinalExam(), getGrade(), "Undergraduate");

}

return null;

}

}

//inherits the Student class

class PostGraduateStudent extends Student {

//our variable supervisor

String supervisor;

//constructor with and without parameters

public PostGraduateStudent() {

}

public PostGraduateStudent(String supervisor, String name, int matric, double courseWork, double finalExam) {

super(name, matric, courseWork, finalExam);

this.supervisor = supervisor;

}

@Override

public String Search(int m) {

if (getMatric() == m) {

return String.format("%-14d %-28s%-17.2f%-15.2f %s %s ", getName(), getMatric(),

getCourseWork(), getFinalExam(), getGrade(), "Postgraduate");

}

return null;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

how can the workplace monitor the usage of equipment

Answered: 1 week ago

Question

What is the approximate diameter of the human eye ?

Answered: 1 week ago

Question

The front transperant part of the sclerosis known as.....?

Answered: 1 week ago

Question

What is the refractive index of the cornea....?

Answered: 1 week ago

Question

Common defects of the eye?

Answered: 1 week ago

Question

The eye is responsible for producing tears....?

Answered: 1 week ago