Menu

(Solved) : Get Help Rolls Method Print Students Info Don T Know Call Keeps Getting Errors Please Arr Q33161900 . . .

can i get help for my rolls method? It should print out eachstudents info but i don’t know on how to call it. What i have keepsgetting errors. PLEASE, NO ARRAY or anything related. NOthing aboutthe array class, nothing about arrays should be used only use theswitch statement or an if or for i guess. Image as if arrays havenever been taught PLS, NOTHING ABOUT ARRAYS.

—–BOLDED is what needs help————–Thanks!!!!!!!!———–

class Course {

private String name, rollString;

private Student studentOne, studentTwo, studentThree,studentFour, studentFive;

private int studentCount;

private double classAvg;

public Course(String name) {

this.name = name;

}

public Student addStudent(Student newStu) {

if (studentOne == null) {

studentOne = newStu;

studentCount = 1;

}

else if (studentTwo == null) {

studentTwo = newStu;

studentCount = 2;

}

else if (studentThree == null) {

studentThree = newStu;

studentCount = 3;

}

else if (studentFour == null) {

studentFour = newStu;

studentCount = 4;

}

else if (studentFive == null) {

studentFive = newStu;

studentCount = 5;

}

return newStu;

}

public double getAverageCScore() {

switch (studentCount) {

case 1:

classAvg = studentOne.Average();

break;

case 2:

classAvg = (studentOne.Average() + studentTwo.Average()) /2.0d;

break;

case 3:

classAvg = (studentOne.Average() + studentTwo.Average() +studentThree.Average()) / 3.0d;

break;

case 4:

classAvg = (studentOne.Average() + studentTwo.Average() +studentThree.Average() + studentFour.Average()) / 4.0d;

break;

case 5:

classAvg = (studentOne.Average() + studentTwo.Average() +studentThree.Average() + studentFour.Average() +studentFive.Average()) / 5.0d;

break;

}

return classAvg;

}

public String roll() {

System.out.println(“Course: ” + name);

System.out.println(“Students: “);

switch (studentCount) {

case 1:

rollString =”Student in class: n” +studentOne.toString() + “n”;

System.out.println(rollString);

break;

case 2:

rollString = “Student in class: n” +studentOne.toString() + “n” +studentTwo.toString()”n”;

System.out.println(rollString);

break;

case 3:

rollString = “Student in class: n” +studentOne.toString() + “n” + studentTwo.toString()”n” +studentThree.toString()+ “n”;

System.out.println(rollString);

break;

case 4:

rollString = “Student in class: n” +studentOne.toString() + “n” + studentTwo.toString()”n” +studentThree.toString()+ “n” +studentFour.toString() +”n”;

System.out.println(rollString);

break;

case 5:

rollString =”Student in class: n” +studentOne.toString() + “n” + studentTwo.toString()”n” +studentThree.toString()+ “n” +studentFour.toString() + “n”+studentFive.toString() + “n”;

System.out.println(rollString);

break;

}

return rollString;

}

class Address {

private String streetAddress, city, state;

private long zipCode;

public Address(String street, String town, String st, longzip)

{

streetAddress = street;

city = town;

state = st;

zipCode = zip;

}

public String toString()

{

String result;

result = streetAddress + “n”;

result += city + “,” + state + ” ” + zipCode;

return result;

}

}

class Student

{

private String firstName, lastName;

private Address homeAddress, schoolAddress;

private int t1 = 0;

private int t2 = 0;

private int t3 = 0;

public Student(String first, String last, Address home, Addressschool, int test1, int test2, int test3)

{

firstName = first;

lastName = last;

homeAddress = home;

schoolAddress = school;

t1 = test1;

t2 = test2;

t3 = test3;

}

public String toString()

{

String result;

result = firstName + ” ” + lastName + “n”;

result += “Home Address:n” + schoolAddress + “n”;

result += “School Address:n” + schoolAddress + “n”;

result += “Test 1 score: ” + t1 + “n”;

result += “Test 2 score: ” + t2 + “n”;

result += “Test 3 score: ” + t3 + “n”;

return result;

}

// can call on this for specific average for each student

public double Average() {

return (t1 + t2 + t3)/3.0;

}

}

public class Studentready

{

public static void main(String[] args)

{

Address school = new Address(“800 Lancaster Ave.”, “Villanova”,”PA”, 19085);

Address jHome = new Address(“21 Jump Street”, “Blacksburg”,”VA”, 24551);

Student john = new Student(“John”, “Smith”, jHome, school, 70,65, 85);

Address mHome = new Address(“123 Main Street”, “Euclid”, “OH”,44132);

Student marsha = new Student(“Marsha”, “Jones”, mHome, school,90, 91, 95);

Address eHome = new Address(“123 Main Street”, “Euclid”, “OH”,44126);

Student emily = new Student(“Emily”, “red”, mHome, school, 60,56, 0);

Course CS = new Course(“Computer Science”);

CS.addStudent(john);

CS.addStudent(marsha);

Course cpp = new Course(“cpp”);

cpp.addStudent(emily);

System.out.println(“The following student are related tothe course computer Scerience”);

CS.roll();

System.out.println(“The following student are related to thecourse cpp”);

cpp.roll();

System.out.println(“The Average for CS is :” +c.getAverageCScore());

}

}

Expert Answer


Answer to Get Help Rolls Method Print Students Info Don T Know Call Keeps Getting Errors Please Arr Q33161900 . . .

OR