473,425 Members | 1,992 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,425 software developers and data experts.

how do i get rid of my error

i need to get rid of my error just compile and run
help!!!
it is for adding up monthly income dont copy my idea!!!

help i am n00b

i know alot of stuff is not used it is not even half way done!!

ps it is very messy i have still not cleaned it up

pss my batery is dieing so i have to type fast i deleted a section and cant get it back what i am trying to do is add up the array Bnum HELP!!!!!


Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3. public class Money {
  4.     public static void main(String[] args){
  5.  
  6.         Scanner Scan = new Scanner(System.in);
  7.         double Income, Tax, TaxTotal, Bills, OfficeSpace, LeftOver, Bill;
  8.         int NBill, i, a, b;
  9.  
  10.         Bills = 0.;
  11.         i = 1;
  12.  
  13.         System.out.println("Imput this month's income:");
  14.  
  15.         Income = Scan.nextDouble();
  16.  
  17.         System.out.println("Your current balence is $" + Income );
  18.         System.out.println("How much of your income will you save for tax? (percentage, no percentage sign, whole num.)");
  19.  
  20.         Tax = Scan.nextDouble();
  21.  
  22.         System.out.println("$" + Income * (Tax / 100) + " goes to the Unchel Sam.");
  23.  
  24.         TaxTotal = Income * (Tax / 100);
  25.         Income = Income - TaxTotal;
  26.  
  27.         System.out.println("Your new current balence is $" + Income );
  28.         System.out.println("How many bills do you have?");
  29.  
  30.         NBill = Scan.nextInt();
  31.  
  32.         double[] Bnum = new double[NBill];
  33.         Bnum[0] = 0;
  34.  
  35.         do{
  36.             System.out.println("how much is value of bill " + i);
  37.             Bnum[i] = Scan.nextDouble();
  38.             i++;
  39.  
  40.         }while(i <= NBill);
  41.  
  42.  
  43.  
  44.         \\ this is deleted part
  45.  
  46.  
  47.         System.out.println("Your new current value of used money is $" + Bnum);
  48.  
  49.  
  50.  
  51.     }
  52. }
Jun 24 '10 #1
9 1551
Dheeraj Joshi
1,123 Expert 1GB
OK. What you want to achieve? And what error's you are getting?

I suspect you are getting array index out of bound exception.

Expand|Select|Wrap|Line Numbers
  1. System.out.println("Your new current value of used money is $" + Bnum);
  2.  
What you want to print here?

Please post error messages too. And please wrap the code in code block.

Regards
Dheeraj Joshi
Jun 24 '10 #2
@dheerajjoshim
the error is Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at Income.main(Money.java:37) the 2 is for how many bills you say you have so if i say i have 5 bill then the 2 will change to a 5

i am trying to make it so i can put in my monthly income and see how much money i have left over so say i made $200 this month (i am not poor) i would save 20% for tax then i say how many bills i have and the i add it up.

i am new at this i am only half way through the java book i am reading so if you have any recommendations i would happily take them.


also i see your picture is the eclipse symbol if you know any tricks for the program it would be much appreciated

sorry there is a bunch of stuff not used i am a very unorganized person and i half been trying to fix this error for 3 days strait last night was the only night i got some sleep

