Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have this code in java: public static int addRecord(Scanner input, PrintWriter output, Student[] students) { int id = input.nextInt(); String fname = input.next(); String

I have this code in java:

public static int addRecord(Scanner input, PrintWriter output, Student[] students) {

int id = input.nextInt();

String fname = input.next();

String lname = input.next();

int g1 = input.nextInt();

int g2 = input.nextInt();

int g3 = input.nextInt();

int index = -1;

Student s = new Student(fname, lname, id, g1, g2, g3, (((g2 * (0.3)) + (g3 * (0.4)) + (g1 * (0.3)))));

// save new student into array students[0] = s;

output.println("Command: ADDRECORD");

output.println(fname + " " + lname + " (ID# " + id + ")" + " has been added to the FSC Grade Book");

output.println(" His final grade is " + s.getFinalGrade()); if (Student.getNumStudents() == 0) {

students[0] = s;

return 0; // once we insert a, stop looping

}

for (int y = 0; y < Student.getNumStudents(); y++) { if (id < students[y].getID()) {

index = y; Student.increaseStudents(); System.out.println(Student.getNumStudents()); } }

if (index != -1) {

for (int i = Student.getNumStudents() - 1; i >= index; i--) {

students[i + 1] = students[i];

} Student.increaseStudents(); students[index] = s;

} else { Student.increaseStudents();

index = Student.getNumStudents();

if (index < Student.getNumStudents()) {

students[index] = s;

} else {

System.out.println("ERROR: Adding student not possible, book reached max size");

return -1;

}

}

return index; }

But it wont increase the number of students for some reason? Why and how do i fix this?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions