CSE 283 Introduction to Object Oriented Design

Barbara Nostrand, Ph.D.


CSE 283 Labs
Welcome to the site for CSE 283 Labs!

 

Lab 3: Projects

Prev | Next | Lab 3

 

Objectives

1. Gain further experience constructing expressions.
2. Gain further experience writing programs.

 

Introduction

Each of the following projects involves the construction of expressions of various types, and so will provide practice in building expressions. Your instructor will tell you which one to do.

Projects

3.1. Finish the lab exercise by completing the remaining experiments.

3.2. Write a program that finds the resistance of an electronic circuit with three parallel resistors resistor1, resistor2, and resistor3. The resistance can be computed using the following formula:

                                   1
   resistance = -------------------------------------- 
                      1            1            1
                 ---------- + ---------- + ----------
                 resistor1    resistor2    resistor3

3.3. The two solutions of a quadratic equation

   y = ax2 + bx + c

can be found using the quadratic formula:

   solution1 = -b + the square root of (b2 - 4ac)
               -----------------------------------
                              2a

and

   solution2 = -b - the square root of (b2 - 4ac)
               -----------------------------------
                              2a

Write a program that inputs values for a, b and c, and outputs the values of solution1 and solution2. Use boolean expressions to print out true/false depending on if

  • a is zero, and
  • the expression (b2 - 4ac) is negative.

3.4.  Write a GUI-based program called Change that,  given the amount of a purchase and the amount received in payment,  computes the change in dollars,  half-dollars,  quarters,  dimes,  nickels and pennies.  You should check input for correct format.  The number should be in decimal without a preceding dollar sign.  However,  you should probably display a dollar sign preceding your text box. 

Remember that floating point numbers may be approximations to the number intended and not exact values.  This can cause small errors in the lowest order digit.  For example,  0.03 can not be exactly represented in binary.  Rather,  the binary expansion of 0.03 is of infinite length much as 1/3 is approximated by 0.333333... in decimal notation.  Floating point representations of positive numbers will generally be less than or equal to their true value.  You can correct this problem by adding a small value which will force the binary representation to be slightly larger than the true value. 

Another problem is caused by entering values with too many digits after the decimal point.  We could simply ignore these small errors,  but we should check user input for correct format before using the input.  Here is a simple program fragment which should give you an idea for how to check a double called value for acceptable U.S. currency values: 

	double value = Double.parseDouble(keyboard.readLine());
	int pennies = (int)(100*value);
	double test = Double.parseDouble(Double.toString(((double)pennies)/100));                       
	screen.println(value);
	screen.println(test);
After completing a transaction,  Change prompts the user for another transaction.  Do not use any conditional staments such as if to compute the change for a transaction. 

Prev | Next | Lab 3

 
  Home

Schedule

Help

Lab 0

Lab 1

Lab 2

Lab 3

Lab 4

Lab 5

Lab 6

Lab 7-8

Lab 9

Lab 10

Lab 11

Lab 12

Lab 13






Last modified: 2007 OCT 28
bnostran@syr.edu