thank you for taking your time to help me
Jun 24 '10 #3
jkmyoung
2,057 Expert 2GB
Indexes start at index 0.
Change it to
while(i < NBill);
removing the equal sign.
Couldn't you tell you were trying to input one too many bills?
Jun 24 '10 #4
@jkmyoung
i have not slept in 3 days how should i know and plus i changed it and ran it and it said (this is what the entire program said )
"Imput this month's income:
200
Your current balence is $200.0
How much of your income will you save for tax? (percentage, no percentage sign, whole num.)
20
$40.0 goes to the Unchel Sam.
Your new current balence is $160.0
How many bills do you have?
2
how much is value of bill 1
2
Your new current value of used money is $[D@1fb8ee3
"


compile it and run you will see what i mean
Jun 24 '10 #5
Dheeraj Joshi
1,123 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. System.out.println("Your new current value of used money is $" + Bnum);
  2.  
It Should print the value in ith index.

So change it to

Expand|Select|Wrap|Line Numbers
  1. System.out.println("Your new current value of used money is $" + Bnum[index]);
  2.  
Regards
Dheeraj Joshi
Jun 25 '10 #6
@dheerajjoshim
i tried that and it gave me an error the error is
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
index cannot be resolved

at Money.main(Money.java:42)




thanks for the help i am so frustrated i have been dreaming about ways to fix the program
Jun 25 '10 #7
Dheeraj Joshi
1,123 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. System.out.println("Your new current value of used money is $" + Bnum[index]);
  2.  
Should not be this inside the while loop?

Regards
Dheeraj Joshi
Jun 25 '10 #8
@dheerajjoshim
it is not my entire script is
Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3. public class Money {
  4.     public static void main(String[] args){
  5.  
  6.         Scanner Scan = new Scanner(System.in);
  7.         double Income, Tax, TaxTotal, Bills, OfficeSpace, LeftOver, Bill;
  8.         int NBill, i, a, b;
  9.  
  10.         Bills = 0.;
  11.         i = 1;
  12.  
  13.         System.out.println("Imput this month's income:");
  14.  
  15.         Income = Scan.nextDouble();
  16.  
  17.         System.out.println("Your current balence is $" + Income );
  18.         System.out.println("How much of your income will you save for tax? (percentage, no percentage sign, whole num.)");
  19.  
  20.         Tax = Scan.nextDouble();
  21.  
  22.         System.out.println("$" + Income * (Tax / 100) + " goes to the Unchel Sam.");
  23.  
  24.         TaxTotal = Income * (Tax / 100);
  25.         Income = Income - TaxTotal;
  26.  
  27.         System.out.println("Your new current balence is $" + Income );
  28.         System.out.println("How many bills do you have?");
  29.  
  30.         NBill = Scan.nextInt();
  31.  
  32.         double[] Bnum = new double[NBill];
  33.         Bnum[0] = 0;
  34.  
  35.         do{
  36.             System.out.println("how much is value of bill " + i);
  37.             Bnum[i] = Scan.nextDouble();
  38.             i++;
  39.  
  40.         }while(i < NBill);
  41.  
  42.         System.out.println("Your new current value of used money is $" + Bnum[index]);
  43.  
  44.  
  45.  
  46.     }
  47. }

and it still gives me an error

thanks for the help
Jun 26 '10 #9
Dheeraj Joshi
1,123 Expert 1GB
index is undefined in your program. Move your print statement inside the while loop. In my last post i gave you the example. Not exact code.

Expand|Select|Wrap|Line Numbers
  1. System.out.println("Your new current value of used money is $" + Bnum[i]);
  2.  
Note: You need to print it before incrementing i.

Regards
Dheeraj Joshi
Jun 26 '10 #10

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

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
2
by: Gregory | last post by:
Hi, One of the disadvantages of using error handling with error codes instead of exception handling is that error codes retuned from a function can be forgotten to check thus leading to...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
5
by: yashu0209 | last post by:
I have an error occurring when i try to compile the program and the error is: D:\Program Files\visual studio 6.0\MSDev98\MyProjects\GLEnabledView\GLNew.cpp(164) : error C2653: 'CGLEnabledView' :...
5
by: titli | last post by:
Hi guys, I have a .mdb which generates , further some mini .mdbs..Later these generated mini mdbs are provided as input to excel viewer.Till yesterday everything was working fine.. But today after...
3
by: saudade | last post by:
Hello, I'm getting 2 errors when I enter my html code in w3c markup validation. These are the errors: # Line 89, Column 17: document type does not allow element "DIV" here; missing one of...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.