katster: (Default)
[personal profile] katster


import keyboardInput.*;
import java.text.DecimalFormat;    

public class Problem8_14
{
  static Keyboard in = new Keyboard();
  static double priceCoff = 1.25;
  static double priceBag = 1.50;
  static double priceDan = 2.25;
  static double percentage = .07;
  static DecimalFormat x = new DecimalFormat("$#0.00");
  
  public static void main(String args[])  
  {
    int quanCoff = howMuchCoffee();
    int quanBag = howManyBagel();
    int quanDan = howManyDanish();
    clearScreen();
    printHead();
    printNew();
    
    double allCoff = calcCoffee(quanCoff, priceCoff);
    printCoffee(quanCoff,allCoff);

    double allBag = calcBagel(quanBag, priceBag);
    printBagel(quanBag,allBag);
    
    double allDan = calcDanish(quanDan, priceDan);
    printDanish(quanDan,allDan);
    printNew();
    double subtotal = calcSub(allCoff, allBag, allDan);
    printSub(subtotal);
    double taxable = calcTax(subtotal, percentage);
    printTax(taxable);
    printNew();
    double total = calcTotal(subtotal, taxable);
    printTotal(total);
  }

  public static void printHead() {
    System.out.println("\tItem\t\tQuantity\tPrice");
    return;
  }
  public static void printNew() {
    System.out.println("\n");
  }
  public static int howMuchCoffee() {
    System.out.print("How many coffees does the customer want? ");
    int amount = in.readInt();
    return amount;
  }
  public static double calcCoffee(int quan, double price) {
    double tot = quan * price;
    return tot;
  }
  public static void printCoffee(int quan, double totlC) {
    System.out.println("\tCoffee\t\t"+ quan + "\t\t" 
                       + x.format(totlC));
    return;
  }
  public static int howManyBagel() {
    System.out.print("How many bagels does the customer want? ");
    int amount = in.readInt();
    return amount;
  }
  public static double calcBagel(int quan, double price) {
    double tot = quan * price;
    return tot;
  }
  public static void printBagel(int quan, double totlB) {
    System.out.println("\tBagels\t\t"+ quan + "\t\t" 
                       + x.format(totlB));
    return;
  }
  public static int howManyDanish() {
    System.out.print("How many danishes does the customer want? ");
    int amount = in.readInt();
    return amount;
  }
  public static double calcDanish(int quan, double price) {
    double tot = quan * price;
    return tot;
  }
  public static void printDanish(int quan, double totlD) {
    System.out.println("\tDanish\t\t"+ quan + "\t\t" 
                       + x.format(totlD));
    return;
  }
  public static double calcSub(double coffee, double bagel, double danish) {
    double subtot = coffee + bagel + danish;
    return subtot;
  }
  public static void printSub(double subtot) {
    System.out.println("\tSub Total\t \t\t" + x.format(subtot));
    return;
  }
  public static double calcTax(double subtot, double percent) {
    double taxes = subtot * percent;
    return taxes;
  }
  public static void printTax(double taxable) {
    System.out.println("\tSales Tax\t \t\t" + x.format(taxable));
    return;
  }
  public static double calcTotal(double subtot, double tax) {
    double tot = subtot + tax;
    return tot;
  }
  public static void printTotal(double tot) {
    System.out.println("\tTotal\t \t\t\t" + x.format(tot));
    return;
  }
  public static void clearScreen() {
    System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
    return;
  }
}//END CLASS
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Note

My main blog is kept at retstak.org. I mirror posts to this Dreamwidth account, so feel free to read and comment either here or there.

November 2020

S M T W T F S
1234 567
891011121314
15161718192021
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 15th, 2026 03:56 pm
Powered by Dreamwidth Studios