In: Computer Science
.......Subject Java.....
main()
main() will ask the user for input and then call functions to do calculations. The calculations will be returned to main() where they will be printed out.
First function
Create a function named computeBill that receives on parameter. It receives the price of an item. It will then add 8.25% sales tax to this and return the total due back to main().
Second function
Create another function named computeBill that receives 2 parameters. It will receive the price of an item and the quantity ordered. It will calculated the total and then add 8.25% sales tax to that and return total due back to main().
Third function
Create a third function names computeBill that receives 3 parameters. It will receive the price of an item, the quantity ordered, and a coupon value. It will then calculate the total, then deduct the coupon amount, and add 8.25% sales tax. It will then return the total due to main().
Can you please use simple code - Thank you
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double price,coupon;
int quantity;
System.out.print("Enter price of
item: ");
price=sc.nextDouble();
System.out.print("Enter quantity of item: ");
quantity=sc.nextInt();
System.out.print("Enter coupon price of item: ");
coupon=sc.nextDouble();
double res1 =computeBill(price);
System.out.println("Total:
"+res1);
double res2 = computeBill(price,quantity);
System.out.println("Total:
"+res2);
double res3 =computeBill(price,quantity,coupon);
System.out.println("Total: "+res3);
}
public static double computeBill(double price)
{
double res1= price + price*8.25/100;
return res1;
}
public static double
computeBill(double price,int quantity)
{
double res2= price*quantity;
return (res2+res2*8.25/100);
}
public static double
computeBill(double price,int quantity, double coupon)
{
double res3= price*quantity-coupon;
return (res3+res3*8.25/100);
}
}