Question

You will be designing and creating a Java GUI-based course application. Create a “Student” class. You...

You will be designing and creating a Java GUI-based course application.

Create a “Student” class. You need to have at least 3 instance variables (student characteristics like name,…), at least 2 constructors (1 should be a no-arg constructor), set and get methods.

Create a “Course” class that consists of 2 instance variables: the course name and an array of Students (using your Student class).

Design and create a JavaFX-based GUI interface that allows you to :

INPUT information for Course and Students taking the course—you will use your Student and Course classes to save this info and then

OUTPUT all this information in another section of the GUI window (Do not use a JOptionPane) when the user selects a particular course and wants to see the students in the course.

SAVE the information you input into an external file.

NOTE: You can design this window anyway you want … please do not use JOptionPane to do any of this GUI interface … use the JavaFX library.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Gui.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="586.0" prefWidth="631.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.GuiController">
<children>
<TextField fx:id="ciTF" layoutX="190.0" layoutY="259.0" prefHeight="39.0" prefWidth="288.0" />
<Label layoutX="43.0" layoutY="196.0" prefHeight="27.0" prefWidth="56.0" text="Credits" />
<Label layoutX="45.0" layoutY="265.0" text="Course Name" />
<TextField fx:id="snTF" layoutX="190.0" layoutY="69.0" prefHeight="39.0" prefWidth="288.0" />
<TextField fx:id="cTF" layoutX="190.0" layoutY="190.0" prefHeight="39.0" prefWidth="288.0" />
<Label layoutX="43.0" layoutY="75.0" text="Student Name" />
<Label layoutX="44.0" layoutY="138.0" text="Division" />
<TextField fx:id="dTF" layoutX="190.0" layoutY="132.0" prefHeight="39.0" prefWidth="288.0" />
<Button layoutX="243.0" layoutY="369.0" mnemonicParsing="false" onAction="#saveInfo" text="Save Information" />
<Button layoutX="76.0" layoutY="369.0" mnemonicParsing="false" onAction="#saveToFile" text="Save to File" />
<MenuBar onMouseClicked="#showDialogBox">
<menus>
<Menu mnemonicParsing="false" text="Show Information" />
</menus>
</MenuBar>
</children>
</AnchorPane>

//Dialog.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="608.0" prefWidth="613.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.GuiController">
<children>
<ComboBox fx:id="cnCB" promptText="Choose" layoutX="185.0" layoutY="56.0" onAction="#loadStudentName" prefHeight="39.0" prefWidth="228.0" />
<ComboBox fx:id="snCB" promptText="Choose" layoutX="185.0" layoutY="112.0" onAction="#loadStudentInfo" prefHeight="39.0" prefWidth="228.0" />
<Label layoutX="34.0" layoutY="62.0" text="Course Name" />
<Label layoutX="34.0" layoutY="118.0" text="Student Name" />
<Label layoutX="34.0" layoutY="182.0" text="Division" />
<TextField fx:id="cnTF" layoutX="185.0" layoutY="176.0" prefHeight="39.0" prefWidth="228.0" />
<Label layoutX="34.0" layoutY="235.0" text="Class" />
<TextField fx:id="divTF" layoutX="186.0" layoutY="229.0" prefHeight="39.0" prefWidth="228.0" />
</children>
</AnchorPane>

//Main.java

package application;
  
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;


public class Main extends Application {
   @Override
   public void start(Stage primaryStage) {
       try {
           Parent root = FXMLLoader.load(getClass().getResource("Gui.fxml"));
           Parent root1 = FXMLLoader.load(getClass().getResource("DialogBox.fxml"));
           Scene scene = new Scene(root,500,500);
           scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
           primaryStage.setScene(scene);
           primaryStage.setTitle("Student-Course Information");
           primaryStage.show();
       } catch(Exception e) {
           e.printStackTrace();
       }
   }
  
   public static void main(String[] args) {
       launch(args);
   }
}

//GuiController.java

package application;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import java.util.ResourceBundle;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
import javafx.scene.control.ComboBox;

public class GuiController {

   @FXML
   private TextField snTF, cTF, dTF, ciTF, divTF,cnTF;
   @FXML
   private ComboBox<String> cnCB, snCB;

   public static List<Course> list;
  

