Results 1 to 7 of 7
  1. #1
    mxrider is offline Member
    Join Date
    Feb 2010
    Posts
    18
    Rep Power
    0

    Default 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)));
    
    	}
    
    
    
    }

  2. #2
    Aseem is offline Senior Member
    Join Date
    Mar 2009
    Location
    USA
    Posts
    127
    Rep Power
    0

    Default

    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)));

    }
    }

  3. #3
    mxrider is offline Member
    Join Date
    Feb 2010
    Posts
    18
    Rep Power
    0

    Default

    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;
    	}
    
    
    
    
    
    }

  4. #4
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    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.

  5. #5
    mxrider is offline Member
    Join Date
    Feb 2010
    Posts
    18
    Rep Power
    0

    Default

    Quote Originally Posted by m00nchile View Post
    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.
    could i have the tutorials? im like really banging my head agains the wall here on what to do

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by mxrider View Post
    could i have the tutorials? im like really banging my head agains the wall here on what to do
    Google "Java tutorials". It's the first hit, the Sun tutorials. Much luck.

  7. #7
    JohnnyR is offline Member
    Join Date
    Feb 2009
    Posts
    46
    Rep Power
    0

    Default

    surely you have a text book of some kind to be working out of - you wouldn't be doing an assignment on java with out it.. or at least been given some resources to learn it.

Similar Threads

  1. Weird msdos problem
    By dudejonne in forum New To Java
    Replies: 6
    Last Post: 11-02-2009, 08:39 PM
  2. Weird path problem when reading properties file
    By jerry_popperq in forum New To Java
    Replies: 0
    Last Post: 03-18-2009, 03:32 PM
  3. Weird problem upon calling same function twice
    By alin_ms in forum New To Java
    Replies: 2
    Last Post: 12-20-2008, 06:14 PM
  4. Replies: 9
    Last Post: 09-30-2008, 07:30 AM
  5. Problem using thread +rmi in my homework
    By IbrahimAbbas in forum Threads and Synchronization
    Replies: 10
    Last Post: 04-14-2008, 09:24 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
  •