Byron's CSC212 Web Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
Byron's CSC212 Web Site  
 
 
Programming Challenge Archive

General Problems Solving ( Basic Programming Apps )
Coffee Beans
 
 

 
  JavaApplication  -- Coffee Beans

      // General Information
   // ------------------------------------------------------
  
      // File:  CoffeeBeanApp.java
      // Type:  java application file
      // Date:  Wed Sept 20, 2000
      // Name:  Byron Bahr
      // Line:  Compute the cost of coffee beans.
  
      // Application Description
   // ------------------------------------------------------
  
      /*
         Compute the cost of coffee beans
      */
  
      // Required Packages
   // ------------------------------------------------------
  
         import blue.io.*;
  
      //Application Class
   // ------------------------------------------------------
  
      class CoffeeBeanApp
      {
              static public void main (String args[])
        {
           //Calculate the Amount of the Check
           //Use the "Problem Decomposition" Method
           //Determine the cost of the Kona Coffee Beans
  
              double costPerLbKonaBeans = 16.95;
              double lbOfKonaBeans = 4.25;
              double costOfKonaBeans =
               costPerLbKonaBeans * lbOfKonaBeans;
  
           //Determine the Cost of Espresso Coffee Beans
  
              double costPerLbEspressoBeans = 12.25;
              double lbOfEspressoBeans = 5.5;
              double costOfEspressoBeans = 
               costPerLbEspressoBeans * lbOfEspressoBeans;
  
           //Determine the Cost of Colombian Coffee Beans;
  
              double costPerLbColombianBeans = 8.95;
              double lbOfColombianBeans = 9.0;
              double costOfColombianBeans = 
               costPerLbColombianBeans * lbOfColombianBeans;
  
           //Determine Sales Tax on Order
  
              double rateOfSalesTax = 0.07;
              double costOfCoffeeBeans = 
               costOfKonaBeans + 
               costOfEspressoBeans + 
               costOfColombianBeans;
              double salesTaxPaid = 
               rateOfSalesTax * costOfCoffeeBeans;
  
           //Determine Shipping & Handling Charges
  
              double rateOfShippingHandling = 0.50;
              double weightOfCoffeeBeans = 
               lbOfKonaBeans + 
               lbOfEspressoBeans + 
               lbOfColombianBeans;
              double chargesForShippingHandling = 
               rateOfShippingHandling * weightOfCoffeeBeans;
  
           //Determine Amount of Check Due
  
              double totalAmountDue = 
               costOfCoffeeBeans + salesTaxPaid + 
               chargesForShippingHandling;
  
           //Display the Results
  
             IO.print ("The total amount for the bean transac+
   tion is $ ");
             IO.print (totalAmountDue);
             IO.println ();
         }
       }
      //  DEMO
   // ------------------------------------------------------
  
      /*
   The total amount for the bean transaction is $ 244.734875
      */