   @FXML
   protected void saveToFile(ActionEvent event) throws IOException {
  
       BufferedWriter bw = null;
       FileWriter fw = null;
       try {
          
           fw = new FileWriter("C:\\avg\\gui.txt");
           bw = new BufferedWriter(fw);
          
           for(Course c : list) {
               bw.write(c.courseName);
               bw.newLine();
               for(Student s : c.students) {
                   bw.write(s.getName());
                   bw.newLine();
                   bw.write(s.getCredits());
                   bw.newLine();
                   bw.write(s.getDiv());
                   bw.newLine();
               }
           }
           bw.flush();
          
       } catch(Exception e) {
          
       }
      
       fw.close();
       bw.close();
   }
  
   @FXML
   protected void loadStudentInfo(ActionEvent event) {
      
       String course = cnCB.getSelectionModel().getSelectedItem();
       String student = snCB.getSelectionModel().getSelectedItem();

       for (Course c : list) {
           if (c.courseName.equals(course)) {              
               for (Student s : c.students) {
                   if(s.getName().equals(student)) {
                       cnTF.setText(String.valueOf(s.getCredits()));
                       divTF.setText(s.getDiv());
                   }
                  
               }              
           }
       }  
      
   }

   @FXML
   protected void showDialogBox(MouseEvent event) {

       try {
           Stage primaryStage = new Stage();
           FXMLLoader loader = new FXMLLoader(getClass().getResource("DialogBox.fxml"));
           Parent root = (Parent)loader.load();
           GuiController cont = loader.<GuiController>getController();
          
           Scene scene = new Scene(root, 500, 500);
           scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
           primaryStage.setScene(scene);
           primaryStage.setTitle("Student-Course Information");
          
           List<String> courseL = new LinkedList<String>();
           for (Course l : list) {
               courseL.add(l.courseName);
           }
           snTF.getText();
           ObservableList<String> courseList = FXCollections.observableArrayList(courseL);
           cont.cnCB.setItems(courseList);          
           primaryStage.show();          

       } catch (Exception e) {
           e.printStackTrace();
       }
   }

   @FXML
   protected void loadStudentName(ActionEvent event) {  

       String course = cnCB.getSelectionModel().getSelectedItem();

       for (Course c : list) {
           if (c.courseName.equals(course)) {
               List<String> stdName = new LinkedList<>();
               for (Student s : c.students) {
                   stdName.add(s.getName());
               }
               snCB.setItems(FXCollections.observableArrayList(stdName));
           }
       }
   }

   @FXML
   protected void saveInfo(ActionEvent event) {

       if (snTF.getText().equals("")) {

           Alert a = new Alert(AlertType.ERROR);
           a.setTitle("Error");
           a.setContentText("Please enter Student Name");
           a.showAndWait().ifPresent(rs -> {
               if (rs == ButtonType.OK) {

               }
           });
       } else if (cTF.getText().equals("")) {

           Alert a = new Alert(AlertType.ERROR);
           a.setTitle("Error");
           a.setContentText("Please enter Credits");
           a.showAndWait().ifPresent(rs -> {
               if (rs == ButtonType.OK) {

               }
           });
       } else if (ciTF.getText().equals("")) {

           Alert a = new Alert(AlertType.ERROR);
           a.setTitle("Error");
           a.setContentText("Please enter Coure Name");
           a.showAndWait().ifPresent(rs -> {
               if (rs == ButtonType.OK) {

               }
           });
       } else if (dTF.getText().equals("")) {

           Alert a = new Alert(AlertType.ERROR);
           a.setTitle("Error");
           a.setContentText("Please enter Division");
           a.showAndWait().ifPresent(rs -> {
               if (rs == ButtonType.OK) {

               }
           });
       } else {

           Student s = new Student();
           s.setName(snTF.getText());
           s.setDiv(dTF.getText());
           s.setCredits(Integer.parseInt(cTF.getText()));

           Course c = new Course();
           c.courseName = ciTF.getText();
           c.students.add(s);

           if(list == null) {
               list = new LinkedList<Course>();
               list.add(c);
           }
              
          
           else {
               boolean flag = false;
               for(Course co:list) {
                   if(co.courseName.equalsIgnoreCase(c.courseName))
                   {
                       co.students.add(s);
                       flag = true;
                       break;
                   }
               }
               if(!flag)
                   list.add(c);
           }
          
          

           snTF.setText("");
           dTF.setText("");
           cTF.setText("");
           ciTF.setText("");
       }

   }

}

//student.java

package application;

public class Student {

   private String name;
   private String div;
   private int credits;
  
   public Student() {
       name ="";
       div = "";
       credits = 0;         
   }
  
