473,544 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Modifying two variables in a loop

5 New Member
I need to modify the UseTaxpayer application so each Taxpayer has a successive Social Security number from 1 top 10 and a gross income that ranges from $10,000 to $100,000, increasing by $10,000 for each successive Taxpayer. Save as UseTaxpayer2

Here is what I have so for far from the UseTaxpayer application. Any suggestions on how to get it to increment?

Expand|Select|Wrap|Line Numbers
  1. public class Taxpayer 
  2. {
  3.     private int socNum;
  4.     private int yearIncome;
  5.  
  6.     public Taxpayer(int s, int i)
  7.     {
  8.         socNum = s;
  9.         yearIncome = i;        
  10.     }
  11.     public int getSocNum()
  12.     {
  13.         return socNum;
  14.     }
  15.     public int getYearIncome()
  16.     {
  17.         return yearIncome;
  18.     }
  19.  
  20. }
  21.  
and

Expand|Select|Wrap|Line Numbers
  1. public class UseTaxpayer
  2. {    
  3.     public static void main(String[] args)
  4.     {    
  5.      Taxpayer[] aTaxpayer = new Taxpayer[10];
  6.  
  7.        for(int i = 0; i < 10; i++)
  8.             aTaxpayer[i] = new Taxpayer(999999999,0);
  9.             for(int i = 0 ; i < 10; i++)
  10.             {
  11.              System.out.println(aTaxpayer[i].getSocNum()
  12.                 + " " + aTaxpayer[i].getYearIncome());
  13.  
  14.             }
  15.         }
  16. }
  17.  
Nov 12 '07 #1
2 3313
SammyB
807 Recognized Expert Contributor
You've made a good start by putting the Taxpayer constructor into a loop. Remember that the Taxpayer constructor gets a SSAN & income input parameter, so you just need to vary these like your instructions instead of using the same values. HTH --Sam
Nov 13 '07 #2
r035198x
13,262 MVP
Have a look at

Expand|Select|Wrap|Line Numbers
  1.         for(int i = 0; i < 10; i++) {
  2.        // you already have a counter called i so use it
  3.        aTaxpayer[i] = new Taxpayer(i, i + 10);
  4. }
All you need to do is manipulate the i value at each point as required to get the values that you want.
Nov 13 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
5043
by: Peter Ballard | last post by:
Whew. I hope that title is descriptive! Hi all, The python tutorial tells me "It is not safe to modify the sequence being iterated over in the loop". But what if my list elements are mutable, such as lists or objects, e.g. a = , , , ] for coord in a:
6
1916
by: Tim Conkling | last post by:
I'm having difficulty tracking down a bug in my program and I'm wondering if it's due to some misuse on my part of new'd objects. Here's the situation. If anyone can shed some light on this, I'd be much obliged. I have a simple class that looks something like this (this is a rather abbreviated version): class TileAttributes {
8
2517
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined in global space, therefore it is not a global variable, yes? Even if it was global, how would it get from one function to another? In PHP variables...
5
2408
by: masood.iqbal | last post by:
My simplistic mind tells me that having local variables within looping constructs is a bad idea. The reason is that these variables are created during the beginning of an iteration and deleted at the end of the iteration. Kindly note that I am not talking about dynamically allocating memory within a loop, which is a perfectly valid operation...
9
2468
by: Javaman59 | last post by:
Using local declarations within a block often makes code more readable, but is it less efficient? eg... void P() { while (...) { int i = ...; bool b = ...; .... } }
2
2556
by: chuck | last post by:
Hi, I am modifying some code from here http://www.quirksmode.org/dom/domform.html I have a div 'readroot' that I clone. I change the change the id and name of the childnodes of 'readroot' to the original name plus a number(counter). The problem is I have i have a div 'serials' inside 'readroot' and the childnodes of
13
2108
by: Robin Becker | last post by:
When young I was warned repeatedly by more knowledgeable folk that self modifying code was dangerous. Is the following idiom dangerous or unpythonic? def func(a): global func, data data = somethingcomplexandcostly() def func(a): return simple(data,a)
4
1689
by: sklett | last post by:
(I posted this in a databinding NG, but it's a VERY low traffic NG so I thought I would post here as well. I hope no one minds too much, if you do I'm sorry) I have a DGV that is bound to a DataTable that is loaded during application startup. I can sort with all the columns and everything works fine. I have a method that can be invoked...
24
2902
by: allpervasive | last post by:
hi all, this is reddy, a beginner to c lang,,here i have some problems in reading and modifying the contents of a file,, hope you can help to solve this problem. Here i attach the file to be modified and the program code. In the attached file below i just want to change the value of data(only float value) after the line 1 P V T 1 15 till 2...
4
1139
by: nondos | last post by:
Hello I have a thread that run loop in queue variable like this: For each <somethingas <somethingin <queue variable>
0
7376
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7633
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7785
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5935
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5310
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4932
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3433
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
997
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
679
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.