|
Fundamental Programming Concepts
Summer 2000 |
|
Overview | |
Warning: this lab is more difficult than the first two
labs. You will need to read it carefully -- preferably away from the
keyboard -- before you begin programming. This is the level of difficulty
that you can expect from future labs in the course.
This lab will introduce almost nothing new about Java. Instead, it will give you a chance to practice and develop the programming skills we've been working on so far:
You may find it useful in this lab, and future labs, to change the font that the Metrowerks editor uses. To change it to a much more usable font:
|
|
Part I: Producing a Bill | |
The Cayuga Carpet Company has asked you to write a computer program to calculate the amount a customer should be charged and produce a bill for the customer. You will call this project CarpetBill. The input will be:
The output will be a bill stating:
The company has given you the following information to help in writing the program:
Here is an example of how one run of the program might occur:
Formatting Monetary Amounts for OutputThe following method will change a monetary amount stored in a double into a String that is suitable for being printed to the screen: /** * Yield a string containing the amount in the argument formatted * as currency in the default locale. */ static String formatCurrency(double amount) { return java.text.NumberFormat.getCurrencyInstance().format(amount); } Here's an example of how to use it: double price = 1.00; System.out.println("Price of an item from a dollar store = " + formatCurrency(price)); Additional RequirementsIn order to give you more practice with certain aspects of variables, and to introduce you to a common framework for programs, your main method must be divided into sections as follows (although your exact comments need not be identical to those shown below): public static void main(String[] args) { ///////////////////////////////////////////////////////////////// // Variable declarations ///////////////////////////////////////////////////////////////// ... ///////////////////////////////////////////////////////////////// // Get all the input ///////////////////////////////////////////////////////////////// ... ///////////////////////////////////////////////////////////////// // Calculate bill ///////////////////////////////////////////////////////////////// ... ///////////////////////////////////////////////////////////////// // Output bill ///////////////////////////////////////////////////////////////// ... } Follow these guidelines:
The rationale for these restrictions is twofold:
|
|
Part II: Solving Systems of Equations | |
Write a program that will solve a system of two equations
using Cramer's Rule. The input will be the coefficients and constants in
the system -- these will all be integers. The output will be the solution
to the system. You will call this project EquationSolver.
As an example, here is how one run of the program might occur:
Cramer's RuleCramer's Rule is a method for solving a system of linear equations. If you have two equations with variables x and y written as: ax + by = c then the solution for x and y can be found using the following equations: For help on the math notation used here, see this explanation. Important: Cramer's rule will not work if the expression (ae - bd) is equal to zero! We'll soon learn how to have the program guard against this possibility. You don't have to worry about it for now, though -- just avoid giving your program such inputs. Additional Requirements
|
|
Submitting | |
You should submit the entire folder containing your
project for both of the programs in this lab.
Your folders should contain at least the following files:
You will submit your lab using FTP, not on a floppy. Follow these instructions to use FTP. Don't forget to include a comment at the beginning of each of your classes, similar to Lab 1. Also, make sure to follow the style guidelines for all your variables and methods. |