   public Student(String n, String d, int c) {
       name = n;
       div = d;
       credits = c;
   }

   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public String getDiv() {
       return div;
   }

   public void setDiv(String div) {
       this.div = div;
   }

   public int getCredits() {
       return credits;
   }

   public void setCredits(int credits) {
       this.credits = credits;
   }
  
}

//Course.java

package application;

import java.util.LinkedList;
import java.util.List;

public class Course {

   String courseName;
   List<Student> students = new LinkedList<Student>();
  
}

//Create JavaFx project and put all files there

Add a comment
Know the answer?
Add Answer to:
You will be designing and creating a Java GUI-based course application. Create a “Student” class. You...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Project 2 (required). Student Information Management System Write a GUI Application that is a MIS...

    i need help with the code and output screen shot Project 2 (required). Student Information Management System Write a GUI Application that is a MIS for students. Information of student includes student ID, name, date of birth, gender, major, grade, introduction, etc. The MIS has to provide insertion, deletion, query, and modification for students. To solve this application you have to: i. Design a friendly GUI based on JavaFX i. Provide the necessary functions, such as data insertion, data deletion,...

  • Visual C# Homework 2 You are to write a program which will create a class called...

    Visual C# Homework 2 You are to write a program which will create a class called Student Each student has a name age height and weight. These variables should be declared as private. Create the correct constructors and functions. In the main, you will create 5 students. Input the data for the 5 students from a file which already has information in it. Name the file “Information.txt”. After setting up all the data, it is time to sort based on...

  • In JAVA please! Write program for exercises You will write a Graphical User Interface(GUI) application to manage student...

    In JAVA please! Write program for exercises You will write a Graphical User Interface(GUI) application to manage student information system. The application should allow: 1. Collect student information and store it in a binary data file. Each student is identified by an unique ID. The user should be able to view/edit an existing student. Do not allow student to edit ID. 2. Collect Course information and store it in a separate data file. Each course is identified by an unique...

  • Need help to create general class Classes Data Element - Ticket Create an abstract class called...

    Need help to create general class Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...

  • In Java. Write a GUI contact list application. The program should allow you to input names...

    In Java. Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...

  • Java: student directory GUI You need to implement three classes: Person Student StudentDirectory StudentMain Start by...

    Java: student directory GUI You need to implement three classes: Person Student StudentDirectory StudentMain Start by implementing Person and Student classes. Once you are sure you can serialize and deserialize and ArrayList of Students to and from a file, move on to building the GUI application. Person: The Person class should implement serializable interface. It contains the following: Person's first name (String) Person's last name (String) Person's id number Person's date of birth (Date) public String toString(): This method method...

  • Create a Business class: Instance variables: Student id 1000 - 9999 Student name Present Student email...

    Create a Business class: Instance variables: Student id 1000 - 9999 Student name Present Student email address Present Number of hours 3.5 - 18 Two constructors should be coded, one that accepts no arguments and sets every field to its default value, and one that accepts all four fields, and assigns the passed values into the instance variables. For each instance variable create two methods; a getter and a setter. Add a static method to the class that will accept...

  • Create Student class•Change header so that Student extends Person•A Student has-an additional instance variable, major of...

    Create Student class•Change header so that Student extends Person•A Student has-an additional instance variable, major of type String.•Add the instance variable, its getters and setters. •Add a toString method to the Student class. It should reuse the toString method of Person. •Add two constructors: –No args–Constructor that receives the student’s name, birth year and Major as parameters•Create a class TestInheritance3–Create 2 Student objects–Create an Instructor object–Print the information about the two students and the instructor using the getters of Person,...

  • I. User Interface Create a JavaFX application with a graphical user interface (GUI) based on the...

    I. User Interface Create a JavaFX application with a graphical user interface (GUI) based on the attached “GUI Mock-Up”. Write code to display each of the following screens in the GUI: A. A main screen, showing the following controls: • buttons for “Add”, “Modify”, “Delete”, “Search” for parts and products, and “Exit” • lists for parts and products • text boxes for searching for parts and products • title labels for parts, products, and the application title B. An add...

  • Course Class Create a class called Course. It will not have a main method; it is...

    Course Class Create a class called Course. It will not have a main method; it is a business class. Put in your documentation comments at the top. Be sure to include your name. Course must have the following instance variables named as shown in the table: Variable name Description crn A unique number given each semester to a section (stands for Course Registration Number) subject A 4-letter abbreviation for the course (e.g., ITEC, PHED, CHEM) number A 4-digit number associated...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT