CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
CS1 Course Site  
 
 
Programming Challenge Archive

General Problems Solving
Coffee Beans
 
The Problem :   From a particular coffee company i wish to order,  by mail,  4.25 punds of Kona beans at 16.95 per pound,  5.5 pounds of Espresso Beans at 12.25 per pound,  and 9 pounds of Colombian Beans at 8.95 per pound.   Sales tax is 7 percent.   Shipping and handling charges are 50 cents per pound.   How much should I write my check out for?  

 
  JavaApplication  -- Coffee Beans

   // General Information
   // ---------------------------------------------------
  
   // File:  CoffeeBeansApp.java
   // Type:  java application file
   // Date:  Wed Sep 13, 2000
   // Name:  James W. Bremenou
   // Line:  Calculates a payment for coffee beans purchase
  
   // Application Description
   // ---------------------------------------------------
  
   /*
      This program will calculate a value, for a costomer
      to write on a check, that will cover the costs of 
      a coffee beans purchase.
   */
  
   // Required Packages
   // ---------------------------------------------------
  
      import blue.io.*;
  
   // Application Class
   // ---------------------------------------------------
  
      class CoffeeBeansApp
      {
         static public void main (String args[])
         {
         // Introduce Coffee Bean amounts & costs
     double lbsKonaBeans = 4.25;
     double costPerKonaLbs = 16.95;
     double lbsXpsoBeans = 5.5;
     double costPerXpsoLbs = 12.25;
     double lbsClmbBeans = 9.0;
     double costPerClmbLbs = 8.95;
     double shippingCost = 
         (lbsKonaBeans + lbsXpsoBeans 
          + lbsClmbBeans) * 0.50;
         // Calculate cost for brand of beans
     double konaCost = 
         (costPerKonaLbs * lbsKonaBeans);
     double xpsoCost = 
         (costPerXpsoLbs * lbsXpsoBeans);
     double clmbCost = 
         (costPerClmbLbs * lbsClmbBeans);
         // Calculate cost for all beans
     double totalBeanCost = 
         (konaCost + xpsoCost + clmbCost);
         // Calculate sales tax
     double salesTax = (totalBeanCost * 0.07);
         // Add sales tax, and shipping costs
     double checkAmount = 
         (totalBeanCost + salesTax) 
         + shippingCost;
         // Display amount to be written on check
     IO.print("Write your check out for:   ");
     IO.print("$" + checkAmount);
     IO.println();
         }
      }
  
   // Demo
   // ---------------------------------------------------
  
   /*
   rocky - bremenou - cbeans > java CoffeeBeansApp
   Write your check out for:   $244.734875
   rocky - bremenou - cbeans > 
   */