Question

In: Computer Science

Design a complete system to allow manipulation of Students (via a designed and developed Student class)....

Design a complete system to allow manipulation of Students (via a designed and developed Student class). in JAVA

It Includes:

1) A Student Class which stores info about the student: name and a generated ID#.

2) User interface (via Scanner) that prompts user for the following:

a) New Student -- user enters the name of the student, the system (your student class will generate the ID#)

b) View Student via Name - the user enters name (not case sens., and partial search works..) outputs full name of student and ID# of student

c) Delete Student - the user enters name (not case sens.) and system deletes this Student from System.

d)View All - displays all students in System and associated ID#s

e) quit -- quits the system

Solutions

Expert Solution

Solution of the above problem is provided below.

Code comments and annotations are provided for better understanding of the code. for moew help write into comment section of the code.

Student.java



public class Student {
        
        private String name;
        private int id;
        
        /**
         * @param name
         */
        public Student(String name) {
                super();
                this.name = name;
                /* Generating random Id in range 1-999 using Math.random();*/
                id = (int) Math.random() * (999 - 1 + 1) + 1; 
        }

        /**
         * @return the name
         */
        public String getName() {
                return name;
        }

        /**
         * @param name the name to set
         */
        public void setName(String name) {
                this.name = name;
        }

        /**
         * @return the id
         */
        public int getId() {
                return id;
        }

        /**
         * @param id the id to set
         */
        public void setId(int id) {
                this.id = id;
        }

        @Override
        public String toString() {
                return "Student [name=" + name + ", id=" + id + "]";
        }
        
        
        
        

}

Main.java <Driver code for programe>


import java.util.*;

public class Main {
        static ArrayList<Student> students;

        public static void main(String[] args) {
                
                // initialising students arraylist to stire student objects
                students = new ArrayList<>();

                Scanner sc = new Scanner(System.in);

                // taking choice from user
                int choice;

                do {
                        // calling menu
                        userInterface();

                        choice = sc.nextInt();

                        switch (choice) {
                        case 1: {
                                
                                /*creating a new student object by taking student name from the console*/
                                
                                System.out.println("Enter Student name: ");
                                String studentName = sc.next();
                                // creating student object
                                Student newStudent = new Student(studentName);

                                // adding student to the arraylist of students
                                students.add(newStudent);

                                break;
                        }

                        case 2: {
                                /* View info of student after entering student name*/
                                System.out.println("Enter name to view info: ");
                                String enteredName = sc.next();
                                for (int i = 0; i < students.size(); i++) {
                                        if (students.get(i).getName().equalsIgnoreCase(enteredName))
                                                ;
                                        System.out.println(students.get(i).toString());
                                }
                                break;
                        }

                        case 3: {
                                /*Delete student from arraylist after searching that element from the list*/
                                System.out.println("Enter name to delete: ");
                                String enteredName = sc.next();
                                for (int i = 0; i < students.size(); i++) {
                                        if (students.get(i).getName().equalsIgnoreCase(enteredName));
                                        students.remove(i);
                                }
                                break;
                        }

                        case 4: {
                                System.out.println("All students " + students.size());
                                for (Student student : students) {
                                        System.out.println(student.toString());
                                }
                                break;
                        }

                        case 5: {
                                System.out.println("\nExiting...\n");
                                System.exit(0);
                                break;
                        }

                        default:
                                System.out.println("\nInvalid selection!\n");
                        }
                } while (choice != 5);
        }

        private static void userInterface() {
                System.out.print("\n1. Add New Student\n" + "2. View Student Via Name\n" + "3. Delete Student   \n"
                                + "4. View all Students \n" + "5. Quit.\n" + "Your selection:");
        }

}

Output:

End of Solution


Related Solutions

C++ Question Design and implement a class that stores a list of students. Each student has...
C++ Question Design and implement a class that stores a list of students. Each student has the list of courses he/she registered for the semester. You will need a container of containers to hold this list of students. Choose the optimal container for this exercise, noting that no duplicates should be permitted. Use STL classes with iterators to navigate the list. Develop a test program, which allows options to add, remove, and list students and their associated course lists. Also...
This assessment is designed to apply the knowledge and skills developed by students in evaluating the...
This assessment is designed to apply the knowledge and skills developed by students in evaluating the role of systems thinking in global and local sustainability challenges. You have been assigned a case study on the LMS, and must answer the following questions in relation to the case: Using the Iceberg model, explain if and how systems thinking might be useful in addressing the wickedness of the problem. (500 words).
This assessment is designed to apply the knowledge and skills developed by students in evaluating the...
This assessment is designed to apply the knowledge and skills developed by students in evaluating the role of systems thinking in global and local sustainability challenges. You have been assigned a case study on the LMS, and must answer the following questions in relation to the case: Why is supply chain topic a wicked problem? Explain using the characteristics of a wicked problem. (400 words)
A study was conducted of the effects of a special class designed to aid students with...
A study was conducted of the effects of a special class designed to aid students with verbal skills. Each child was given a verbal skills test twice, both before and after completing a 4- week period in the class. Let Y = score on exam at time 2 - score on exam at time 1. Hence, if the population mean µ for Y is equal to 0, the class has no effect, on the average. For the four children in...
The average height for a student in a class with n = 60 students is a...
The average height for a student in a class with n = 60 students is a random variable with an average height of 180 cm and standard deviation σ = 10. The individual heights which make up that average are i.i.d. (1) use Chebyshev’s inequality to find an upper bound for the probability that the average of the class (obtained from the individual student heights) is greater than 200cm. (2) Use Chebyshev’s inequality to upper bound the probability that the...
Design and implement a program to allow a college administrator to register new students and add...
Design and implement a program to allow a college administrator to register new students and add courses to the existing one. In addition, your program should allow the administrator to do the following: • Add/Remove a new student • Add/Remove a course to/from a selected student • Search for a student either by last name or by id. • Search for a course either by name or by id. • Display a selected student along with the courses s/he is...
A tire company has developed a new tread design and claim that the newly designed tire...
A tire company has developed a new tread design and claim that the newly designed tire has a mean life of 60,000 miles or more. To examine the claim, a random sample of 16 prototype tires is tested. The mean tire life for this sample is 60,758 miles. Assume that the tire life is normally distributed with unknown mean µ and standard deviation σ=1500 miles. (a) Please construct a 90% confidence interval for the mean life of the new designed...
The Incident Command System is a standardized management tool designed to allow its users to adopt...
The Incident Command System is a standardized management tool designed to allow its users to adopt an integrated organizational structure flexible enough to meet the demands of small or large emergency or non-emergency situations. But the Incident Command System has been at times criticized for ignoring the importance of inter-organizational relationships, the spontaneous nature of response, the role of unorganized volunteers, and the potential for conflict between organizations. Often the challenge can be reconstituting command and control after an improvised...
As part of their class requirements, the students in Dr. Taylor’s Research Design and Analysis class...
As part of their class requirements, the students in Dr. Taylor’s Research Design and Analysis class are sent over to Trumbull Mall to observe interactions between mothers and their toddler-aged children. They are told not to interact with the moms at all, but just record certain behaviors, like the number of times they speak harshly to their children and the number of times the children whine or cry. One of the mothers notices that the students are watching people and...
Complete the following class UML design class diagram by filling in all the sections based on...
Complete the following class UML design class diagram by filling in all the sections based on the information given below.         The class name is Boat, and it is a concrete entity class. All three attributes are private strings with initial null values. The attribute boat identifier has the property of “key.” The other attributes are the manufacturer of the boat and the model of the boat. Provide at least two methods for this class. Class Name: Attribute Names: Method...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT