473,385 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How do I store values into three arrays?

I posted this before and it was not clear so I am posting this again as I need help. And I have turned to thescripts because I have tried all the tutorials on Arrays/ArrayList and have just been even more confused.

Problem:
I am in the process of making a Tax Calculator, where the user enter his details (Name, Income, Number of Children, etc.) and the programe calculates the total amount of tax upon the given values. However, I made the system calculate the values but now I want it to store the values such as the users Name, Income and no of children. I know that I need to use an arraylist but I am totally confused about how to set up one and intergrate it into the code I already have.




The code below is where the details from the user are typed in then these values are then used by the calculations I have set up. These calculations are then shown to the user.

Expand|Select|Wrap|Line Numbers
  1.    InputStreamReader istream = new InputStreamReader(System.in) ;
  2.  
  3.               BufferedReader bufRead = new BufferedReader(istream) ;
  4.  
  5.               System.out.println("Welcome To The Rockall Tax Calculator");
  6.  
  7.  
  8.           try {
  9.                  //When the user enters the information it will be stored in these strings
  10.                  System.out.println("Please Enter In Your First Name: ");
  11.  
  12.                  String firstName = bufRead.readLine();
  13.  
  14.  
  15.                  System.out.println("What is your household income per year?: ");
  16.  
  17.                  String houseIncome = bufRead.readLine();
  18.  
  19.  
  20.                  System.out.println("How many children are in your household?: ");
  21.  
  22.                  String numberofChildren = bufRead.readLine();
  23.  
  24.  
  25.                  System.out.println("How many imported puffins are there?: ");
  26.  
  27.                  String numberofPuffins = bufRead.readLine();

But


How do I go about storing the caluclated values (below) along with the name of the user into an ArrayList.

Expand|Select|Wrap|Line Numbers
  1. if ( income >= 100000 ) 
  2.                 {
  3.                  System.out.println("Hello " +firstName + ". Your U " + houseIncome + " is over U 100000 therefore you will pay no tax on children = U" + allowanceTax); 
  4.                  System.out.println("The " + steppedTax + " will be taxed at 25% which = U" + total2);
  5.                  System.out.println("However, you earn more than U 100000 so the exceeding amount, which is U " + exceedAmount +  " ,will be taxed 40% = U" + htax); 
  6.                  System.out.println("As there are " + puffins + " puffins you will be charged 10% of U " + fullTotal1 + ", which is U " + fullTotal1*puffinTax);
  7.                 }
  8.                  else 
  9.                 {
  10.                  System.out.println("Hello " +firstName + ". Your U " + income + " is under U 100000 therefore you will pay tax on" + children + " , which is = U" + allowanceTax);   
  11.                  System.out.println("As you have " + children + " children you will be taxed at U " + allowanceTax);
  12.                  System.out.println("The tax owned on the amount of U " + total + " taxed at 25% is U " + tax);
  13.                  System.out.println("As there are " + puffins + " puffins you will be charged 10% of U " + fullTotal2 + ", which is U " + fullTotal2*puffinTax);
  14.                 }

If anyone could help me then I would be extremely grateful. As I need complete this program so that I am able to submit in time.

Thanks in advance,

thegreatest21
Aug 7 '07 #1
3 1376
JosAH
11,448 Expert 8TB
I am in the process of making a Tax Calculator, where the user enter his details (Name, Income, Number of Children, etc.) and the programe calculates the total amount of tax upon the given values. However, I made the system calculate the values but now I want it to store the values such as the users Name, Income and no of children. I know that I need to use an arraylist but I am totally confused about how to set up one and intergrate it into the code I already have.
You're not supposed to do that at all. You're supposed to create a little Tax class
or whatever you want to call it and store the relevant data in such an object.
Storing different data (and types!) in arrays or ArrayLists is so Fortran and it
screams for nasty errors. Don't do it.

kind regards,

Jos
Aug 7 '07 #2
I have been doing it completely wrong!
Wow. Thanks for the heads up.
Aug 7 '07 #3
JosAH
11,448 Expert 8TB
I have been doing it completely wrong!
Wow. Thanks for the heads up.
No need to worry; when people start programming using Java they all make the
same following common mistakes:

1) stuff everything in the main() method which turns into an unmaintainable huge
and complicated mess.

2) stuff everything in one single class which turns into an unmaintainable huge
Swiss Army knife.

3) assume that visual basic trickery-dickery should work in Java as well.

4) depend on other classes directy without defining interfaces first which glues
everything together to a huge unmaintainable mess of classes.

5) don't read the API documentation for third party .jars and start blaming their
own faults on these jars.

and the list goes on ... ;-)

kind regards,

Jos
Aug 7 '07 #4

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

Similar topics

4
by: Christopher Brandsdal | last post by:
Hi! I have a delicatg problem.... I have made a registration form for adding my friends information in a database. The problem is that I want to connect the persons with companies in the same...
6
by: steveneng | last post by:
C++ Primer Plus Programming Exercises 4th Ed - Prate Help I'm trying to refresh myself and I'm stuck on this problem (not homework/school related but for personal advancement). 6: Do...
2
by: Chaz | last post by:
Hello, I hope someone can help me out. I am going to be taking the third step in a programming class soon(I took the previous two a while ago at a different school) and in an effort to get back up...
41
by: Materialised | last post by:
I am writing a simple function to initialise 3 variables to pesudo random numbers. I have a function which is as follows int randomise( int x, int y, intz) { srand((unsigned)time(NULL)); x...
4
by: RubenDV | last post by:
I am trying to make a cipher with a 256-bit key but i have no idea how the store this key without using arrays of ints or something like that. I just need a type that is big enough to hold the...
5
by: Michal Táborský | last post by:
I am wondering, if it's effective to use text arrays to store multilanguage information. We used to do it like this: CREATE TABLE product ( id serial NOT NULL, price float4, ... )
6
by: c676228 | last post by:
Hi everyone, I wrote a store procedure that fetch one row data in the database based on the parameter value I entered. After I created the store procedure, the store procedure code looks like...
90
by: John Salerno | last post by:
I'm a little confused. Why doesn't s evaluate to True in the first part, but it does in the second? Is the first statement something different? False print 'hi' hi Thanks.
5
by: jc | last post by:
Hi. I am in a situation with an engineering application involving monitoring of press operations. This involves storage of numbers for both an X and Y arrays. The number of element within the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...

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.