Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package bookstore.pkg2;
- /**
- *
- * @author LemoneFresh
- */
- import java.util.Scanner;
- public class Bookstore2 {
- /**
- *
- * @param costBook Cost of Book
- * @param numEbook Number of Ebooks Bought
- * @param baseCharge Base charge cost*numbought
- * @return returns the base charge of books
- */
- public static double calcBasecharge(double costBook,int numEbook){
- double baseCharge = costBook*numEbook;
- return baseCharge;
- }
- /**
- *
- * @param baseCharge Takes the base charge for calculations
- * @param numEbook Takes number of ebooks for calculations
- * @return returns the amount of service charge based on the number of books.
- */
- public static double calcServicecharge(double baseCharge, int numEbook){
- final double serviceUnder8 = 0.07,
- serviceOver8 = 0.05,
- serviceOver15 = 0.03,
- serviceOver20 = 0.0;
- double serviceCharge = 0.0;
- if (numEbook >= 20) {serviceCharge =baseCharge*serviceOver20;}
- else if (numEbook > 15) {serviceCharge = baseCharge*serviceOver15;}
- else if (numEbook > 8) {serviceCharge = baseCharge*serviceOver8;}
- else {serviceCharge = baseCharge*serviceUnder8;}
- return serviceCharge;
- }
- public static double calcDiscount(double productCharge, int memStatus,double baseCharge ){
- final double noMem = 1,
- bronzeMem = 0.10,
- silverMem = 0.15,
- goldMem = 0.20;
- double discount = 0.0;
- if (memStatus==3) {discount = productCharge*goldMem;}
- else if (memStatus==2) {discount = productCharge*silverMem;}
- else if (memStatus==1) {discount = productCharge*bronzeMem;}
- else {discount = baseCharge*noMem;}
- return discount;
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- //define variables
- String custFirst,
- custLast;
- double
- costBook = 0.0,
- baseCharge = 0.0,
- productCharge = 0.0,
- subTotal = 0.0,
- totalTax = 0.0;
- int numEbook = 0,
- memStatus = 0;
- final double tax = 0.055;
- // create a Scanner object to accept keyboard input
- Scanner keyboard = new Scanner(System.in);
- //callculate product charge.
- productCharge = baseCharge+calcServicecharge(costBook,numEbook);
- //subtotal
- subTotal = productCharge-calcDiscount(productCharge,memStatus,baseCharge);
- //get total tax
- totalTax = subTotal*tax;
- System.out.printf("Please enter your first name.");
- custFirst = keyboard.nextLine();
- //get last name
- System.out.printf("Please enter your last name.");
- custLast = keyboard.nextLine();
- //get price
- System.out.printf("Please enter the price of the book");
- costBook = keyboard.nextDouble();
- //get num of books
- System.out.printf("Please enter the number of books you took.");
- numEbook = keyboard.nextInt();
- //membershipstatus
- System.out.printf("Enter your membership Status:\n" +
- "3 represents gold member\n" +
- "2 represents silver member\n" +
- "1 represents bronze member\n" +
- "0 represents nonmember: -->");
- memStatus = keyboard.nextInt();
- //print results.
- System.out.printf("Your base cost is %.2f",calcBasecharge(costBook,numEbook));
- System.out.printf("Your service charge is $%.2f",calcServicecharge(costBook,numEbook));
- System.out.printf("Your Discount is $%.2f",calcDiscount(productCharge,memStatus,baseCharge));
- System.out.printf("Your Subtotal is $%.2f",subTotal);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement