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

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).
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...
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...
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...
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...
1) Design an implement a program that created and exception class called StringTooLongException, designed to be...
1) Design an implement a program that created and exception class called StringTooLongException, designed to be thrown when a string is discovered that has too many characters in it. Create a driver that reads in strings from the user until the user enters DONE. If a string that has more then 5 characters is entered, throw the exception. Allow the thrown exception to terminate the program 2) Create a class called TestScore that has a constructor that accepts an array...
AT coaching: A sample of 10 students took a class designed to improve their SAT math...
AT coaching: A sample of 10 students took a class designed to improve their SAT math scores. Following are their scores before and after the class. Before After 451 454 453 463 491 511 526 529 473 493 440 466 481 482 459 455 399 404 383 420 Send data to Excel Part: 0 / 2 0 of 2 Parts Complete Part 1 of 2 (a) Construct a 95% confidence interval for the mean increase in scores after the class....
Two professors at a local college developed a new teaching curriculum designed to increase​ students' grades...
Two professors at a local college developed a new teaching curriculum designed to increase​ students' grades in math classes. In a typical developmental math​ course, 55​% of the students complete the course with a letter grade of​ A, B, or C. In the experimental​ course, of the 15 students​ enrolled, 12 completed the course with a letter grade of​ A, B, or C. Is the experimental course effective at the alpha equals 0.025 level of​ significance? Complete parts ​(a) through​...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT