Question

Given the following code: IN JAVA Write the method definiton for missing method 1 that: provides...

Given the following code: IN JAVA

Write the method definiton for missing method 1 that:

  • provides the number of pizzas sold as an input parameter
  • defines a constant value of $15 for the cost of a single pizza, and uses it in calculations
  • returns the total cost of the pizzas sold

Write the method definition for missing method 2 that:

  • provides the total cost of the pizzas sold and the tax rate as input parameters
  • returns the total with tax

Given the code from the previous questions:

Write the code for missing statement 1 that calls the appropriate method to calculate the pizzaTotal.

Given the code from the previous questions:

Write the code for missing statement 2 that calls the appropriate method to calculate the totalWithTax.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please comment, if you need any corrections.

Give a Thumps up if you like the answer

Program

import java.util.*;
public class pizza
{
//Define constant value for the cost of a single pizza
public static int single_pizza_price = 15;
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
//Declare variables
double PizzaTotal;
double TotalWithTax,tax_rate;
int no_pizza;
//Read input
System.out.print("Enter Number Of Pizzas :");
no_pizza=s.nextInt();
//Function call to find total cost of pizzas sold
PizzaTotal=total_cost(no_pizza);
//Display result
System.out.println("Total Cost of pizzas :$"+PizzaTotal);

//Read tax rate
System.out.print("Enter tax rate :");
tax_rate=s.nextDouble();
//Function call to find total cost with tax
TotalWithTax=total_tax(PizzaTotal,tax_rate);
//Display result
System.out.println("Total Cost of pizzas with tax:$"+TotalWithTax);
}

public static double total_cost(int no_pizza)
{
return (no_pizza*single_pizza_price);
}

public static double total_tax(double total_cost,double tax_rate)
{
double result;
result=total_cost+(total_cost*(tax_rate/100));
return (result);
}
}

Output

Enter Number Of Pizzas :10
Total Cost of pizzas :$150.0
Enter tax rate :10
Total Cost of pizzas with tax:$165.0

Screenshot of Program

import java.util.*; public class pizza { Define constant value for the cost of a single pizza public static int single_pizza_

Add a comment
Know the answer?
Add Answer to:
Given the following code: IN JAVA Write the method definiton for missing method 1 that: provides...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT