java programming
how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...)
and include an option to print a list of all students added in a grid format and short by name, course, instructor, and location.
///main
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
ArrayList<Student>students = new ArrayList<>();
int choice;
while(true)
{
displayMenu();
choice = in.nextInt();
switch(choice)
{
case 1:
in.nextLine();
System.out.println("Enter Student Name");
String name = in.nextLine();
System.out.println("Enter Course Name");
String course = in.nextLine();
Course c = new Course();
c.setcourse(course);
System.out.println("Enter Instructor Name");
String instructor = in.nextLine();
Instructor i = new Instructor();
i.setinstructor(instructor);
System.out.println("Enter Location Name");
String location = in.nextLine();
Location l = new Location();
l.setlocation(location);
students.add(new Student(name,c,i,l));
break;
case 2:
in.nextLine();
System.out.println("Enter student name to delete");
String studentName = in.nextLine();
boolean found = false;
for (int j = 0; j<students.size(); j++){
if(students.get(j).getName().equalsIgnoreCase(studentName))
{
} else {
students.remove(j);
System.out.println("Student Removed");
found=true;
}
}
if(!found)
{
System.out.println("Student not found");
}
break;
case 3:
in.nextLine();
boolean found1=false;
System.out.println("Search for:");
String searchStudent = in.nextLine();
for(Student s:students){
if(s.getName().equalsIgnoreCase(searchStudent)){
System.out.print("Student information: \n"+ s);
found1 = true;
}
}
if(!found1)
System.out.println("Student not found");
break;
case 4:
System.exit(0);
break;
}
}
}
public static void displayMenu()
{
System.out.print("\nPlease select an option:");
System.out.println("\n1.Add Student \n2.Delete Student \n3.Search
for Student \n4.Exit");
}
}
///course
class Course {
String course;
public String getcourse() {
return course;
}
public void setcourse(String course) {
this.course = course;
}
}
///insturctor
class Instructor {
String instructor;
public String getinstructor() {
return instructor;
}
public void setinstructor(String instructor) {
this.instructor = instructor;
}
}
///location
class Location {
String location;
public String getlocation() {
return location;
}
public void setlocation(String location) {
this.location = location;
}
}
/////student
public class Student {
private String name;
private Course c;
private Instructor i;
private Location l;
public Student(String name ,Course c,Instructor i, Location l)
{
this.name = name;
this.c = c;
this.i = i;
this.l = l;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name + ":" + c.getcourse() + "," + l.getlocation() + ", Proffesor "
+ i.getinstructor();
}
}1. Course , Student, Location and instructor classes remain the same.
Added pointers to modify the code to add GUI for menu based system.
We will build GUI using Swings, by importing
import javax.swing.*;
Step 1: Create a container using the JFrame component.
In main function, replace scanner initialization with frame
//Scanner in = new Scanner(System.in); // This code initializes
scanner for getting inputs
JFrame frame = new JFrame("My Form"); // Initalize the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,300);
Step 2: Create a menu bar, you can add options as per the need, adding a basic instructions for now.
//Creating the MenuBar and adding components
JMenuBar mb = new JMenuBar();
JMenu m1 = new JMenu("FILE");
JMenu m2 = new JMenu("Help");
JMenuItem m11 = new JMenuItem("Add Student");
JMenuItem m12 = new JMenuItem("Delete Student");
JMenuItem m13 = new JMenuItem("Search for Student");
JMenuItem m14 = new JMenuItem("Print Students");
mb.add(m1);
mb.add(m2);
m1.add(m11);
m1.add(m12);
m1.add(m13);
m1.add(m14);
Step 3: Create the panel and add it to the frame
JPanel panel = new JPanel(); // the panel is not visible in output
//Adding Components to the frame. frame.getContentPane().add(BorderLayout.SOUTH, panel); // Using border layout to place the components frame.getContentPane().add(BorderLayout.NORTH, mb);
Step 4: Create Text fields and labels and buttons and add them to panel
JLabel label1 = new JLabel("Enter Student Name");
JTextField tf1 = new JTextField(100);
String name = tf1.getText();
JLabel label2 = new JLabel("Enter Course Name");
JTextField tf2 = new JTextField(100);
String course = tf2.getText();
Course c = new Course();
c.setcourse(course);
JLabel label3 = new JLabel("Enter Instructor Name");
JTextField tf3 = new JTextField(100);
String instructor =tf3 .getText();
Instructor i = new Instructor();
i.setinstructor(instructor);
JLabel label4 = new JLabel("Enter Location Name");
JTextField tf4 = new JTextField(100);
String location = tf4.getText();
Location l = new Location();
l.setlocation(location);
// add the above options to the panel
JButton submit = new JButton("Submit"); // Create the buttons and add it to the panel
JButton reset = new JButton("Reset");
panel.add(label1); // Components Added using default Layout
panel.add(label2);
panel.add(label3);
panel.add(label4);
panel.add(tf1);
panel.add(tf2);
panel.add(tf3);
panel.add(tf4);
panel.add(submit); // submit button
panel.add(reset); // Reset form
// On the similar lines, create panel for all the cases separately and all the components to different panels
Step 5: Add listeners to menu items to switch the panels in the frame, below is example for student menu item
m11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addStudent(evt);
}
});
// define Function to switch the panel in frame.
private void addStudent(java.awt.event.ActionEvent evt) {
//Jpanel "Student"
}
Step 6: Add action listeners to button to submit and save or remove the data to arraylist.
Step 7: Set frame to visible
frame.setVisible(true);
To create print panel use a grid layout for the panel and add the data or content as labels
java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and sh...
I need to add a method high school student, I couldn't connect high school student to student please help!!! package chapter.pkg9; import java.util.ArrayList; import java.util.Scanner; public class Main { public static Student student; public static ArrayList<Student> students; public static HighSchoolStudent highStudent; public static void main(String[] args) { int choice; Scanner scanner = new Scanner(System.in); students = new ArrayList<>(); while (true) { displayMenu(); choice = scanner.nextInt(); switch (choice) { case 1: addCollegeStudent(); break; case 2: addHighSchoolStudent(); case 3: deleteStudent(); break; case...
Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get...
After pillaging for a few weeks with our new cargo bay upgrade, we decide to branch out into a new sector of space to explore and hopefully find new targets. We travel to the next star system over, another low-security sector. After exploring the new star system for a few hours, we are hailed by a strange vessel. He sends us a message stating that he is a traveling merchant looking to purchase goods, and asks us if we would...
I need a shoppingcartmanager.java that contains a main method for this code in java Itemtopurchase.java public class ItemToPurchase { // instance variables private String itemName; private String itemDescription; private int itemPrice; private int itemQuantity; // default constructor public ItemToPurchase() { this.itemName = "none"; this.itemDescription = "none"; this.itemPrice = 0; this.itemQuantity = 0; } public ItemToPurchase(String itemName, int itemPrice, int itemQuantity,String itemDescription) { ...
I need help in converting this into pseudo-code Student.java public class Student implements Comparable<Student>{ private String name, major, status; private int rank; public Student() { this.name = this.major = this.status = ""; this.rank = 0; } public Student(String name, String major, String status) { this.name = name; this.major = major; this.status = status; } public String getName() { return name; } public String getMajor() { return major; } public String getStatus() { return status; } public int...
Could you help me pleas , this is my code I want change it to insert student by user , and i have problem when i want append name it just one time i can't append or present more one. >>>>>>>>>>>>>>>>>>>. import java.util.Iterator; import java.util.Scanner; public class studentDLLTest { static int getChoice() { Scanner in = new Scanner(System.in); int choice; do { System.out.print("\nYour choice? : "); choice = in.nextInt(); } while (choice < 1 || choice > 9); return choice;...
I need code in java
The Student class:
CODE IN JAVA:
Student.java file:
public class Student {
private String name;
private double gpa;
private int idNumber;
public Student() {
this.name = "";
this.gpa = 0;
this.idNumber = 0;
}
public Student(String name, double gpa, int
idNumber) {
this.name = name;
this.gpa = gpa;
this.idNumber = idNumber;
}
public Student(Student s)...
MERGESORT ASSIGNMENT FOLLOW THE FORMAT Modify the MergeSort code provided in class (if you find a mistake with it extra credit) (https://repl.it/@ashokbasawapatna/MergeSortExample) to work with Students (No need for generic types, you will only write Main.java). Then use the compareTo method for strings in Java to sort the students in Alphabetical order via MergeSort. 1) Create an array of 10 students by hand. Make sure it's not in alphabetical order. ONLY USE LOWER CASES FOR NAMES (I'll only test with...
I have a little problem about my code. when i'm working on "toString method" in "Course" class, it always say there is a mistake, but i can not fix it: Student class: public class Student { private String firstName; private String lastName; private String id; private boolean tuitionPaid; public Student(String firstName, String lastName, String id, boolean tuitionPaid) { this.firstName=firstName; this.lastName=lastName; this.id=id; this.tuitionPaid=tuitionPaid; } ...
How can the java code be edited that when someone exits the lot, they receive an exiting timestamp. And also i would need that exit timestamp to be subtracted from the timestamp the driver gets when entering the lot to find out the total amount of time they were in the parking lot. please explain. should only need a couple of lines added. //////////////////////////////ParkingCarInfo.java/////////////////////////////////////////// package test; import java.sql.Timestamp; //Class: ParkingCarInfo public class ParkingCarInfo { private String name; //name private Timestamp...