Question

Write a Java program which will store, manipulate, and print student registration information. As part of...

  1. Write a Java program which will store, manipulate, and print student registration information.

As part of the solution, identify the following classes:

  • Student
  • Admissions.

The class Student must have the following fields – Name, Address, Id number, Courses, and Date, where:

  • Name is a user defined class comprising of at minimum first name and last name.
  • Address is a user defined class comprising of fields - street, city, state, and zip code.
  • Date is a predefined class in the java.util package
  • The field Courses is a set of no more than five (5) string values representing the courses being registered for. Course names supplied are assumed to be valid and contains no blank space, for instance COP3337 is valid but not COP 3337.
  • Id number a string variable that uniquely identifies a student.

The class Student must be capable of adding courses and dropping courses

The class Admissions stores and manipulates the student information (student record). Because the list of students grows dynamically, it is best to use a dynamic data structure such as the ArrayList to store the information. This class should do the following, among other possible activities:

  • Add student to the list
  • Remove student from the list, which would first involve locating the record in order to remove it. In order to determine which record to remove you must supply the Id number as the search argument.

You are to provide a test class that coordinates the activities of the classes outlined above, by:

  • Creating student objects and adding them to the database of the Admissions object
  • Manipulating student record by:
    • Adding a course(s)
    • Dropping a course(s)
  • Removing a student from the database
  • Displaying list of currently registered students
  • Displaying list of all students that were dropped from the course

Display the output in a scrollable pane, and must be formatted as follows:

CURRENTLY ENROLLED

Id number: 123456

Name:         Williams, John

Address:      2525 Hartsfield Road

Tallahassee, FL 33319

Date:          September 5, 2009

Courses:      COP3804, MATH2050, ENG3300

                  :

                  :

:

STUDENT WHO WERE DROPPED

Id number: 567890

Name:         Roberts, Kay-Anne

Date:          September 5, 2009

                  :

                  :

Note: Use the class GetData provided to enter the data from the keyboard.

  1. import javax.swing.JOptionPane;
  2. class GetData
  3. {
  4. static double getDouble(String s)
  5. {
  6. return Double.parseDouble(getWord(s));             
  7. }
  8. static int getInt(String s)
  9. {
  10. return Integer.parseInt(getWord(s));      
  11. }
  12. static String getWord(String s)
  13. {
  14. return JOptionPane.showInputDialog(s);
  15. }
  16. }

The method display shown below shows how to display information in a scrollable pane. Listing 1.8 of text shows how the class GetData and the method display are implemented within a program.

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

package Session2;

//class for name
public class Name {
//fields

    private String FirstName;
    private String LastName;
//default constructor

    public Name() {
        this.FirstName = "";
        this.LastName = "";
    }
//parameterised constructor

    public Name(String FirstName, String LastName) {
        this.FirstName = FirstName;
        this.LastName = LastName;
    }
//accessor and mutators for all fields

    public String getFirstName() {
        return FirstName;
    }

    public void setFirstName(String FirstName) {
        this.FirstName = FirstName;
    }

    public String getLastName() {
        return LastName;
    }

    public void setLastName(String LastName) {
        this.LastName = LastName;
    }
//tostring to print Name

    @Override
    public String toString() {
        return "Name: " + LastName + ", " + FirstName;
    }
}

package Session2;


//class for Address
public class Address {
//fields street, city, state, and zip code

    private String street;
    private String city;
    private String state;
    private String zip_code;

//default constructor
    public Address() {
        this.street = "";
        this.city = "";
        this.state = "";
        this.zip_code = "";
    }

//parameterised constructor
    public Address(String street, String city, String state, String zip_code) {
        this.street = street;
        this.city = city;
        this.state = state;
        this.zip_code = zip_code;
    }
//accessor and mutators for all fields

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getZip_code() {
        return zip_code;
    }

    public void setZip_code(String zip_code) {
        this.zip_code = zip_code;
    }

//tostring to print Address
    @Override
    public String toString() {
        return "Address: " + street + " " + city + " " + state + ", " + zip_code;
    }
}

