Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: I have recieved 5 errors... I dont know what they mean...

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default I have recieved 5 errors... I dont know what they mean...

    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;
     }
     
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: I have recieved 5 errors... I dont know what they mean...

    Your first 2 errors appear to indicate that you did not import the Scanner class. The rest are related to inconsistencies in your code, like:

    It's not clear how the 4 parts you posted go together. Are they each stand-alone parts, saved in their own files? If so, there are missing braces, { or }. If not, describe how the parts fit together.

    The second bit of code you posted makes no sense. It begins with a constructor, Student2(), but there's no class Student2.

    Help us understand what's going on here.

Similar Threads

  1. Replies: 7
    Last Post: May 8th, 2014, 12:51 PM
  2. i dont know where the problem is...help me here
    By Shoes Mosh in forum What's Wrong With My Code?
    Replies: 6
    Last Post: May 6th, 2014, 11:27 PM
  3. a HUGE list of errors, and i dont know why.
    By MR bruto in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 10th, 2013, 07:10 AM
  4. Replies: 3
    Last Post: March 6th, 2012, 03:50 AM
  5. I dont get it....please help
    By DestinyChick1225 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: June 30th, 2010, 03:16 AM

Tags for this Thread