Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please convert this simple project into GUI import java.io.DataInputStream; clas

ID: 3652115 • Letter: P

Question

Please convert this simple project into GUI

import java.io.DataInputStream;

class Person
{
int ID_number;
String name;

void addID(int id){ID_number=id;}
void addName(String n){name=n;}
int getID(){return ID_number;}
String getName(){return name;}
}
class Student extends Person
{
int student_ID;
String college;
String major;
int GPA_average;

void addStudentID(int id){student_ID=id;}
void addCollege(String clg){college=clg;}
void addMajor(String mjr){major=mjr;}
void addGPA(int gpa){GPA_average=gpa;}
int getStudentID(){return student_ID;}
String getCollege(){return college;}
String getMajor(){return major;}
int getGPA(){return GPA_average;}
}
class Main
{
public static void main(String a[])
{
Student[] s = new Student[5];
int inputData=0;
try{
process(s,inputData);
}
catch(Exception e){
System.out.println("Exception -- "+ e);
}
}
static void process(Student[] s, int inputData) throws Exception
{
Functions f = new Functions();
System.out.println("Available Choices::");
System.out.println("1. Input Student Data");
System.out.println("3. Search for a student");
System.out.println("4. Display");
System.out.println("5. exit");
System.out.println("Enter your choice:");
int choice=0;
int choice2=0;
try{
choice = f.getInt();
}
catch(Exception e)
{
System.out.println("Improper integer value");
System.out.println("Exception -- "+ e);
}
switch(choice)
{
case 1: try{
s[inputData]=f.getInput();
}
catch(Exception e)
{
System.out.println("Exception -- "+ e);
}
inputData++;
break;
case 2: System.out.println("Available Choices::");
System.out.println("1. Sort by name");
System.out.println("2. Sort by ID");
try{
choice2 = f.getInt();
}
catch(Exception e)
{
System.out.println("Improper integer value");
System.out.println("Exception -- "+ e);
}
switch(choice2){
case 1: Student temp = new Student();
for(int i=0;i<inputData;i++)
{
for(int j=0;j<inputData;j++)
{
if(s[i].getName().compareTo(s[j].getName())<0)
{
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
}
f.printStudents(s,inputData);
break;
case 2: Student temp2 = new Student();
for(int i=0;i<inputData;i++)
{
for(int j=0;j<inputData;j++)
{
if(s[i].getStudentID() > s[j].getStudentID())
{
temp2=s[i];
s[i]=s[j];
s[j]=temp2;
}
}
}
f.printStudents(s,inputData);
break;
default:
}
break;
case 3: System.out.println("Available Choices::");
System.out.println("1. Search for name");
System.out.println("2. Search for ID");
try{
choice2 = f.getInt();
}
catch(Exception e)
{
System.out.println("Improper integer value");
System.out.println("Exception -- "+ e);
}
switch(choice2){
case 1: System.out.println("Enter Student name:");
String name = f.getStr();
for(int i=0;i<inputData;i++)
{
if(name.equals(s[i].getName()))
{
System.out.println("Name:"+s[i].getName());
System.out.println("Student Id:"+s[i].getStudentID());
System.out.println("College:"+s[i].getCollege());
System.out.println("Major:"+s[i].getMajor());
System.out.println("GPA:"+s[i].getGPA());
System.out.println();
}
}
break;
case 2: System.out.println("Enter Student ID:");
int id = f.getInt();
for(int i=0;i<inputData;i++)
{
if(id==s[i].getStudentID())
{
System.out.println("Name:"+s[i].getName());
System.out.println("Student Id:"+s[i].getStudentID());
System.out.println("College:"+s[i].getCollege());
System.out.println("Major:"+s[i].getMajor());
System.out.println("GPA:"+s[i].getGPA());
System.out.println();
}
}
break;
default:
}
break;
case 4: f.printStudents(s,inputData);
break;
case 5: System.out.println("Thank You");
System.exit(0);
default: System.out.println("Invalid Choice");
}
process(s,inputData);
}

}
class Functions
{
void printStudents(Student[] s, int inputData)
{
for(int i=0;i<inputData;i++){
System.out.println("Name:"+s[i].getName());
System.out.println("Student Id:"+s[i].getStudentID());
System.out.println("College:"+s[i].getCollege());
System.out.println("Major:"+s[i].getMajor());
System.out.println("GPA:"+s[i].getGPA());
System.out.println();
}
}
int getInt() throws Exception{
DataInputStream dis = new DataInputStream(System.in);
String data = dis.readLine();
return (Integer.parseInt(data));
}
String getStr() throws Exception{
DataInputStream dis = new DataInputStream(System.in);
String data = dis.readLine();
return (data);
}
Student getInput() throws Exception{
Student s=new Student();
System.out.println("Enter Name:");
s.addName(getStr());
System.out.println("Enter student id");
s.addStudentID(getInt());
System.out.println("Enter College");
s.addCollege(getStr());
System.out.println("Enter Major");
s.addMajor(getStr());
System.out.println("Enter GPA average");
s.addGPA(getInt());
return s;
}
}

Explanation / Answer

We have convert your code into GUI. import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.JOptionPane; public class CompString implements ActionListener{ JFrame frame; JPanel panel; JTextField string1; JLabel label1, label2; JButton compareButton; JTextField string2; public CompString() { frame = new JFrame("Compare String"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(new Dimension(180, 80)); panel = new JPanel(new GridLayout(3, 2)); panel.setBorder(BorderFactory.createEmptyBorder(60, 60, 20, 60)); addItems(); frame.getRootPane().setDefaultButton(compareButton); frame.getContentPane().add(panel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); } private void addItems() { label1 = new JLabel("Text1", SwingConstants.LEFT); string1 = new JTextField(20); compareButton = new JButton("Compare"); label2 = new JLabel("Text2", SwingConstants.LEFT); string2 = new JTextField(20); compareButton.addActionListener(this); panel=new JPanel(new GridLayout(4,1)); panel.add(label1); panel.add(string1); panel.add(label2); panel.add(string2); panel.add(compareButton); label1.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 5)); label1.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 5)); } public void actionPerformed(ActionEvent event) { String st1=string1.getText(); String st2=string2.getText(); if (st2.compareTo(st1) > 0){ JOptionPane.showMessageDialog(null,"The second string is greater than the first one"); } else{ JOptionPane.showMessageDialog(null,"The first string is greater than the second one"); } } private static void createAndShowGUI() { JFrame.setDefaultLookAndFeelDecorated(true); CompString converter = new CompString(); } public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote