Question

Hello. can anyone solve this. i am having hard time with this. please post a solution...

Hello. can anyone solve this. i am having hard time with this. please post a solution ASAP

a) Create a class named Student. Data fields for Student class include an integer Student ID, a String name, and a double CGPA. Methods include a constructor that requires values for all data fields, as well as get and set methods for each of the data fields. b) Create an application that allows a user to enter values for an array of 15 Student objects. Offer the user the choice of displaying the objects in order by either Student ID or CGPA. Save the application as StudentDemo.java. c) Now, create another application that allows you to store an array that acts as a database of any number of Student objects up to 35. While the user decides to continue, offer three options: to add a record to the database, to delete a record from the database, or to change a record in the database. Then proceed as follows:  If the user selects the add option, issue an error message if the database is full. Otherwise, prompt the user for Student ID. If the Student ID already exists in the database, issue an error message. Otherwise, prompt the user for student name, a valid CGPA (>0 and <=4.0) and add the new record to the database.  If the user selects the delete option, issue an error message if the database is empty. Otherwise, prompt the user for Student ID. If the Student ID does not exist, issue an error message. Otherwise, do not access the record for any future processing.  If the user selects the change option, issue an error message if the database is empty. Otherwise, prompt the user for Student ID. If the requested record does 2 not exist, issue an error message. Otherwise, prompt the user for a new CGPA and change the CGPA value for the record.  After each option executes, display the updated database in ascending order by Student ID and prompt the user to select the next action. Save the application as SDatabase.java.  Part c should be done using array but not ArrayList.

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

thanks for the question, here is the solution to the first part -  b) Create an application that allows a user to enter values for an array of 15 Student objects. Offer the user the choice of displaying the objects in order by either Student ID or CGPA.

Please post the second part of the question as a separate post and I will assist you in that as well. As per Chegg policy, I am instructed to answer the first part only.

Here are the two classes - Student.java and StudentDemo.java

================================================================

public class Student{

    private int studentID;
    private String studentName;
    private double CGPA;

    public Student(int studentID, String studentName, double CGPA) {
        this.studentID = studentID;
        this.studentName = studentName;
        this.CGPA = CGPA;
    }

    public int getStudentID() {
        return studentID;
    }

    public void setStudentID(int studentID) {
        this.studentID = studentID;
    }

    public String getStudentName() {
        return studentName;
    }

    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    public double getCGPA() {
        return CGPA;
    }

    public void setCGPA(double CGPA) {
        this.CGPA = CGPA;
    }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

import java.util.Arrays;

import java.util.Comparator;

import java.util.Scanner;



public class StudentDemo {



    public static void main(String[] args) {



        Scanner scanner = new Scanner(System.in);

        Student students[] = new Student[15]; // create an empty array of type Student


                // store the student details in each index of the array
        for (int count = 1; count <= students.length; count++) {

            System.out.print("Enter student ID as an integer: ");

            int id = scanner.nextInt();

            scanner.nextLine();

            System.out.print("Enter student name: ");

            String name = scanner.nextLine();

            System.out.print("Enter student\'s CGPA score: ");

            double cgpa = scanner.nextDouble();



            students[count - 1] = new Student(id, name, cgpa);

        }



        int choice;

        do {

            System.out.println("Enter 1 for displaying by Id 2 for displaying by CGPA score: ");

            choice = scanner.nextInt();

        } while (choice != 1 && choice != 2);



        if (choice == 1) {

            Arrays.sort(students, new Comparator<Student>() {

                @Override

                public int compare(Student studentOne, Student studentTwo) {

                    return -studentTwo.getStudentID() + studentOne.getStudentID();

                }

            });

            System.out.println("Displaying by Student ID in ascending order");

        } else {

            Arrays.sort(students, new Comparator<Student>() {

                @Override

                public int compare(Student studentOne, Student studentTwo) {

                    return Double.compare(studentOne.getCGPA(), studentTwo.getCGPA());

                }

            });

            System.out.println("Displaying by Student CGPA in ascending order");

        }



        for (Student student : students) {

            System.out.println(student.getStudentID() + ", " + student.getStudentName() + ", " + student.getCGPA());

        }

    }

}

================================================================

Add a comment
Know the answer?
Add Answer to:
Hello. can anyone solve this. i am having hard time with this. please post a solution...
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
  • Looking for some help with this Java program I am totally lost on how to go about this. You have been approached by a local grocery store to write a program that will track the progress of their sale...

