Results 1 to 8 of 8
  1. #1
    b177y is offline Member
    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

    Question java toll booth information system (toll booth calculator)

    can some one help me to solve this problem to create a program in java for toll booth information system that enable to monitor number cars passing the toll both, compute total amount of money collected and total number of cars passing..

    class
    TollBooth

    member function:
    payingcar() //that increments the car total and adds $1.50/or the toll tax rate, to the cash total.
    nonpaycar() //that increments the car total but adds nothing to car cash total.
    display() //that display the two total (car and cash).

    the program should allow user to push 1 to count a paying car, and 2 to count a non paying car. Pushing 0 should cause the program to print the total cars and total cash and then exit

    :confused:
    i try to make the code but always get mistake
    because i dont know how to use switch case for a method and how to create a program to test this class..


    import javax.swing.*;
    import java.util.*;

    public class TollBooth
    {
    private int Carnum;
    private double Total;

    public TollBooth()
    {
    Carnum = 0;
    Total = 0.00;
    }
    public void setCarnum(int car)
    {
    Carnum = car;
    }
    public void setTotal(double tot);
    {
    Total = tot;
    }
    public int getCarnum()
    {
    return Carnum;
    }
    public double getTotal()
    {
    return Total;
    }
    payingcar()
    {
    }
    nonPayCar()
    {
    }
    display()
    {
    }
    }
    i dont know how to create the method code..:(
    and a program to test the class

    import javax.swing.*;
    import java.util.*;

    public class TestToll
    {
    public static void main(String arg[])
    {
    TollBooth item = new TollBooth();


    int userselect = Integer.parseInt(input);
    switch(userselect){
    case 0: <statement>
    break;
    case 1: <statement>
    break;
    case 2: <statement>
    break;
    default: <statement>

    }
    }
    }

  2. #2
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    one doubt, how to identify a car passing through tollboth should pay the tax,or not .Is it user choice?

  3. #3
    b177y is offline Member
    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by sandeepsai39 View Post
    one doubt, how to identify a car passing through tollboth should pay the tax,or not .Is it user choice?
    Actually its not the user choice. Cars passing the toll are expected to pay $1.50 per way. Mostly they do but sometimes a car goes without paying. So the system should keep track all the cars that passing the toll the cars that pay and cars didn't pay

    when user system push
    1 the program + 1 to the Carnum and 1.50 to Total
    2 the program + 1 to the Carnum and noting to Total
    0 the program display total car and total cash

    Carnum = payingcar + nonpaycar
    if paying car so Total + 1.50

  4. #4
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    Then,whats up you write every thing ,you have commplete logic with u , just implemnet those methods and call suitable method based on the user choices . you just spare some time.If u got any errors or problems ,then comeback again ,we will help you.

  5. #5
    b177y is offline Member
    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

    Default

    i got the logic but i cant implement the method :(
    i have no idea on how to use switch statement so i could get the output
    if case 1 what to do so its can go to calculate the total of paying cars
    if case 2 what?
    and case 0 what?

    i really stuck at to develope a program to test the TollBooth class

  6. #6
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    public class TollBooth
    {
    private int Carnum;
    private double Total;

    public TollBooth()
    {
    Carnum = 0;
    Total = 0.00;
    }
    public void setCarnum(int car)
    {
    Carnum = car;
    }
    public void setTotal(double tot)
    {
    Total = tot;
    }
    public int getCarnum()
    {
    return Carnum;
    }
    public double getTotal()
    {
    return Total;
    }
    public void payingcar()
    {
    Total +=1.50;
    Carnum++;
    display();
    }
    public void nonPayCar()
    {
    Carnum++;
    display();
    }
    public void display()
    {
    System.out.println("Cash total = " + Total);
    System.out.println("Car total =" + Carnum);
    }
    }
    //testing class

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;


    public class TestToll
    {
    public static void main(String arg[]) throws IOException
    {
    TollBooth item = new TollBooth();
    BufferedReader br =new BufferedReader(new InputStreamReader(System.in));

    boolean flag =true;

    while(flag){
    String input = br.readLine();
    int userselect = Integer.parseInt(input);
    switch(userselect){
    case 0:
    item.display();
    flag=false;
    break;
    case 1:
    item.payingcar();
    break;
    case 2:
    item.nonPayCar();
    break;
    default:
    flag=false;
    }
    }
    }
    }

  7. #7
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    I think it will meet your requirements.

  8. #8
    b177y is offline Member
    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

Similar Threads

  1. calculator java following pemdas rule
    By sassygirl_kea9@yahoo.com in forum New To Java
    Replies: 2
    Last Post: 07-10-2008, 04:15 AM
  2. Java Calculator
    By aapanju in forum New To Java
    Replies: 3
    Last Post: 04-17-2008, 05:33 AM
  3. Java calculator decimal
    By cart1443 in forum New To Java
    Replies: 2
    Last Post: 04-16-2008, 01:19 PM
  4. system information
    By nitinborge5 in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 09:25 AM
  5. Create a Calculator in Java
    By Albert in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 08:01 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
  •