Results 1 to 7 of 7
- 02-19-2010, 03:03 AM #1
Member
- Join Date
- Feb 2010
- Posts
- 18
- Rep Power
- 0
Weird problem with my homework, statements out of order?
For my homework i need the statements to be in this order like this

but my code makes it come up like this??

Can someone point me out how to order it?
Heres the 2 pages of code, thanks!
Java Code:public class TestHousehold { public static void main(String[] args) { Household occupants = new Household(); occupants.methodThatUsesInstanceVariables(); } }Java Code:import java.text.DecimalFormat; public class Household { private int occ; private double income; DecimalFormat money = new DecimalFormat("0.00"); Household() { occ = 1; income = 0.00; System.out.println("The house before the set methods has "+ occ + " occupants and an income of $" + (money.format(income))); } public void methodThatUsesInstanceVariables() { int occ = 3; double income = 55000; System.out.print("The revised house has " + occ); System.out.println(" occupants and an income of $" + (money.format(income))); } { int occ = 2; System.out.print("The second house has " + occ); System.out.println(" occupants and an income of $" + (money.format(income))); } { int occ = 7; double income = 80000; System.out.print("The third house has " + occ); System.out.println(" occupants and an income of $" + (money.format(income))); } }
- 02-19-2010, 04:54 AM #2
Senior Member
- Join Date
- Mar 2009
- Location
- USA
- Posts
- 127
- Rep Power
- 0
is this wat u mean:
import java.text.DecimalFormat;
public class Household
{
private int occ,occ1,occ3,occ4;
private double income,income1,income2;
DecimalFormat money = new DecimalFormat("0.00");
Household() {
occ = 1;
occ1 =2;
occ3=7;
occ4=3;
income = 0.00;
income1=55000.00;
income2 =80000.00;
System.out.println("The house before the set methods has "+ occ + " occupants and an income of $" + (money.format(income)));
}
public void methodThatUsesInstanceVariables(){
System.out.print("The revised house has " + occ4);
System.out.println(" occupants and an income of $" + (money.format(income1)));
System.out.print("The second house has " + occ1);
System.out.println(" occupants and an income of $" + (money.format(income)));
System.out.print("The third house has " + occ3);
System.out.println(" occupants and an income of $" + (money.format(income2)));
}
}
- 02-19-2010, 06:24 AM #3
Member
- Join Date
- Feb 2010
- Posts
- 18
- Rep Power
- 0
I actually emailed my teacher and found out that i did the whole thing wrong and i dont know how to correct it
this is the problem
A create a class named Household that includes data fields for the number of occupants and the annual income, as well as get and set methods for each field. in addition, create a default constructor that automatically sets the occupants fields to 1 and income fields to 0. save this file as Household.java. Create an application named TestHousehold that demostrates each method works correctly. Save the file as TestHousehold.java
B Create an additional overload constructor for the Household class you created in excersive 3a. this constructor recieves an integer parameter and assings the value to the occupants field. Add any needed statments to the testhousehold to ensure that the overload constructor works correctly, save it and then test it.
C create a third overloaded constructor for the household class you created in excercises 3a and 3b. this constructor recieves two parameters, the values of which are assigned to the occipants and income fields, respectively. Alter the TestHousehold application to demostrate that each verson of the constructor works properly. save the application and then complie and test it.
this is the code i have and idk where to go from this
Java Code:public class TestHousehold { public static void main(String[] args) { Student house = new student(); System.out.println("The house before the set methods has " + house.getoccupants()+ "occupants and an income of $" + house.getincome() ); System.out.println("The revised house has " + house.getoccupants() + "occupants and an income of $" + house.getincome()); System.out.println("The second house has " + house.getoccupants() + "occupants and an income of $" + house.getincome()); System.out.println("The third house has " + house.getoccupants() + "occupants and an income of $" + house.getincome()); } }Java Code:import java.text.DecimalFormat; public class Household { private String occupants; private double income; DecimalFormat money = new DecimalFormat("0.00"); Household() { occupants = "1"; } public void setoccupants(String occ) { occupants = occ; } public void setincome(double inc) { income = inc; } public String getoccupants() { return occupants; } public double getincome() { return income; } }
- 02-19-2010, 06:46 AM #4
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
Ok, the assignment description tells you exactely what to do. If you are unsure about how to proceed, I would reccomend you read a few tutorials, as I doubt anyone will just post the code.
- 02-19-2010, 04:05 PM #5
Member
- Join Date
- Feb 2010
- Posts
- 18
- Rep Power
- 0
-
- 02-20-2010, 03:27 AM #7
Member
- Join Date
- Feb 2009
- Posts
- 46
- Rep Power
- 0
Similar Threads
-
Weird msdos problem
By dudejonne in forum New To JavaReplies: 6Last Post: 11-02-2009, 08:39 PM -
Weird path problem when reading properties file
By jerry_popperq in forum New To JavaReplies: 0Last Post: 03-18-2009, 03:32 PM -
Weird problem upon calling same function twice
By alin_ms in forum New To JavaReplies: 2Last Post: 12-20-2008, 06:14 PM -
Weird problem: Terms and Conditions keep showing up, can't use Java at all
By Czar of Fishies in forum New To JavaReplies: 9Last Post: 09-30-2008, 07:30 AM -
Problem using thread +rmi in my homework
By IbrahimAbbas in forum Threads and SynchronizationReplies: 10Last Post: 04-14-2008, 09:24 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks