Return to Jeff's Main Page

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
My Intro to Object-Oriented Programming  
 
 
Programming Challenge Archive

Programming Assignment # 1
Coffee Beans
 
Coffee beans are to be ordered from a particular company.   Determine the total costs of the coffee bean order given a certain quantity and unit price for the coffee beans,  sales tax,  and shipping and handling charges.   The types of beans to be ordered are:   Kona Beans,  Espresso Beans,  and Columbian beans.  

 
  JavaApplication - Programming Assignment # 1  -- Coffee Beans

   // General Information
   // ---------------------------------------------------
  
   // File:  CoffeeBeansApp.java
   // Type:  java application file
   // Date:  Sat Sep 16, 2000
   // Name:  Jeffrey R. Norkoli
   // Line:  Determine costs to order coffee beans by mail
  
   // Application Description
   // ---------------------------------------------------
  
   /*
      Coffee beans are to be ordered from a particular 
      company.  Determine the total costs of the coffee 
      bean order given a certain quantity and unit price 
      for the coffee beans, sales tax, and shipping and
      handling charges.  The types of beans to be ordered 
      are:  Kona Beans, Espresso Beans, and Columbian 
      beans.
   */
  
   // Required Packages
   // ---------------------------------------------------
  
      import blue.io.*;
      import blue.math.*;
  
  
   // Application Class
   // ---------------------------------------------------
  
      class CoffeeBeansApp
      {
         static public void main (String args[])
         {
     // Compute the material cost of the Kona 
     // Beans given a quantity (lbs) and  unit 
     // price.
     double quantityKoBeans = 4.25;
     double unitCostKoBeans = 16.95;
     double materialCostKoBeans = quantityKoBeans 
         * unitCostKoBeans;
  
     // Compute the material cost of the 
     // Espresso Beans.
     double quantityEspBeans = 5.5;
     double unitCostEspBeans = 12.25;
     double materialCostEspBeans = quantityEspBeans 
         * unitCostEspBeans;
  
     // Compute the material cost of the 
     // Columbian Beans.
     double quantityColBeans = 9.0;
     double unitCostColBeans = 8.95;
     double materialCostColBeans = quantityColBeans 
         * unitCostColBeans;
  
     // Compute the total material cost of the
     // various beans.
     double materialCostAllBeans = materialCostKoBeans 
         + materialCostEspBeans + materialCostColBeans;
  
     // Compute the sales tax.
     double salesTaxRate = 0.07;
     double totalSalesTax = salesTaxRate 
         * materialCostAllBeans; 
  
     // Compute the shipping & handling charges.
     double shippingHandlingRate = 0.50;
     double quantityOfBeans = quantityKoBeans 
         + quantityEspBeans + quantityColBeans;
     double totalShippingHandling = shippingHandlingRate 
         * quantityOfBeans;
  
     // Compute total cost of order.
     double costOfBeanOrder = materialCostAllBeans
         + totalSalesTax + totalShippingHandling;
  
     // Display result.
     IO.println ("The total amount for the bean 
                 transaction is $" + costOfBeanOrder + ".");
    
         }
      }
  
   // Demo
   // ---------------------------------------------------
  
   /*
   $ javac CoffeeBeansApp.java
   $ java CoffeeBeansApp
   The total amount for the bean transaction is $244.734875.
   $ 
   */