Create a class called Theatre
Have main method in it.
Create an instance[object] called raja of Theatre class.
Call method bookTicket(200)
Have method signature for bookTicket method with necessary arguments for handling the input 200.
Define bookTicket method as below.
Declare a local variable ticket_price in int datatype.
Assign 120 as value for ticket_price variable.
Subtract 120 from method argument (200)
Store result of above line into another variable called balance of int datatype.
return this balance to main method.
In main method, receive this balance as int balance
In main method, print as below.
System.out.println(βAfter booking ticket β + balance);
package test2;
public class Theatre
{
public static void main(String[] args)
{
Theatre raja = new Theatre();
int Balance = raja.bookTicket(200);
System.out.println("after the balance "+Balance);
}
public int bookTicket(int price)
{
int ticket_price = 120;
int Balance = price - ticket_price;
return Balance;
}
}
out put---after the balance 80
Top comments (0)