So, it's been a while since I last coded anything, and I have an assignment asking me to edit a student class to overload the constructor to set all test scores to 0, find the average, and print. However! I can't seem to make my driver class work, and I'm not completely sure why that is. I'm sure some of my code in the actual Student class is incorrect, but I'll be able to fix that on my own (hopefully) once I can test it and mess around with the driver itself. Here's what I have so far:
I just need some help with this driver.
Thank you so much!!
public class Address { private String streetAddress, city, state; private long zipCode; //------------------------------------------------------------ // Constructor: Sets up this address with the specified data. //------------------------------------------------------------ public Address (String street, String town, String st, long zip) { streetAddress = street; city = town; state = st; zipCode = zip; } //------------------------------------------------------------ // Returs a description of this Address object. //------------------------------------------------------------ public String toString() { String result; result = streetAddress + "\n"; result += city + ", " + state + " " + zipCode; return result; } }
import java.util.*; public class Student { private String firstName, lastName; private Address homeAddress, schoolAddress; final double defaultScore = 0.0; private int testNo; private double scoreNo, average, temp; private double[] scores; //----------------------------------------------------------- // Constructor: Sets up this student with the specified // values //----------------------------------------------------------- public Student (String first, String last, Address home, Address school) { firstName = first; lastName = last; homeAddress = home; schoolAddress = school; scores = new double[3]; } //---------------------------------------------------------- // Fills array with default test score value of 0. //---------------------------------------------------------- public Student () { for(int i=0; i<scores.length; i++) { scores[i] = defaultScore; } } //---------------------------------------------------------- // Sets new test score value. //---------------------------------------------------------- public double[] setTestScore (int testNo ,double testScoreIn) { scores[testNo] = testScoreIn; return scores; } //---------------------------------------------------------- // Returns test score for appropriate test. //---------------------------------------------------------- public double getTestScore (int testNo) { scores[testNo] = scoreNo; return scoreNo; } //---------------------------------------------------------- // Calculates and returns the average of all of the test // scores for a student. //---------------------------------------------------------- public double average () { for(int i=0; i<scores.length; i++) { scores[testNo] = temp; } temp += average; return average; } //---------------------------------------------------------- // Returns a string description of this Student object. //---------------------------------------------------------- public String toString() { String result; result = firstName + " " + lastName + "\n"; result += "Home Address:\n" + homeAddress + "\n"; result += "School Address:\n" + schoolAddress + "\n"; //result += "Test scores:\n" + double[] scores + "\n"; result += "Test Score Average:\n" + average + "\n"; return result; } }
public class Driver { static Student student1; public static void main(String[] args) { Student student1 = new Student("first", "last", "home", "school"); System.out.println(student1); } }
I just need some help with this driver.
Thank you so much!!