Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The University bookstore is having the start of the semester sale and offering d

ID: 3537988 • Letter: T

Question

The University bookstore is having the start of the semester sale and offering

discount for students, please write a Java program to perform the following.

user should input the value via the keyboard.

by the number of books entered), in each iteration ask the user to input the

price of the book and your loop should calculate the total price.

price after the discount. To calculate the discount, your main method is to call

the calcDiscount method. The amount of discount is determined according to the

number of the text books the student buys. The method (calcDiscount) accepts the

number of books as an input parameter and returns the amount of discount

according to the following:

of original price

original price

original price

Explanation / Answer

import java.util.Scanner;

import java.io.*;

class Bookstore

{


public static double calcDiscount(int n)

{

if( n <3) return 0.1;

else if(n<5) return 0.15;

else return 0.2;

}

public static void main(String args[]) throws IOException

{

System.out.println("Enter Number of Books");

Scanner sc=new Scanner(System.in);

int nb=sc.nextInt();

double sum=0;

for(int i=0;i<nb;i++)

{

System.out.println("Enter Price of Book "+(i+1)+" :");

sum=sum+sc.nextDouble();

}

double disRate=calcDiscount(nb);

double price= (1.0 - disRate)*sum;

System.out.println("Final Discounted Price is :"+price);


}

}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote