error in program


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: error in program

  1. #1
    Join Date
    Feb 2006
    Posts
    1

    error in program

    can somebody plz..help me with this error, im really new in java and i need lots of help plsss..

    [code]
    import java.io.*;
    class Students implements Comparable
    {
    private String firstName, lastName;
    private int credits;
    private double gradePointAverage;
    private boolean nullStudent = false;
    // The exception thrown for names without a space
    // separating the first name and last name
    public class NameFormatError extends IOException {}

    public int compareTo(Object other)
    {
    Student otherStudent = (Student)other;
    String name1 = lastName + firstName;
    String name2 = otherStudent.lastName + otherStudent.firstName;
    return name1.compareTo(name2);
    }

    public boolean equals(Comparable other)
    {
    if (!(other instanceof Student))
    return false;
    Student o = (Student)other;
    return name1.equals(o.name1) && name2.equals(o.name2);
    }
    public boolean isNull()
    {
    return nullStudent;
    }
    public void input(BufferedReader reader) throws IOException
    {
    String line = reader.readLine();
    if (line == null)
    {
    nullStudent = true;
    return;
    }
    // indexOf() and substring();
    {

    if (line == null)
    return;
    int space = line.indexOf(' ');
    if (space < 0)
    throw new NameFormatError();

    firstName = (line.substring(0, space));
    int space2 = line.indexOf(' ', space + 1);
    lastName = (line.substring(space + 1, space2));
    space = line.indexOf(' ', space2 + 1);
    credits = Integer.parseInt(line.substring(space2 + 1, space));
    gradePointAverage = Double.parseDouble(line.substring(space + 1));

    {
    System.out.println(firstName + ", " + lastName + " " + credits + " " +
    gradePointAverage);
    }
    }
    }
    }
    [\code]

    the error im getting are:

    lastName has private access in Student
    firstName has private access in Student
    name1 has private access in Student
    name2 has private access in Student
    cannot find symbol varibale name1
    cannot find symboll variable name2

    plz help
    thanks

  2. #2
    Join Date
    Jun 2004
    Posts
    199
    lastName has private access in Student
    firstName has private access in Student

    Use an accessor (get) or change the visiblity to something other than private

    name1 has private access in Student
    name2 has private access in Student
    cannot find symbol varibale name1
    cannot find symboll variable name2

    These are declared locally. If you need to refer to them give them class scope. But what you are doing in the equals is wrong. Do the same sort of thing you are doing in the compare method.

Similar Threads

  1. Help with a program
    By stormswimmer in forum Java
    Replies: 2
    Last Post: 01-02-2006, 04:17 PM
  2. problem in program in c++
    By mheasen in forum Architecture and Design
    Replies: 0
    Last Post: 03-20-2002, 10:24 AM
  3. Please help with running executable vb program.
    By Gordon Reichhardt in forum VB Classic
    Replies: 2
    Last Post: 01-08-2002, 11:06 AM
  4. How can I build copy protection into my program
    By W.Pierce in forum VB Classic
    Replies: 1
    Last Post: 12-11-2001, 09:28 AM
  5. Replies: 0
    Last Post: 12-15-2000, 11:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center