Student class:
Class Roster: This class will implement the functionality of all roster for school.
Grading rubric
constructors
1 single parameter
1 default
-> initializes both Array Lists
-> initalize MAX_NUM
2 boolean containsStudent(String studentName)
//@returns true if studentName is in roster
2 String retrieveById(int id)
//@ returns Student name associated with id
2 int retrieveByName(String Student)
//@returns id associated with String Student
1 boolean addStudent(String studentName, int studentId) ;
//adds student name and id to end of roster
This method should not allow a student to be added if the name or the studentId is already in the roster or allow the total number of students to exceed MAX_NUM. Hint: Make user of the containsStudent() method
//The next 2 methods must maintain the integrity of the parallel ArrayLists. If you remove from 1 then remove the element in the other ArrayList associated with the first list's elements. In other words, if you remove a student based on his or her name, make sure that you also remove his or her id from the other ArrayList.
3 boolean removeStudent(int id)
// removes student from roster based on id
3 boolean removeStudent(String name)
//removes student based on name
Total points 15
Testing data:
Student names: Jack, Jane, Janet, Jasmin
Student IDs: 1005, 1007, 1009, 1011
output
Add: Jessie, 1017
Remove: Jane
output
Remove: 1011
Retrieve ID: 1011
Retrieve student: Jessie
Output
Add Jessie, 1017, output if adding is successful
/******************************************************************************
import java.io.*;
import java.util.*;
class Student{
int id;
String name;
public Student()
{
id=0;
name="";
}
public Student(int id,String name)
{
this.name=name;
this.id=id;
}
public int getID()
{
return id;
}
public String getName()
{
return name;
}
}
class Roster{
int Max_num=10;
ArrayList<Student> arr = new
ArrayList<Student>(10);
public Roster(int num ,ArrayList<Student> s)
{
Max_num=num;
arr=s;
}
//Accessors
public boolean containStudent(String Studentname)
{
for(int i=0;i<Max_num;i++)
{
if(Studentname.equals(arr.get(i).name))
{
return true;
}
}
return false;
}
public String retriveById(int id)
{
for(int i=0;i<Max_num;i++)
{
if((arr.get(i).id==id))
{
return arr.get(i).getName();
}
}
return "0";
}
public int reterivebyname(String name)
{
for(int i=0;i<Max_num;i++)
{
if(name.equals(arr.get(i).name))
{
return arr.get(i).getID();
}
}
return 0;
}
public boolean addStudent(int id, String name)
{
if(containStudent(name))
{
return false;
}
else{
Student ob=new Student(id,name);
arr.add(ob);
Max_num++;
}
return true;
}
public boolean removeStudent(int id)
{
int flag=-1;
for(int i=0;i<Max_num;i++)
{
if((arr.get(i).id==id))
{
flag =i;
break;
}
}
if(flag!=-1)
{
arr.remove(flag);
return true;
}
else{
return false;
}
}
public boolean removeStudent(String name)
{
int flag=-1;
for(int i=0;i<Max_num;i++)
{
if(name.equals(arr.get(i).name))
{
flag =i;
break;
}
}
if(flag!=-1)
{
arr.remove(flag);
return true;
}
else{
return false;
}
}
}
public class Main
{
public static void main(String[] args) {
System.out.println("program
Compiled");
Student ob= new Student(1,"abc");
Student ob2= new Student(2,"ab");
ArrayList<Student> stu=new
ArrayList<Student>(2);
stu.add(ob);
stu.add(ob2);
Roster r= new Roster(3,stu);
int ab=r.reterivebyname("ab");
System.out.println(ab);
}
}
// i used my test data and it is working fine please go through the code.
i add test data of 2 students and check the id of student by name and it is giving correct output
Student class: Instance variables name id Constructors: Default constructor Constructor that has id and name passed...
Given a class called Student and a class called Course that contains an ArrayList of Student. Write a method called getDeansList() as described below. Refer to Student.java below to learn what methods are available. I will paste both of the simple .JAVA codes below COURSE.JAVA import java.util.*; import java.io.*; /****************************************************** * A list of students in a course *****************************************************/ public class Course{ /** collection of Students */ private ArrayList<Student> roster; /***************************************************** Constructor for objects of class Course *****************************************************/...
Write a class called Student. The specification for a Student is: Three Instance fields name - a String of the student's full name totalQuizScore - double numQuizesTaken - int Constructor Default construtor that sets the instance fields to a default value Parameterized constructor that sets the name instance field to a parameter value and set the other instance fields to a default value. Methods setName - sets or changes the student name by taking in a parameter getName - returns...
I need to add a method high school student, I couldn't connect high school student to student please help!!! package chapter.pkg9; import java.util.ArrayList; import java.util.Scanner; public class Main { public static Student student; public static ArrayList<Student> students; public static HighSchoolStudent highStudent; public static void main(String[] args) { int choice; Scanner scanner = new Scanner(System.in); students = new ArrayList<>(); while (true) { displayMenu(); choice = scanner.nextInt(); switch (choice) { case 1: addCollegeStudent(); break; case 2: addHighSchoolStudent(); case 3: deleteStudent(); break; case...
Student is a class that has the following instance variables: name (a String), yearInSchool (an int), and gpa (a double). Write a constructor for the Student class that takes parameters for these instance variables as initial values of the variables. (in Java)
Create a Business class: Instance variables: Student id 1000 - 9999 Student name Present Student email address Present Number of hours 3.5 - 18 Two constructors should be coded, one that accepts no arguments and sets every field to its default value, and one that accepts all four fields, and assigns the passed values into the instance variables. For each instance variable create two methods; a getter and a setter. Add a static method to the class that will accept...
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)...
Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course { /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...
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...
LW: Class Constructors Objectives Write a default constructor for a class. Note that this constructor is used to build the object anytime an argument is not provided when it is defined. Write a parameterized constructor that takes arguments that are used to initialize the class’s member variables Labwork Download the code associated with this lab: ColorConstructor.zip Main.cpp Color.h Color.cpp Compile and run the code. The first line of output of the program should display nonsensical integers for the values of...
We wish to keep track of student advisees. Each advisee consists of a name, student id, concentration, number of hours completed, name of advisor, whether or not they have completed a major sheet for graduation and whether or not they have filed an intent to graduate. An advisor needs the ability to: o update as well as access each advisee’s information o display all student advisees in the system including all information formatted as shown in the example o display...