Question
Doesn't have to be coded in java just need to do this in a doc. I started it but am not sure if I am
Doesn't have to be coded in java just need to do this in a doc. I started it but am not sure if I am even doing it correctly.. Any help would be appreciated.
Write the following static methods. Assume the reference variable input for the Scanner class and any global variables mentioned are already declared. Use print.
1a. A method called ticket() that prompts for the number of tickets to be purchased and stores it in a global variable called noOfTickets. Think about the data type.
public static void tickets( )
{
System.out.printf(%n How many tickets would you like to purchase? );
noOfTickets=input.nextInt();
}
1b. Overload the method coded in 1a above so that it accepts the number of tickets and the price for a ticket through its parameter list, and returns the cost for the ticket(s). No prompts are needed.
public static void tickets(int noOfTickets, double costOfTicket)
{System.out.printf(%n How many tickets would you like to purchase? );
input.nextInt();
return noOfTicket * costOfTicket;
}
1c. A value-receiving method that accepts the cost for a ticket purchase and adds it to a global variable called monthlyFun.
1d. A method that accepts yearlyFun and yearlyFunBudget through its parameter list and test to see if yearlyFun is over-budget, under-budget, or on-budget. If it is over-budget return the message Way too much fun! Over budget!; under-budget return Little more fun! Under-budget!; and on-budget Just the right fun! On-budget!. No prompts are needed.
public static String fun(Double yearlyFun, Double yearlyFunBudget)
{
if(yearlyFun < yearlyFunBudget)
System.out.printf(%nWay too much fun! Over-budget!)
else if(yearlyFun > yearlyFunBudget)
System.out.printf(%nLittle more fun! Under-budget!)
else
System.out.printf(%nJust the right fun! On-budget!);
}
Write statements that will call each of the methods coded above. Be conscious of the value-returning methods. If returning to a variable declare the variable. The return for 1d is to be printed. Assume method calls are done in the main() is in the same class.
a.
b.
c.
d.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started