package Session2;

import java.util.Date;

//class student

public class Student {
//fields

    private int id;
    private Name Name;
    private Address Address;
    private String[] Courses;
    private int len;
    private Date Date;
//default constructor

    public Student() {
        this.id = 0;
        this.Name = null;
        this.Address = null;
        this.Courses = new String[5];
        this.len=0;
        this.Date = null;
    }
//parameterised constructor

    public Student(int id, Name Name, Address Address, String[] Courses, Date Date) {
        this.id = id;
        this.Name = Name;
        this.Address = Address;
        this.Courses = Courses;
        this.len=Courses.length;
        this.Date = Date;
    }

//accessor and mutators for all fields

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Name getName() {
        return Name;
    }

    public void setName(Name Name) {
        this.Name = Name;
    }

    public Address getAddress() {
        return Address;
    }

    public void setAddress(Address Address) {
        this.Address = Address;
    }

    public String[] getCourses() {
        return Courses;
    }

    public void setCourses(String[] Courses) {
        this.Courses = Courses;
        this.len=Courses.length;
    }
//method to add course

    public void addCourses(String newcourse) {
        if (len < 5) {
            Courses[len] = newcourse;
            len++;
            System.out.println("Courses added successfully");
        } else {
            System.out.println("More Courses can't be added");
        }
    }
//method to drop courses

    public void dropCourses(String oldCourses) {
        int index=0;
        String[] Course = new String[5];
        for (int i = 0; i < len; i++) {
            if (!Courses[i].equals(oldCourses)) {
                Course[index] = Courses[i];
                index++;
            }
        }
        if (index == len) {
            System.out.println("No such course found");
        } else {
            System.out.println("Courses dropped successfully");
            len--;
        }
        Courses = Course;
    }

    public Date getDate() {
        return Date;
    }

    public void setDate(Date Date) {
        this.Date = Date;
    }

    @Override
    public String toString() {
        return "id:" + id + ",\n Name=" + Name.toString() + ",\n Address=" + Address.toString() + ",\n Courses=" + Courses + ",\n Date=" + Date + "\n";
    }
}

package Session2;

import java.util.ArrayList;
import java.util.Date;
import javax.swing.JOptionPane;

class GetData {

    static double getDouble(String s) {
        return Double.parseDouble(getWord(s));
    }

    static int getInt(String s) {
        return Integer.parseInt(getWord(s));
    }

    static String getWord(String s) {
        return JOptionPane.showInputDialog(s);
    }
}

public class Admission {

    public ArrayList<Student> StudentRecord = new ArrayList();

    public void addStudent() {
        Student s = new Student();
        s.setId(GetData.getInt("Enter the id: "));
        s.setName(new Name(GetData.getWord("Enter FirstName: "), GetData.getWord("Enter LastName: ")));
        s.setAddress(new Address(GetData.getWord("Enter Street: "), GetData.getWord("Enter City: "), GetData.getWord("Enter state: "), GetData.getWord("Enter Zip Code: ")));
        s.addCourses(GetData.getWord("Enter a course"));
        s.setDate(new Date(GetData.getWord("Enter Date: ")));
        StudentRecord.add(s);
        System.out.println("Students Enrolled successfully");
    }

    public void dropStudent(int id) {
        for (int i = 0; i < StudentRecord.size(); i++) {
            if (StudentRecord.get(i).getId() == id) {
                StudentRecord.remove(i);
                System.out.println("Students Dropped successfully");
                break;
            }
            if (StudentRecord.size() == i) {
                System.out.println("No such Student found");
            }
        }
    }

    public void Studentlist() {
        for (int i = 0; i < StudentRecord.size(); i++) {
            StudentRecord.get(i).toString();
        }
    }
}

package Session2;

public class test {

    public static void main(String[] args) {
        Admission a = new Admission();
        a.addStudent();
        a.addStudent();
        a.Studentlist();
        a.dropStudent(GetData.getInt("Enter id of student to drop: "));
        a.Studentlist();
    }
}

