Question

In: Computer Science

In this exercise, you will create a basic data management system for students in the Department...

In this exercise, you will create a basic data management system for students in the Department of Computer Science and Information Technology using the linked list.

You must write two classes – Student class attached, and StudentChart.

Student class consists of student data. StudentChart class contains a linked list of all students in the department.

For this purpose, you must fulfill the following interfaces (note - fields of the objects should be marked as private).

Class: Student chart

Class of Student Chart contains data for all students stored in a linked list. The way to add a student to the list by method addStudent only to the front of the list. At the beginning the student list is empty, the number of students enrolled in the Department is 0. Think what would be the fields of this class, so that you can know much information at any one time.

Constructors:

Creat the class chart according to the private

StudentChart()

.fields(variables).

Methods:

Return type

Method name and parameters

operation

Add student to the front of the linked list.

void

addStudent(Student student

Delete student from the list. Do nothing if the student does not exist in the list. Returns false if student not found in the list

boolean

deleteStudent(Student student)

int

getNumOfStudents()

Returns the number of students in the list.

boolean

isStudent(Student student)

Examine if student exists in the list.

Student

getStudent(int studentNum)

Returns students data for the students with studentNum.

Returns the student average in the course with number

double

getAverage(int course)

course

Returns student average in all courses for all students.

double

getAverage()

(You can use the Student class methods).

Prints the students data for all students as follow:

Student number 1:

<Student String representation> Student number 2:

<Student String representation>

Student number <n>:

<Student String representation> If there are no students print:

void

printStudentChart()

No students!

It is recommended to write tester to present all the methods of the class and to check that they actually work.

The student class :

public class Student {
   private String name;// student name
   private long id; // student identity number
   private int [] grades = new int[5]; // list of student courses grades
   
   //costructor that initialize name and id
   public Student(String name, long id){
       String n = name.toUpperCase();
       name = name.replace(name.charAt(0), n.charAt(0));
       for(int i=0 ; i<name. length(); i++)
           if(name.charAt(i)==' ')
               name = name.replace(name.charAt(i+1), n.charAt(i+1));
       this.name = name;
       this.id=id;
       
   }
   
   //copy constructor
   public Student(Student st){
       this.name= st.name;
       this.id = st.id;
   }
   
   //return the student name
   public String getName(){
       return name;
   }
   //returns the student id number
   public long getId(){
       return id;
   }
   
   // returns the course grade accoring to parameter course(course number) 
   public int getGrade(int course){
       if(grades[course]== 0)
           return -1;
       return grades[course];
       
   }
   // set the name of student with parameter name
   public void setName(String name){
       String n = name.toUpperCase();
       name = name.replace(name.charAt(0), n.charAt(0));
       for(int i=0 ; i<name. length(); i++)
           if(name.charAt(i)==' ')
               name = name.replace(name.charAt(i+1), n.charAt(i+1));
       this.name = name;
       
   }
   
   //sets the student id with parameter id
   public void setId(long id){
       this.id = id;
   }
   //set the course grade with parameter grade 
   public void setGrade(int course, int grade){
       grades[course]= grade;
   }
    // set all the grades of the student from user
   public void setGrades(int [] g){
       for(int i=0; i< grades.length; i++)
           grades[i]=g[i];
            
   }
   //returns the student average in his course
   public double getAverage(){
       int sum= 0;
       int count =0;
       for(int i=0; i< grades.length; i++){
           if(grades[i]!=-1)
          sum=+ grades[i];
           count++;
       }
       return sum/count*1.0;// compute and return average
       
   }
   
   // takes a student object as a parameter and 
   // return true if it is the same as student parameter
   public boolean equals(Student student){
       if(student.id== this.id)
           return true;
       else
           return false;
   }
   //returns a string that represents the student object
   public String toString(){
       
       String [] g = new String[5];
       for(int i=0; i< grades.length; i++)
           if(grades[i]!= -1)
               g[i]= grades[i]+" ";
               else
               g[i]="no grade";
              
       String n1= "Name:"+ name+"\n"+ "ID:  "+ id +"\n"+ "Grades:"+"\n"+
               "Introduction to Programming - "+g[0] +"\n"+"Introduction to Management – "+g[1]+"\n"+
               "Data Structures – "+g[2]+"\n"+"Introduction to Economics – "+g[3]+"\n"+
               "Introduction to Mathematics – "+g[4];
       
       return n1;               
   }
    
}

Solutions

Expert Solution

please find the solution for the same:-

package studentdata;

import java.util.LinkedList;

public class StudentChat {
   LinkedList<Student> list = new LinkedList<Student>();;

   public static void main(String[] args) {
       StudentChat studentChat = new StudentChat();
       studentChat.printStudentChart();
       // Adding student 1
       Student student = new Student("Rohan", 1);
       student.setGrade(0, 9);
       student.setGrade(1, 9);
       student.setGrade(2, 8);
       student.setGrade(3, 6);
       student.setGrade(4, 7);
       studentChat.addStudent(student);
       Student student2 = new Student("Raj", 2);
       student2.setGrade(0, 9);
       student2.setGrade(1, 9);
       student2.setGrade(2, 8);
       student2.setGrade(3, 6);
       student2.setGrade(4, 7);
       studentChat.addStudent(student2);
       System.out.println("Total Number of students created: " + studentChat.getNumOfSudents());
       studentChat.printStudentChart();
       System.out.println("####################");
       //getaverage
       double average=student.getAverage();
       System.out.println("total Average for student "+student.getId()+" :-"+average);
       System.out.println("####################");
       double averagecourse=student.getAverage(3);
       System.out.println("total Average for student "+student.getId()+" :-"+averagecourse);
       System.out.println("####################");
       //is valid student
       boolean isValidStudent=studentChat.isStudent(student2);
       System.out.println("Student exists:-"+isValidStudent);
       System.out.println("####################");
       // get the student
       Student stut = studentChat.getStudent(2);
       System.out.println(stut.toString());
       System.out.println("####################");
       // delete
       studentChat.deleteStudent(student2);
       studentChat.printStudentChart();
       System.out.println("####################");


   }

   public void addStudent(Student student) {
       list.addFirst(student);
   }

   public boolean deleteStudent(Student student) {
       return list.remove(student);
   }

   public int getNumOfSudents() {
       return list.size();
   }

   public boolean isStudent(Student student) {
       return list.contains(student);
   }

   public Student getStudent(int studentNum) {
       for (int i = 0; i < list.size(); i++) {
           if (list.get(i).getId() == studentNum) {
               return list.get(i);

           }
       }
       return null;
   }

   public void printStudentChart() {
       int count = list.size();
       if (count > 0) {
           for (int i = 0; i < list.size(); i++) {
               System.out.println("Student number " + list.get(i).getId());
               System.out.println(list.get(i).toString());
           }
       } else {
           System.out.println("No Students");
       }
   }

}

package studentdata;

public class Student {
   private String name;// student name
   private long id; // student identity number
   private int[] grades = new int[5]; // list of student courses grades

   // costructor that initialize name and id
   public Student(String name, long id) {
       String n = name.toUpperCase();
       name = name.replace(name.charAt(0), n.charAt(0));
       for (int i = 0; i < name.length(); i++)
           if (name.charAt(i) == ' ')
               name = name.replace(name.charAt(i + 1), n.charAt(i + 1));
       this.name = name;
       this.id = id;

   }

   // copy constructor
   public Student(Student st) {
       this.name = st.name;
       this.id = st.id;
   }

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

   // returns the student id number
   public long getId() {
       return id;
   }

   // returns the course grade accoring to parameter course(course number)
   public int getGrade(int course) {
       if (grades[course] == 0)
           return -1;
       return grades[course];

   }

   // set the name of student with parameter name
   public void setName(String name) {
       String n = name.toUpperCase();
       name = name.replace(name.charAt(0), n.charAt(0));
       for (int i = 0; i < name.length(); i++)
           if (name.charAt(i) == ' ')
               name = name.replace(name.charAt(i + 1), n.charAt(i + 1));
       this.name = name;

   }

   // sets the student id with parameter id
   public void setId(long id) {
       this.id = id;
   }

   // set the course grade with parameter grade
   public void setGrade(int course, int grade) {
       grades[course] = grade;
   }

   // set all the grades of the student from user
   public void setGrades(int[] g) {
       for (int i = 0; i < grades.length; i++)
           grades[i] = g[i];

   }
  
   public double getAverage(int course) {
       return grades[course]*1.0;
   }

   // returns the student average in his course
   public double getAverage() {
       double sum = 0.0;
       int count = 0;
       for (int i = 0; i < grades.length; i++) {
           if (grades[i] != -1)
               sum +=grades[i];
           count++;
       }
       return sum / count;

   }

   // takes a student object as a parameter and
   // return true if it is the same as student parameter
   public boolean equals(Student student) {
       if (student.id == this.id)
           return true;
       else
           return false;
   }

   // returns a string that represents the student object
   public String toString() {

       String[] g = new String[5];
       for (int i = 0; i < grades.length; i++)
           if (grades[i] != -1)
               g[i] = grades[i] + " ";
           else
               g[i] = "no grade";

       String n1 = "Name:" + name + "\n" + "ID: " + id + "\n" + "Grades:" + "\n" + "Introduction to Programming - "
               + g[0] + "\n" + "Introduction to Management – " + g[1] + "\n" + "Data Structures – " + g[2] + "\n"
               + "Introduction to Economics – " + g[3] + "\n" + "Introduction to Mathematics – " + g[4];

       return n1;
   }

}


Related Solutions

Create a scenario on University management system that provides services to students and professors alike. and...
Create a scenario on University management system that provides services to students and professors alike. and prepare use case diagrams, sequence diagrams, activity diagram(s), and class diagrams for the system developing.
In c# I need to create a simple payroll management system using visual basic and GUI....
In c# I need to create a simple payroll management system using visual basic and GUI. I also need to connect to SQL database. It needs a log in screen, inside the login screen it needs another screen to enter or edit employee information. It needs somewhere to enter hours worked for that specific employee, and another screen that can access reports.
Database - Data Control Language    Exercise Write few system and object privileges. Create user with...
Database - Data Control Language    Exercise Write few system and object privileges. Create user with your name and grant above discussed system and object privileges to the user created. Revoke update and select from the user which you have created.
You are required to create a sales and marketing management system with a small number of...
You are required to create a sales and marketing management system with a small number of common sense attributes. The system should contain the following information Sales details Marketing details Customer details Production details Delivery details Management details So consider what sales and marketing system is required to deliver a consistent and customer oriented service to all customers over the world. You need to identify the tables you require and the information that they are to contain. This is only...
You are required to create a sales and marketing management system with a small number of...
You are required to create a sales and marketing management system with a small number of common sense attributes. The system should contain the following information  Sales details  Marketing details  Customer details  Production details  Delivery details  Management details So consider what sales and marketing system is required to deliver a consistent and customer oriented service to all customers over the world. You need to identify the tables you require and the information that they...
Create a presentation of an ideal performance management system (PMS) that you would implement as the...
Create a presentation of an ideal performance management system (PMS) that you would implement as the human resources (HR) manager of an organization (fictional or real). Be sure to include information that addresses the following aspects of your PMS: Organizational Strategy including description of the organization’s purpose, vision, mission Systems including defining and measuring results, appraisals, compensation Implementation Factors including communication plan, appeal process Employee Development Considerations Each of the above areas and their subcategories must be addressed. Assume you...
A general-purpose database management system (DBMS) has 5 basic responsibilities: Interaction with the file management system...
A general-purpose database management system (DBMS) has 5 basic responsibilities: Interaction with the file management system Integrity enforcement Security enforcement Backup and Recovery Concurrency control For each responsibility, explain the problems that would arise if the DBMS did not execute these responsibilities. Be descriptive and give examples where appropriate.
Use Visual Basic Language In this assignment,you will create the following data file in Notepad: 25...
Use Visual Basic Language In this assignment,you will create the following data file in Notepad: 25 5 1 7 10 21 34 67 29 30 You will call it assignment4.dat and save it in c:\data\lastname\assignment4\. Where lastname is your last name. The assignment will be a console application that will prompt the user for a number. Ex. Console.Write(“Enter a number: ”) And then read in the number Ex. Number = Console.ReadLine() You will then read the data file using a...
Create a description of a university course registration system. You should include features for students, faculty,...
Create a description of a university course registration system. You should include features for students, faculty, and administrators. For example, students need to use the system to add and drop courses that they attend, faculty needs to add and drop courses that they offer and the Registrar needs to allocate and de-allocate resources for courses that are added or dropped. Each type of user also has to satisfy some constraints, such as how many courses they take (students), teach (faculty)...
An employment agency needs to convert its basic one-table management system into a modern information management...
An employment agency needs to convert its basic one-table management system into a modern information management system/database that can hold its improving business. You are hired to create this IMS and the first step you are carrying out is normalization. The table that the agency originally uses is the following: APPLICATION(ApplicantName, AppicantPhone1, ApplicantPhone2, ApplicantAddress, ApplicantFieldOfInterest, ApplicanHighestLevelOfEducation, EmployerBusinessName, EmployerAddress, EmployerPhoneNumber, EmployerCity, EmployerEmail, JobPostingID, JobPostingTitle, JobYearlySalary, InterviewId, InterviewDate, NamesOfInterviewers, OfferDetailsIfApplicable) Rules: - Applicants can be identified by their phone number(s) - No...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT