CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
CS1 Course Site  
 
 
Programming Challenge Archive

General Problems Solving
Coffee Beans
 
 

 
  JavaApplication  -- CoffeeBean

   // General Information
   // ---------------------------------------------------
  
   // File:  >CoffeeBeansApp>.java
   // Type:  java application file
   // Date:  Mon Sep 18, 2000
   // Name:  
   // Line:  
  
   // Application Description
   // ---------------------------------------------------
  
   /*
        or to purchase vario    us types of beans using the given +
   information.>
   */
  
   // Required Packages
   // ---------------------------------------------------
  
   import blue.io.*;
  
  
   // Application Class
   // ---------------------------------------------------
  
   class CoffeeBeanApp
   {
       static public void main (String args[])
       {
   //Determine the cost of kona beans.
   double costPerPoundOfKonaBeans = 16.95;
   double nrKonaBeans = 4.25;
   double konaBeanCost = costPerPoundOfKonaBeans * nrKonaBea+
   ns;
   //Determine the cost of the espresso beans.
   double costPerPoundOfEspressoBeans = 12.25;
   double nrEspressoBeans = 5.5;
   double espressoBeanCost = costPerPoundOfEspressoBeans * n+
   rEspressoBeans;
   //Determine the cost of colombian beans.
   double costPerPoundOfColombianBeans = 8.95;
   double nrColombianBeans = 9.0;
   double colombianBeanCost = costPerPoundOfColombianBeans *+
    nrColombianBeans;
   //Determine the subtotal.
   double subTotal = konaBeanCost + espressoBeanCost + colom+
   bianBeanCost;
   //Determine the sales tax.
   double salesTax = 0.07;
   double costSalesTax = subTotal * salesTax;
   //Determine shipping and handling charges.
   double shipAndHand = 0.50;
   double costShipAndHand = shipAndHand * (nrKonaBeans + nrE+
   spressoBeans + nrColombianBeans);
   //Determine the total cost.
   double totalCost = subTotal + costShipAndHand + costSales+
   Tax;
   //Display the result.
   IO.print("The total amount for the bean transaction is ")+
   ;
   IO.print(totalCost);
   IO.println();
  
       }
   }
  
   // Demo
   // ---------------------------------------------------
  
   /* 
   $ javac CoffeeBeanApp.java
   $ java CoffeeBeanApp
   The total amount for the bean transaction is 244.734875
   $
   */