output:

Add a comment
Know the answer?
Add Answer to:
Write a Java program which will store, manipulate, and print student registration information. As part of...
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
  • Writing 3 Java Classes for Student registration /** * A class which maintains basic information about...

    Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course {    /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...

  • You will create a class to keep student's information: name, student ID, and grade. The program...

    You will create a class to keep student's information: name, student ID, and grade. The program will have the following functionality: - The record is persistent, that is, the whole registry should be saved on file upon exiting the program, and after any major change. - The program should provide the option to create a new entry with a student's name, ID, and grade. - There should be an option to lookup a student from his student ID (this will...

  • How to complete this methods: import java.io.FileInputStream; import java.io.FileNotFoundException; import java.time.Loc...

    How to complete this methods: import java.io.FileInputStream; import java.io.FileNotFoundException; import java.time.LocalDate; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Scanner; import java.util.Set; /** * Utility class that deals with all the other classes. * * @author EECS2030 Summer 2019 * */ public final class Registrar {    public static final String COURSES_FILE = "Courses.csv";    public static final String STUDENTS_FILE = "Students.csv";    public static final String PATH = System.getProperty("java.class.path");    /**    * Hash table to store the list of students using their...

  • You are asked to build and test the following system using Java and the object-oriented concepts ...

    You are asked to build and test the following system using Java and the object-oriented concepts you learned in this course: Project (20 marks) CIT College of Information technology has students, faculty, courses and departments. You are asked to create a program to manage all these information's. Create a class CIT to represents the following: Array of Students, each student is represented by class Student. Array of Faculty, each faculty is represented by class Faculty. Array of Course, each course...

  • Question 1 (24 Marks] 1. (4 marks) Write an immutable Person class in Java which provides...

    Question 1 (24 Marks] 1. (4 marks) Write an immutable Person class in Java which provides the following. • Two attributes: lastName and first Name of type String. • Appropriate initialization, accessors/mutator methods. 2. (6 marks) Write a Student class that is a subclass of Person class (in the previous question) which provides the following. • Two attributes: A unique student ID of type String and GPA of type float; the student ID is initialized when a Student object gets...

  • Write a Student class that stores information for a Montclair student. The class should include the...

    Write a Student class that stores information for a Montclair student. The class should include the following instance variables id, an integer identifier for the student lastName, a string for the student's last name creditsEarned, an integer representing the number of course-credits the student has earned courseLoadCredits, an integer representing the current number of credits in progress. status, an integer representing the status of the student (1 means freshman, 2 means sophomore, 3 means junior, 4 means senior). This status...

  • Write a java code : Student ID at University is composed of year of admission and...

    Write a java code : Student ID at University is composed of year of admission and students number. we aim to implement a structure that improves operations of inserting and searching for a student. To enhance these operations, we will build a tree of linked lists (TreeOfLists) to combine advantages of both structures. Each node in this tree contains a linked list of all students who were admitted in that year. Each node in the linked list represents a student(id,...

  • 1. Do the following a. Write a class Student that has the following attributes: - name:...

    1. Do the following a. Write a class Student that has the following attributes: - name: String, the student's name ("Last, First" format) - enrollment date (a Date object) The Student class provides a constructor that saves the student's name and enrollment date. Student(String name, Date whenEnrolled) The Student class provides accessors for the name and enrollment date. Make sure the class is immutable. Be careful with that Date field -- remember what to do when sharing mutable instance variables...

  • what is the solution for this Java problem? Generics Suppose you need to process the following...

    what is the solution for this Java problem? Generics Suppose you need to process the following information regarding Students and Courses: A Student has a name, age, ID, and courseList. The class should have a constructor with inputs for setting name, ID and age. The class should have setters and getters for attributes name, ID and age, and a method addCourse, removeCourse, printSchedule. courseList: use the generic class ArrayList<E> as the type of this attribute addCourse: this method takes as...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    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)...

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
ADVERTISEMENT