The code below is the file for the constructor method and the get methods

//Date: 3/18/2010

public class Taxpayer 
{
	private int socSec;
	private double yearlyGross;
	
	public Taxpayer(int taxPayer, double income) 
	{
		socSec = taxPayer;
		yearlyGross = income;
	}
	public int getSocSec()
	{
		return socSec;
	}
	public double getYearlyGross()
	{
		return yearlyGross;
	}

}

Next is the code for the for loop printing of the constructor and get method in another file

//Date: 3/18/2010

public class UseTaxpayer 
{
	public static void main(String[] args) 
	{
	Taxpayer[] somePayer = new Taxpayer[10];
	int x;
		
	for (x = 0; x < 10; ++x)
	{
	somePayer[x] = new Taxpayer(999999999, 0.0);
	System.out.println("Social Security #: " + somePayer[x].getSocSec() + ", and yearly gross income: $" + somePayer[x].getYearlyGross());
		}
	}

}

As you can see if you run it, it prints out to
Social Security #: 999999999, and yearly gross income: $0.0
Social Security #: 999999999, and yearly gross income: $0.0
Social Security #: 999999999, and yearly gross income: $0.0
Social Security #: 999999999, and yearly gross income: $0.0
Social Security #: 999999999, and yearly gross income: $0.0
Social Security #: 999999999, and yearly gross income: $0.0
Social Security #: 999999999, and yearly gross income: $0.0
Social Security #: 999999999, and yearly gross income: $0.0
Social Security #: 999999999, and yearly gross income: $0.0
Social Security #: 999999999, and yearly gross income: $0.0

which is what I want it to do, my problem is taking it and manipulating it to read
Social Security #: 111111111, and yearly gross income: $10000.0
Social Security #: 222222222, and yearly gross income: $20000.0
Social Security #: 333333333, and yearly gross income: $30000.0
Social Security #: 444444444, and yearly gross income: $40000.0
Social Security #: 555555555, and yearly gross income: $50000.0
Social Security #: 666666666, and yearly gross income: $60000.0

all the way up to 999999999 and income of $100,000.
I spent 2 hours trying to do it with what I learned from the book and I can't figure it out. Someone help?

You are entering a taxpayer with the same parameters within your for loop. Depending on what parameters you start with you are going to need to increment or decrement, for your current example it you would need 2 variables. One would increment by 10,000 each time and you would add it to your income parameter each loop. For the taxpayer, you could set a variable equal to 111111111 and then increment it times 2 upon each loop.

So a general overview of what i just tried to say. create 2 variables that will be your paremeters for new taxPayer and then increment/decrement as needed for it to match the criteria you want it to output in the end.

That explanation may not be the best, but maybe it can atleast give you an idea.

thank you sooo much. That's all I needed to do, duh, haha. That was so easy. I like this website, very helpful people. :-)

Quick question: I was able to do everything that I wanted done, but now my only question is, how do I do the whole for loop, but change just ONE of them...as you see below, all social security numbers go from 1 to 9 but the 10th one does 111....0 which is 1 too many for a social security number, how do I change just the 10th one to say: 101010101????

Social Security #: 111111111, and yearly gross income: $10,000.00
Social Security #: 222222222, and yearly gross income: $20,000.00
Social Security #: 333333333, and yearly gross income: $30,000.00
Social Security #: 444444444, and yearly gross income: $40,000.00
Social Security #: 555555555, and yearly gross income: $50,000.00
Social Security #: 666666666, and yearly gross income: $60,000.00
Social Security #: 777777777, and yearly gross income: $70,000.00
Social Security #: 888888888, and yearly gross income: $80,000.00
Social Security #: 999999999, and yearly gross income: $90,000.00
Social Security #: 1111111110, and yearly gross income: $100,000.00

is it a if() statement?? help.

i think you have not extended the taxpayer class from other main method class and also the both classes shud be in same package

The code below is the file for the constructor method and the get methods

//Date: 3/18/2010

public class Taxpayer 
{
	private int socSec;
	private double yearlyGross;
	
	public Taxpayer(int taxPayer, double income) 
	{
		socSec = taxPayer;
		yearlyGross = income;
	}
	public int getSocSec()
	{
		return socSec;
	}
	public double getYearlyGross()
	{
		return yearlyGross;
	}

}

Next is the code for the for loop printing of the constructor and get method in another file

//Date: 3/18/2010

public class UseTaxpayer extends Taxpayer 
{
	public static void main(String[] args) 
	{
	Taxpayer[] somePayer = new Taxpayer[10];
	int x;
		
	for (x = 0; x < 10; ++x)
	{
	somePayer[x] = new Taxpayer(999999999, 0.0);
	System.out.println("Social Security #: " + somePayer[x].getSocSec() + ", and yearly gross income: $" + somePayer[x].getYearlyGross());
		}
	}

}

As you can see if you run it, it prints out to
Social Security #: 999999999, and yearly gross income: $0.0
Social Security #: 999999999, and yearly gross income: $0.0
Social Security #: 999999999, and yearly gross income: $0.0
Social Security #: 999999999, and yearly gross income: $0.0
Social Security #: 999999999, and yearly gross income: $0.0
Social Security #: 999999999, and yearly gross income: $0.0
Social Security #: 999999999, and yearly gross income: $0.0
Social Security #: 999999999, and yearly gross income: $0.0
Social Security #: 999999999, and yearly gross income: $0.0
Social Security #: 999999999, and yearly gross income: $0.0

which is what I want it to do, my problem is taking it and manipulating it to read
Social Security #: 111111111, and yearly gross income: $10000.0
Social Security #: 222222222, and yearly gross income: $20000.0
Social Security #: 333333333, and yearly gross income: $30000.0
Social Security #: 444444444, and yearly gross income: $40000.0
Social Security #: 555555555, and yearly gross income: $50000.0
Social Security #: 666666666, and yearly gross income: $60000.0

all the way up to 999999999 and income of $100,000.
I spent 2 hours trying to do it with what I learned from the book and I can't figure it out. Someone help?

i think you have not extended the taxpayer class from other main method class and also the both classes shud be in same package

You couldn't be more wrong. Please don't give wrong advices if you don't know what you are talking about.

Do all Social-Security-Numbers(SSN) need to be like this: (111...111, 222....222, ...) ?
Since you can have 999999999 different combinations, why do you want to limit yourself by using only those, when you can do this:

for (x = 0; x < 10; ++x)
	{
	somePayer[x] = new Taxpayer((x+1), 0.0);

}

The above will print:
1
2
3
4
....

If you want them to be:
000000001
000000002
000000003
000000004
Then don't use an int variable, use a String. Ints are used for calculations and you are not going to do any addittions with the SSN.
So this is my suggestion:

//Date: 3/18/2010

public class Taxpayer 
{
	private String socSec;
	private double yearlyGross;
	
	public Taxpayer(int taxPayer, double income) 
	{
		convertToString(taxPayer);
		yearlyGross = income;
	}
	public String getSocSec()
	{
		return socSec;
	}
	public double getYearlyGross()
	{
		return yearlyGross;
	}

       private convertToString(int i) {
           socSec = String.valueOf(i);

           while (socSec.length()<9) {
                   socSec = "0"+socSec;
           }
       }
}

In that wat when you call the constructor with an int: 1, then it will become the Stirng "0000000001"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.