    Looking for some help with this Java program I am totally lost on how to go about this. You have been approached by a local grocery store to write a program that will track the progress of their sales people (SalesPerson.java) The information needed are: D Number integer Month 1 Sales Amount-Double Month 2 Sales Amount-Double Month 3 Sales Amount-Double Write a Java program that allows you to store the information of any salesperson up to 20 While the user...

  • This program will store a roster of most popular videos with kittens. The roster can include...

    This program will store a roster of most popular videos with kittens. The roster can include at most 10 kittens.You will implement structures to handle kitten information. You will also use functions to manipulate the structure. (1) Create a structure kitten. The structure should contain the following attributes: name; string color; string score; integer Important! The name of the structure and each of its field must match exactly for the program to work and be graded correctly. (2) Create a...

  • Hello all, I have a c++/unix (bash) question. I am struggling on starting this assignment. If...

    Hello all, I have a c++/unix (bash) question. I am struggling on starting this assignment. If you could start the assignment and tell me how to do the rest it would be greatly appreciated! (Quick thumbs up answer response if thorough and correct) Maintain automobile records in a database Write a shell script to create, view and modify a simple database that contains automobile records. The shell script has to be done in Bourne shell syntax (bash as a matter...

  • Hi, I am writing Java code and I am having a trouble working it out. The...

    Hi, I am writing Java code and I am having a trouble working it out. The instructions can be found below, and the code. Thanks. Instructions Here are the methods needed for CIS425_Student: Constructor: public CIS425_Student( String id, String name, int num_exams ) Create an int array exams[num_exams] which will hold all exam grades for a student Save num_exams for later error checking public boolean addGrade( int exam, int grade ) Save a grade in the exams[ ] array at...

  • Here is everything I have on my codes, the compiler does not allow me to input...

    Here is everything I have on my codes, the compiler does not allow me to input my name, it will print out "Please enter your name: " but totally ignores it and does not allow me to input my name and just proceeds to my result of ID and Sale. Please help. I've bolded the part where it I should be able to input my name package salesperson; public class Salesperson { String Names; int ID; double Sales; // craeting...

  • Please, please help with C program. This is a longer program, so take your time. But...

    Please, please help with C program. This is a longer program, so take your time. But please make sure it meets all the requirements and runs. Here is the assignment: I appreciate any help given. Cannot use goto or system(3) function unless directed to. In this exercise you are to create a database of dogs in a file, using open, close(), read, write(), and Iseek(). Do NOT use the standard library fopen() ... calls! Be sure to follow the directions!...

  • please make sure to write down all the coding and the output for it and to...

    please make sure to write down all the coding and the output for it and to do all three steps Student Name: 1. Write a class named Employee that holds the following data about an employee in attributes: name, ID number, department, and job title. (employee.py) 2. Create a UML diagram for Employee class. (word file) 3. Create a program that stores Employee objects in a dictionary. Use the employee ID number as the key. (employee_App.py) The program should present...

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

  • Java programming The purpose of this problem is to practice using a generic Urn class. NOTE:...

    Java programming The purpose of this problem is to practice using a generic Urn class. NOTE: Refer to the code for the ArrayStack class from Chapter 12. Use that code as a starting point to create the Urn class, modifying it to remove the methods in the ArrayStack class (push, pop, etc) then add the methods described below. Also change the variable names to reflect the new class. For example the array name should NOT be stack, instead it should...

  • Hello! I am to create a .js file that allows the paragraph on the bottom of...

    Hello! I am to create a .js file that allows the paragraph on the bottom of the page to update with what the user enters. I need to modify the given HTML to recognize the javascript file that I am to make from scratch. The HTML file and other details are below: Use the given HTML to add functionality to an interactive form that generates an invitation to volunteers for an event. The file will have the following invitation message...

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