Java Compolation

Chelsea
Java Compolation
Posted in : Java Beginners
How do I correctly write a program that calculates a customer's monthly bill?

This is what I have:

import java.util.Scanner;
import java.text.DecimalFormat;
public class Bill
{
public static void main(String[] args)
{
final double BASE_RATE_A = 9.95;
final double BASE_RATE_B = 13.95;
final double BASE_RATE_C = 19.95;
final double BASE_HOUR_RATE_A = 10;
final double BASE_HOUR_RATE_B = 20;
String servicePackage;
int hours;
double charges;

Scanner kb = new Scanner(System.in);
DecimalFormat fmt = new DecimalFormat("\$##.00");

System.out.print("Service package (A, B, or C): ");
servicePackage = kb.nextLine();
System.out.print("Number of hours: ");
hours = kb.nextInt();

kb.nextLine();

if(servicePackage == "A")
{
if(hours>0&&hours<=10)
{
charges = BASE_RATE_A;
System.out.println("Total charges: "+fmt.format(charges));
System.exit(0);
}
else if(hours>10&&hours<=30*24)
{
System.out.println("Total charges: "+fmt.format(charges));
System.exit(0);
}
else
{
System.out.print("invalid input, please enter number of "
+ "hours between 0 and 720 ");
hours = kb.nextInt();
}
}
else
{
System.out.print("invalid input, please enter (A, B or C): ");
}
}
}

February 15, 2010 at 11:10 AM

Hi Friend,

Try the following:

import java.util.Scanner;
import java.text.DecimalFormat;
public class Bill
{
public static void main(String[] args)
{
final double BASE_RATE_A = 9.95;
final double BASE_RATE_B = 13.95;
final double BASE_RATE_C = 19.95;
final double BASE_HOUR_RATE_A = 10;
final double BASE_HOUR_RATE_B = 20;
String servicePackage;
int hours;
double charges;

Scanner kb = new Scanner(System.in);
DecimalFormat fmt = new DecimalFormat("\$##.00");

System.out.print("Service package (A, B, or C): ");
servicePackage = kb.nextLine();
System.out.print("Number of hours: ");
hours = kb.nextInt();
kb.nextLine();
if(servicePackage.equals("A"))
{
if(hours>0&&hours<=10)
{
charges = BASE_RATE_A;
System.out.println("Total charges: "+fmt.format(charges));
System.exit(0);
}
else if(hours>10&&hours<=30*24)
{
System.out.println("Total charges: "+fmt.format(charges));
System.exit(0);
}
else
{
System.out.print("invalid input, please enter number of "+ "hours between 0 and 720 ");
hours = kb.nextInt();
}
}
else
{
System.out.print("invalid input, please enter (A, B or C): ");
}
}
}

Thanks

jav compolation error - Java Beginners
jav compolation error  find symbol error
Java Compolation - Java Beginners
Java Compolation  How do I correctly write a program that calculates a customer's monthly bill? This is what I have: import java.util.Scanner; import java.text.DecimalFormat; public class Bill { public static void
java
java  diff bt core java and java
java
java  what is java
JAVA
JAVA  how the name came for java language as "JAVA
java
java   why iterator in java if we for loop
java
java  explain technologies are used in java now days and structure java
java
java  different between java & core java
Java
Java   Whether Java is pure object oriented Language
java
java  is java open source
java
java  what is java reflection
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java   What is ?static? keyword
java
java  RARP implementation using java socket
java
java  sample code for RARP using java
java
java  Does java allows multiline comments
Java
Java  how to do java in command prompt
java
java  give a simple example for inheritance in java
java
java  give a simple example for inheritance in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  Write a java code to print "ABABBABCABABBA
java
java  write a program in java to acess the email
java
java  send me java interview questions
java
java  how use java method
java
java  what are JAVA applications development tools
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  is java purely object oriented language