Results 1 to 5 of 5
Thread: java program check
- 07-22-2010, 03:31 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 16
- Rep Power
- 0
java program check
Im beginning a java book and am having trouble on one of hte exercises.
The exercise is
and here's my code:1. Create a class named Household that includes data fields for the number of occupants and the annual income, as well as methods named setOccupants ( ), setIncome ( ), getOccupants ( ), and getIncome ( ) that set and return those values, respectively. Also, create a constructor that requires no arguments and automatically set the occupants field to 1 and the income field to 0. Name the program as Household.java.
public class household
{
private int occupants;
private double income;
household house = new household();
public void setOccupants( int newOccupants)
{
occupants = newOccupants;
house.getOccupants();
}
public void setIncome( double income)
{
income = 0;
house.getIncome();
}
public int getOccupants()
{
return occupants;
house.setOccupants(16);
}
public double getIncome(double income)
{
return income;
house.setIncome(157.73);
}
public household()
{
occupants = 1;
income = 0;
}
}
and the problem is this:
buiLd output
general outputC:\Documents and Settings\bLah\My Documents\household.java:20: getIncome(double) in household cannot be applied to ()
house.getIncome();
^
1 error
Process completed.
anyone can heLp me about this? :(java.lang.NoSuchMethodError: main
Exception in thread "main"
Process completed.
- 07-22-2010, 04:05 AM #2
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Im a beginner but as I see your code to getIncome method is
then you call your method like thisJava Code:public double [b]getIncome(double income)[/b] { return income; house.setIncome(157.73); }
Good Luck,Java Code:public void setIncome( double income) { income = 0; [b]house.getIncome();[/b] ...
geje
-
In this simple exercise, your getter method such as getIncome() should not take a parameter. Rather it should simply return the value held by the income field, nothing more.
setIncome on the other hand should take a value, the new income value, and you should use this parameter to set the income field, and do nothing more in that method. For instance:
Java Code:public class SimpleEg { private int myValue; // all this method does is return the value held by the myValue field public int getMyValue() { return myValue; } // all this method does is set the value held by the myValue field public void setMyValue(int myValue) { this.myValue = myValue; } }
-
- 07-22-2010, 04:55 AM #5
Actually mine0926 did raise a correct point; though he didn't state it well, he pointed out the fact that getIncome() was called with no parameters, but the function declaration was set up to accept one parameter.
In any case, Fubarable's post has the right information for you.
Similar Threads
-
perform a check if chat's(edu/test/small program) textarea saved or not
By lse123 in forum AWT / SwingReplies: 10Last Post: 05-01-2010, 09:51 PM -
how to check java
By funkygarzon in forum New To JavaReplies: 10Last Post: 03-08-2009, 08:39 AM -
Please check my java applet
By mark.7100 in forum Java AppletsReplies: 3Last Post: 07-22-2008, 04:33 PM -
CRC check program 1 error
By javakid9000 in forum New To JavaReplies: 1Last Post: 03-19-2008, 05:04 AM -
how to check available resources in java program
By lealea in forum New To JavaReplies: 3Last Post: 08-13-2007, 08:35 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks