Hi... I will post my code and errors... I have tried fixing them and then something else is wrong... There are four parts as we are working on arrays...Thank you
Errors: ----jGRASP exec: javac -g StudentBody2.java StudentBody2.java:12: error: cannot find symbol Scanner sc = new Scanner(System.in); ^ symbol: class Scanner location: class StudentBody2 StudentBody2.java:12: error: cannot find symbol Scanner sc = new Scanner(System.in); ^ symbol: class Scanner location: class StudentBody2 StudentBody2.java:54: error: no suitable constructor found for Student(String,String,Address,Address,Course[]) Student s = new Student(fname,lname,jHome,school,carray); ^ constructor Student.Student(String,String,Address,Address,int,int,int) is not applicable (actual and formal argument lists differ in length) constructor Student.Student(String,String,Address,Address) is not applicable (actual and formal argument lists differ in length) StudentBody2.java:69: error: firstName has private access in Student System.out.println(index+"\t"+student.firstName+""+student.lastName); ^ StudentBody2.java:69: error: lastName has private access in Student System.out.println(index+"\t"+student.firstName+""+student.lastName); ^ 5 errors
class Address2 { private String streetAddress, city, state; private long zipCode; // Constructor: Sets up this address with the specified data public Address2 (String street, String town, String st, long zip) { streetAddress = street; city = town; state = st; zipCode = zip; } // Returns a desciption of this address object public String toString() { String result; result = streetAddress + " \n"; result += city + ", " + state + " " + zipCode; return result; } }
// Constructor: Sets up this student with the specified values public Student2 (String first, String last, Address home, Address school,Course[] schedule) { firstName = first; lastName = last; homeAddress = home; schoolAddress = school; this.schedule = schedule; } // Returs 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+="Course Details : \n"; String temp = ""; for(Course c : schedule) { temp+="Term : "+c.term+" Course Number : "+c.courseNumber+" Location : "+c.location+" Instructor Name :"+c.instructor; temp+="\n"; } result+=temp;
public class StudentBody2 { // Creates some Address and Student objects and prints them public static void main (String[] args) { Address school = new Address("800 Lancaster Ave." , "Villanova","PA" , 19085); Address jHome = new Address("21 Jump Street", "Lynchburg","VA", 24551); Scanner sc = new Scanner(System.in); System.out.print("Enter how many Students ? "); int size = sc.nextInt(); Student array[] = new Student[size]; int i = 0, j = 0; while(i < array.length) { System.out.println(); System.out.println("Enter "+(i+1)+" Student details"); System.out.print("Enter Student First name : "); String fname = sc.next(); System.out.print("Enter Student Last name : "); String lname = sc.next(); // adding up to 6 courses to student using random int random = 1 + (int)(Math.random() * 6); Course carray[] = new Course[random]; System.out.println(); System.out.println("Enter "+random+" courses"); while(j < carray.length) { System.out.println(); System.out.print("Enter Course Term name : "); String team = sc.next(); System.out.print("Enter course Number : "); String courseNo = sc.next(); System.out.print("Enter Location name : "); String location = sc.next(); System.out.print("Enter instructor First name : "); String insFname = sc.next(); System.out.print("Enter instructor Last name : "); String insLname = sc.next(); String instructorName = insLname+","+insFname; Course c = new Course(team,courseNo,location,instructorName); carray[j] = c; j++; } Student s = new Student(fname,lname,jHome,school,carray); array[i] = s; System.out.println(); System.out.println("Student Details : "+s); i++; j = 0; } System.out.println("Total Number of Students : "+array.length); System.out.println("Total Number of Courses : "+Course.count); System.out.println("INDEX"+"\t"+"Student Name"); int index = 0; for(Student student : array) { System.out.println(index+"\t"+student.firstName+""+student.lastName); index++; } } }
class Course { static int count; String term,courseNumber,location,instructor; public Course(String term, String courseNumber, String location, String instructor) { this.term = term; this.courseNumber = courseNumber; this.location = location; setInstructor(instructor); count++; } public String getCourseNumber() { return courseNumber; } public void setCourseNumber(String courseNumber) { this.courseNumber = courseNumber; } public String getInstructor() { return instructor; } public void setInstructor(String instructor) { this.instructor = instructor; } public String getLocation() { return location; } public void setLocation(String location) { this.location = location; } public String getTerm() { return term; } public void setTerm(String term) { this.term = term; } public String toString() { return term+"\t"+courseNumber+"\t"+location+"\t"+instructor; } }