Results 1 to 11 of 11
  1. #1
    XodoX is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default Help with errors in code

    Hi.

    The following code snippets got some errors in there, Netbeans says. Can somebody tell me what, and why, so that I understand the errors, please?
    So I'll know what I did wrong.


    Database.Java

    The first "private person" gives me an error. Why is that?

    Java Code:
    package Test;
    
    public class Database {
    
        private person[] list;
        private int numberOfRecords;
    
        public Database() {
            
            throw new RuntimeException("Compiled Code");
        }
    
        public void add(String lastName, String firstName, int month, int day, int year) {
            //compiled code
            throw new RuntimeException("Compiled Code");
        }
    
        public int find(String firstName, String lastName, int month, int day, int year) {
            
            throw new RuntimeException("Compiled Code");
        }
    
        public void printList() {
         
            throw new RuntimeException("Compiled Code");
        }
    }
    Date.Java

    gives me an error for exit(1); and return month==theOtherDate.month && day==theOtherDate.day && year==year; ??

    Java Code:
    ackage Test;
    
    import java.language.*;
    
    public class Date
    {
        private int day;
        private int month;
        public int year;
    
        public Date(int m, int d, int y)
        {
            setDay(d);
            setMonth(y);
            setYear(y);
        }
    
        private int getDay()
        {
            return day;
        }
        public int getMonth()
        {
            return month;
        }
        public int getYear()
        {
            return month;
        }
        public void setDay(int d)
        {
            if( d>0 && d<=30) // assume there are 30 days in a month
            {
                day =d;
            }
            else
            {
                System.out.println("Improper user input. Day must be in [1,30]");
                exit(1);
            }
        }
        public void setMonth(int m)
        {
            if( m>=1 && m<=12)
            {
                month =m;
            }
            else
            {
                System.out.println("Improper user input. Month must be in [1,12]");
                System.exit(1);
            }
        }
        public void setYear(int y)
        {
            if( y>1900 && y<2050)
            {
                year =y;
            }
            else
            {
                System.out.println("Improper user input. Year must be in [1901,2049]");
                System.exit(1);
            }
        }
    
        public int equals(Date theOtherDate)
        {
            return month==theOtherDate.month && day==theOtherDate.day && year==year;
        }
        public String toString()
        {
            return month + "/" + day + "/" + year;
        }
    }
    Person.Java

    This gives me an error for the first 3 private strings ( firstname, lastname, birthdate) Any ideas?
    Java Code:
    package assignment2;
    
    class Person {
    
        private string firstName;
        private string lastName;
        private Date birthDate;
    
        public Person(String fN, String lN, int month, int day, int year) {
            //compiled code
            throw new RuntimeException("Compiled Code");
        }
    
        public boolean equals(Person theOtherPerson) {
            //compiled code
            throw new RuntimeException("Compiled Code");
        }
    
        public boolean equal(String fN, String lN, int month, int day, int year) {
            //compiled code
            throw new RuntimeException("Compiled Code");
        }
    
        public String toString() {
            //compiled code
            throw new RuntimeException("Compiled Code");
        }
    }
    I appreciate your help!

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default

    In future copy and paste the EXACT error message.

    Java is case sensitive. You do not have a person class.

    You do not have an exit method. Look closer at the rest of our code where you use the exit method.

    The result of your return statement is a boolean. What is the return type of the method?

  3. #3
    XodoX is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    In future copy and paste the EXACT error message.

    Java is case sensitive. You do not have a person class.

    You do not have an exit method. Look closer at the rest of our code where you use the exit method.

    The result of your return statement is a boolean. What is the return type of the method?

    What do you mean I don't have a person class? Where? You mean rename public class Database { line to public class person ?

    About the return.. do you mean it's supposed to be int instead of boolean?

    And yeah, sorry, but netbeans dosen't say much, so I figured pointing out the lines it ok.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default

    Quote Originally Posted by XodoX View Post
    What do you mean I don't have a person class?
    As I said Java is case sensitive. You create an array of person (private person[] list) but do not have a person class.

    About the return.. do you mean it's supposed to be int instead of boolean?
    I don't know, it is your code, you make the decision but if you say your method will return an int then it must return an int and not a boolean.

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default

    By the way
    Java Code:
    year==year
    is pointless. It will never be false.

  6. #6
    XodoX is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    As I said Java is case sensitive. You create an array of person (private person[] list) but do not have a person class.


    I don't know, it is your code, you make the decision but if you say your method will return an int then it must return an int and not a boolean.


    Ok, so I got the class wrong. Then it's:


    public class person {

    private person[] list;
    private int numberOfRecords;

    public person() {
    I understood what you meant, I was just making sure. You're right, it should be int. What about the other errors? So just add an exit method?


    Thanks! You have been very helpful.
    Last edited by XodoX; 02-08-2011 at 04:54 AM.

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default

    Oh lord help me!

    No, the class name should be Database, that is fine. What is not fine is
    Java Code:
    private person[] list;
    Why, because you do not have a class called person. Oh look you do have a class called Person though. Understand?

  8. #8
    XodoX is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    Oh lord help me!

    No, the class name should be Database, that is fine. What is not fine is
    Java Code:
    private person[] list;
    Why, because you do not have a class called person. Oh look you do have a class called Person though. Understand?
    No. I don't understand what there's to change.

  9. #9
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default

    Do you know what case sensitive is?

    A lowercase letter is not the same as an uppercase letter. Lets hope that sinks in.

  10. #10
    XodoX is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    If you don't want to help, then don't do it. You're being rude. But yes, I got it now.
    Last edited by XodoX; 02-08-2011 at 05:13 AM.

  11. #11
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default

    I am helping or at least trying to help. It is not my fault if you are incapable of understanding. Perhaps you just want to be spoonfed or maybe just trolling.

Similar Threads

  1. nasty errors in your code
    By j2me64 in forum Forum Lobby
    Replies: 0
    Last Post: 01-27-2011, 04:18 PM
  2. Errors in the code (?)
    By AndersBjörnör in forum New To Java
    Replies: 1
    Last Post: 10-09-2009, 03:06 PM
  3. Replies: 3
    Last Post: 03-03-2009, 09:48 PM
  4. HELP ON errors occuring in the code
    By jaiminparikh in forum Advanced Java
    Replies: 6
    Last Post: 02-12-2009, 02:02 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
  •