Fund. CS II (CS152 2006S)

Homework 5: A One-Line Calculator

Assigned: Wednesday, February 8, 2006
Due: 8:00 a.m., Friday, February 10, 2006

Summary: In this assignment, you will write a very simple calculator.

Purpose: To give you an opportunity to explore issues of numbers in strings, particular with regards to input, output, and simple calculation.

Contents:

The Assignment

Write a program that reads a one line arithmetic operation of the form

number operation number

and prints out the result.

You can choose whether to use BigInteger or BigDecimal values.

You can require that there be a space between the numbers and the operand.

A Sample Session

Expression: 23 * 13
23 * 13 = 299

Hints

You create a BigInteger from a string with the constructor which takes a string as a parameter. For example,

BigInteger leftOperand;
leftOperand = new BigInteger(exp.substring(0,exp.indexOf(" ")));

Submitting Your Work

When you are satisfied with your work, you should email me the program.

Questions

When you ask questions, I'll try to put the answers here.

 

History

Monday, 6 February 2006 [Samuel A. Rebelsky]

 

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Tue May 9 08:31:08 2006.
The source to the document was last modified on Wed Feb 8 08:39:39 2006.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS152/2006S/Homework/hw.05.html.

You may wish to validate this document's HTML ; Valid CSS! ; Check with Bobby

Samuel A. Rebelsky, rebelsky@grinnell.edu