DEV Community

hema latha
hema latha

Posted on

Task

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

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more