Results 1 to 6 of 6
  1. #1
    matteo263 is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Exclamation Probmlem help fast

    I had this problem:

    A telephone company sends the bills to the customers every month. The rate of local calls is 10c for the first 5 minutes, and 1c for every minute after the first 5 minutes. If a call is less than 5 minutes, the-call will still cost 10c. The bill is calculated on minutes, i.e. if a customer makes a 10-second call, it will count as a 1-minute call. A discount of 10% is given if the bill is over 50 Euros.

    Write an algorithm for part of the billing system which will ask the user to enter the duration of each local call done during that month. Remember that each call duration is entered in minutes only. The user can stop entering durations by entering a zero. After displaying the bill, you should ask the user whether he wants to enter data for another customer.

    A program that performs the above must satisfy the following requirements:

    REQ 1: A user must be prompted to enter customer’s name and customer number, and to enter call durations for each local call. He stops entering durations be entering a zero.

    REQ 2:The final bill including any discount must be output to the user in Euros and Euro cents. You need to show the total amount of minutes for local calls, any discounts, and the total bill. Remember that if the bill is over 50 Euros, you should give a 10% discount.


    This is the sorce code I did


    import java.util.Scanner;
    public class Tester
    {
    public static void main (String args[])
    {

    boolean go=true;

    while(go)
    {

    System.out.println("Please enter your name _");
    Scanner kbReader=new Scanner(System.in);
    String name=kbReader.nextLine();
    System.out.println("Please enter your telephone number_");
    int num=kbReader.nextInt();
    System.out.println("Please enter your the duration of all your calls");
    int minutes;
    double gross=0;
    double net=0;
    double discount=0;
    int totalminutes=0;
    do
    {
    minutes=kbReader.nextInt();
    totalminutes=totalminutes+minutes;
    if (minutes<=5&&minutes!=0)
    { gross=gross+10;
    }
    if (minutes>5&&minutes!=0)
    { gross=gross+10;
    int extra=minutes-5;
    gross=gross+extra;
    }
    }
    while(minutes!=0);
    if (gross>=5000)
    { discount=gross*0.10;
    net=gross-discount;
    }
    else
    {net=gross;
    }

    int eurogross=(int) gross/100;
    int eurogrossc=eurogross*100;
    int centgross=(int) gross-eurogrossc;
    System.out.println("Total minutes="+totalminutes+" minutes");
    System.out.println("gross price="+eurogross+" Euro "+centgross+" Cents ");
    int eurodisc=(int) discount/100;
    int eurodiscc=eurodisc*100;
    int centdisc=(int) discount-eurodiscc;
    System.out.println("10% discount(if aplicable)="+eurodisc+" Euro "+centdisc+" Cents ");
    int euronet=(int) net/100;
    int euronetc=euronet*100;
    int centnet=(int) net-euronetc;
    System.out.println("net price="+euronet+" Euro "+centnet+" Cents ");
    System.out.println("Do you want to calculate another account [Y/N]");
    String userInput="y";
    userInput=kbReader.nextLine();
    char c=userInput.charAt(0);
    if( c!='Y')
    {go = false;
    }
    }
    }
    }

    Why is it giving me a Runtime Error?!

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    What is the full C&P'd runtime error text with line numbers included, please? Also, in the future, please wrap your code in [CODE] tags to make it more readable.

  3. #3
    matteo263 is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    Sry this is my first post :p

    java.lang.StringIndexOutOfBoundsException: String index out of range: 0
    at java.lang.String.charAt(String.java:686)
    at Tester.main(Tester.java:61)

  4. #4
    matteo263 is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    oh and it was line 61

  5. #5
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    I'm not sure exactly what the issue is (though I suspect that nextInt is just messing with the scanner), but you can alleviate it by putting "kbReader.nextLine();" after the "while(minutes!=0);" line just to relieve the scanner's data.

  6. #6
    matteo263 is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

Similar Threads

  1. Fast Help Plz ..
    By Hamodi18 in forum New To Java
    Replies: 6
    Last Post: 07-16-2010, 05:24 AM
  2. how fast?
    By abdullahansari in forum New To Java
    Replies: 4
    Last Post: 06-30-2010, 03:17 AM
  3. Help me fast!
    By Manikyr in forum New To Java
    Replies: 4
    Last Post: 03-16-2009, 07:43 AM
  4. pls help me fast!
    By rexson98 in forum New To Java
    Replies: 10
    Last Post: 10-15-2008, 12:20 PM
  5. Fast Data Transfer 0.6.4
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-20-2007, 08:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •