Answer to Question #228529 in Java | JSP | JSF for swastica k g

Question #228529

1.Imagine a tollbooth with a class called toll Booth. The two data items are a type unsigned int to hold the total number of cars, and a type double to hold the total amount of money collected. A constructor initializes both these to 0. A member function called payingCar ( ) increments the car total and adds 0.50 to the cash total. Another function, called nopayCar ( ), increments the car total but adds nothing to the cash total. Finally, a member function called displays the two totals. 



1
Expert's answer
2021-08-23T01:17:49-0400


public class Main
{
	public static void main(String[] args) {
		tollbooth t=new tollbooth();
		t.payingcar();
		t.nopayingcar();
		t.display();
	}
}
class tollbooth
{
    private long car;
    private double amount;
    public tollbooth()
    {
        car=0;
        amount=0;
    }
    public void payingcar()
    {
        car++;
        amount+=0.50;
    }
    public void nopayingcar()
    {
        car++;
    }
    public void display()
    {
        System.out.println("Total cars: "+car);
        System.out.println("Total amount: "+amount);
    }
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS