Results 1 to 11 of 11
Thread: Help with errors in code
- 02-08-2011, 04:25 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 5
- Rep Power
- 0
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?
Date.JavaJava 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"); } }
gives me an error for exit(1); and return month==theOtherDate.month && day==theOtherDate.day && year==year; ??
Person.JavaJava 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; } }
This gives me an error for the first 3 private strings ( firstname, lastname, birthdate) Any ideas?
I appreciate your help!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"); } }
- 02-08-2011, 04:31 AM #2
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?
- 02-08-2011, 04:36 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 5
- Rep Power
- 0
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.
- 02-08-2011, 04:42 AM #4
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.About the return.. do you mean it's supposed to be int instead of boolean?
- 02-08-2011, 04:43 AM #5
By the way
is pointless. It will never be false.Java Code:year==year
- 02-08-2011, 04:52 AM #6
Member
- Join Date
- Feb 2011
- Posts
- 5
- Rep Power
- 0
Ok, so I got the class wrong. Then it's:
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?
public class person {
private person[] list;
private int numberOfRecords;
public person() {
Thanks! You have been very helpful.Last edited by XodoX; 02-08-2011 at 04:54 AM.
- 02-08-2011, 04:56 AM #7
Oh lord help me!
No, the class name should be Database, that is fine. What is not fine is
Why, because you do not have a class called person. Oh look you do have a class called Person though. Understand?Java Code:private person[] list;
- 02-08-2011, 05:01 AM #8
Member
- Join Date
- Feb 2011
- Posts
- 5
- Rep Power
- 0
- 02-08-2011, 05:03 AM #9
Do you know what case sensitive is?
A lowercase letter is not the same as an uppercase letter. Lets hope that sinks in.
- 02-08-2011, 05:10 AM #10
Member
- Join Date
- Feb 2011
- Posts
- 5
- Rep Power
- 0
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.
- 02-08-2011, 05:14 AM #11
Similar Threads
-
nasty errors in your code
By j2me64 in forum Forum LobbyReplies: 0Last Post: 01-27-2011, 04:18 PM -
Errors in the code (?)
By AndersBjörnör in forum New To JavaReplies: 1Last Post: 10-09-2009, 03:06 PM -
hi,can anyone help with the following code,i could not complie because its got errors
By omutaoka in forum New To JavaReplies: 3Last Post: 03-03-2009, 09:48 PM -
HELP ON errors occuring in the code
By jaiminparikh in forum Advanced JavaReplies: 6Last Post: 02-12-2009, 02:02 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks