trouble with java! please help a newbie coder

  • Thread starter Deleted member 29591
  • Start date
Status
Not open for further replies.
D

Deleted member 29591

Guest
I'm in a beginners programming class and I have a program that is due monday. It's supposed to calculate a sales tax of %6.25 if you live in utah or idaho and just tell you the price if you live in another state. I'll post my code so far, hopefully someone can tell me what i'm doing wrong. Right now it if i put in a value, like 8 dollars it tells me
Enter the price of the item 0.0 8.00
What state do you live in?u
Your tax is $0.5
Your total is $8.00
and if i do a different state, say oregon, it works perfectly.
Enter the price of the item 0.0 8.00
What state do you live in?
Your tax is $0.0
Your total is $8.0

Anyway, here's the code
public class prog2
{

public static void main(String[] args)
{

double tax = 0.0;
double total = 0.0;
double price = 0.0;
char state = 'u';

price = Console.readDouble("Enter the price of the item " + price + " ");
state = Console.readChar("What state do you live in?");

if (state == 'u' || state == 'U' || state == 'I' || state == 'i') {
tax = 0.0625;
tax = (price * tax);
}



System.out.println("Your tax is $" + tax);
System.out.println("Your total is $" + price);
}
}
by the way, Console.class is a program they give you so you can recieve user input. It's supposedly really hard to recieve user input in java.
 
Originally posted by Crimson939:
Anyway, here's the code
<BLOCKQUOTE>code:<HR>
Code:
   public class prog2
    {<P>      public static void main(String[] args)
      {<P>	double tax = 0.0;
	double total = 0.0;
	double price = 0.0;
	char state = 'u';
   
	price = Console.readDouble("Enter the price of the item " + price + " ");
	state = Console.readChar("What state do you live in?");<P>   if (state == 'u' || state == 'U' || state == 'I' || state == 'i') {
      tax = 0.0625;
tax = (price * tax);
}
  <P>       
System.out.println("Your tax is $" + tax);
System.out.println("Your total is $" + price);
}
}<P>
by the way, Console.class is a program they give you so you can recieve user input. It's supposedly really hard to recieve user input in java.<HR></BLOCKQUOTE>


  • You don't need to initalize state to 'u' if you're just going to read a new value into it. Just "char state;" will be fine.
  • Class names should start with an uppercase letter. See Code Conventions for the Java Programming Language
  • It's not all that hard to read stuff in, just wrap System.in in a BufferedReader and call readLine() on it.
  • The UBB "CODE" tag is sexy.


~Kevin
:)
 
Status
Not open for further replies.