Question

2. The Student Database Class: The object of this class should store a list of up to 10 objects of the Student class. This cl
o Add a set of Students to the Student Database through a file. public void AddStudents (String StudentsFile) // Max of 10 StO Allow the user to enter a Students id number, this method finds the Student with that specific id number in the database a3. A Student DatabaseDemo Class to test the above two classes. This class will only have the main method. In the main method

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) {
       this.name = s.name;
       this.gpa = s.gpa;
       this.idNumber = s.idNumber;
   }

   public String getName() {
       return name;
   }

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

   public double getGpa() {
       return gpa;
   }

   public void setGpa(double gpa) {
       this.gpa = gpa;
   }

   public int getIdNumber() {
       return idNumber;
   }

   public void setIdNumber(int idNumber) {
       this.idNumber = idNumber;
   }

}

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

Code:

Output:

Raw Code:

class Student{
   String name; // student name
   Student(String name){
       this.name = name; // storing student name
   }
}
class StudentDatabase{
   // declaring private variables
   private int NumStudents;
   private Student Students[];
   private int index = 0; // it is nothing but no of students present currently in the Students list
   StudentDatabase(int num){
       if (num > 10){ // if given num is greater then 10 then print error message
           System.out.println("The students size is soo large.");
       }
       else{ // otherwise assign it to NumStudents
           this.NumStudents = num;
           this.Students = new Student[NumStudents]; // creating Students list
       }
   }
   void addStudent(Student stu){ // addStudent method
       if (index == 10 || index==NumStudents){ // if the no of students is equal to 10 or if the no of students is equal to NumStudents
                                               // then print error message
           System.out.println("The Class is Full");
       }
       else{ // other wise add student to Students list
           Students[index] = stu;
           System.out.println("Student " + stu.name + " is added"); // printing name of the student
           index++; // incrementing no of students present currently in the Students list
       }
   }
   void removeStudent(Student stu){
       if (index==0){ // if there is no students in the list
           System.out.println("There is no students in the class");
       }
       else{
           int found = -1; // declaring variable
           for (int i=0;i<index ;i++ ) { // iterate through each student in list
               if (Students[i].name.equals(stu.name)){//checking student name with the given name if it is equal then assign i value to found.
                   found = i;
                   break; // break the loop
               }
           }
           if (found != -1){
               int i;
               for (i=found; i<index - 1; i++) {
                   Students[i] = Students[i+1]; // from removed student to last student, moving each student back
               }
               System.out.println("Student " + stu.name + " is removed"); // printing removed student name
               Students[i] = null; // assigning null value
               index--; // decrementing no of students present currently in the Students list
           }
           else{ // if the not found in the list with the given name
               System.out.println("There is no student with name " + stu.name + " in the class");
           }
       }
   }
   void displayStudents(){ // displayStudents method
       System.out.println("Studens List :");
       for (int i=0;i<index ;i++ ) { // iterate through each student
           System.out.println(Students[i].name); // printing each student name
       }
   }
}
public class Main{
   public static void main(String[] args) {
       StudentDatabase cls = new StudentDatabase(5); // creating StudentDatabase object
       // adding students to Students list
       cls.addStudent(new Student("A"));
       cls.addStudent(new Student("B"));
       cls.addStudent(new Student("C"));
       cls.addStudent(new Student("D"));
       cls.addStudent(new Student("E"));
       cls.addStudent(new Student("F"));
       cls.displayStudents(); // calling displayStudenst methos
       // calling removeStudent method
       cls.removeStudent(new Student("A"));
       cls.removeStudent(new Student("Z"));
   }
}

If you have any doubts feel free to comment in comment section.

DO VOTE(LIKE).

Add a comment
Know the answer?
Add Answer to:
I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...
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
  • Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src...

    Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src folder, create a package named: edu.ilstu · Import the following files from T:\it168\Labs\lab13. Note that the .txt file must be in the top level of your project, not inside your src folder. o Student.java o StudentList.java o students.txt Carefully examine the Student.java and StudentList.java files. You are going to complete the StudentList class (updating all necessary Javadoc comments), following the instruction in the code....

  • Write a program in Java that prompts a user for Name and id number. and then...

    Write a program in Java that prompts a user for Name and id number. and then the program outputs students GPA MAIN import java.util.StringTokenizer; import javax.swing.JOptionPane; public class Main {    public static void main(String[] args) {                       String thedata = JOptionPane.showInputDialog(null, "Please type in Student Name. ", "Student OOP Program", JOptionPane.INFORMATION_MESSAGE);        String name = thedata;        Student pupil = new Student(name);                   //add code here       ...

  • PLEASE DO IN JAVA 3) Add the following method to College: 1. sort(): moves all students...

    PLEASE DO IN JAVA 3) Add the following method to College: 1. sort(): moves all students to the first positions of the array, and all faculties after that. As an example, let fn indicate faculty n and sn indicate student n. If the array contains s1|f1|f2|s2|s3|f3|s4, after invoking sort the array will contain s1|s2|s3|s4|f1|f2|f3 (this does not have to be done “in place”). Students and faculty are sorted by last name. You can use any number of auxiliary (private) methods, if needed....

  • Java Do 72a, 72b, 72c, 72d. Code & output required. public class Employee { private int...

    Java Do 72a, 72b, 72c, 72d. Code & output required. public class Employee { private int id; private String name; private int sal; public Employee(int id, String name, int sal) { super(); this.id = id; this.name = name; this.sal = sal; } public int getid) { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; public void setName(String name) { this.name = name; } public int get Sall) { return sal;...

  • import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {   ...

    import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {        Student s1 = new Student();         Student s2 = new Student("Smith", "123-45-6789", 3.2);         Student s3 = new Student("Jones", "987-65-4321", 3.7);         System.out.println("The name of student #1 is ");         System.out.println("The social security number of student #1 is " + s1.toString());         System.out.println("Student #2 is " + s2);         System.out.println("the name of student #3 is " + s3.getName());         System.out.println("The social security number...

  • A teacher wants to create a list of students in her class. Using the existing Student...

    A teacher wants to create a list of students in her class. Using the existing Student class in this exercise. Create a static ArrayList called classList that adds a student to the classList whenever a new Student is created. In the constructor, you will have to add that Student to the ArrayList. Coding below was given to edit and use public class ClassListTester { public static void main(String[] args) { //You don't need to change anything here, but feel free...

  • Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h...

    Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h (Given. Just use it, don't change it!) Student.cpp (Partially filled, need to complete) 1. Assignment description In this assignment, you will write a simple class roster management system for ASU CSE100. Step #1: First, you will need to finish the design of class Student. See the following UML diagram for Student class, the relevant header file (class declaration) is given to you as Student.h,...

  • 4. Command pattern //class Stock public class Stock { private String name; private double price; public...

    4. Command pattern //class Stock public class Stock { private String name; private double price; public Product(String name, double price) { this.name = name; this.price = price; } public void buy(int quantity){ System.out.println(“BOUGHT: “ + quantity + “x “ + this); } public void sell(int quantity){ System.out.println(“SOLD: “ + quantity + “x “ + this); } public String toString() { return “Product [name=” + name + “, price=” + price + “]”; } } a. Create two command classes that...

  • java This lab is intended to give you practice creating a class with a constructor method,...

    java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...

  • Java. Java is a new programming language I am learning, and so far I am a...

    Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get...

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