next up previous
Up: APS105 Home

APS 105 - Computer Fundamentals

Lab #1: Simple Java Programs

Fall 2000

You must submit part 4 by 11:59pm Wednesday, September 20.


Objective
In this lab you will be writing some simple programs in order to get a feel for the language and to become familiar with the JDK. These programs, using variables, arithmetic operators, and predefined methods, will perform input, calculate results using the input, and output these results.


Part 1 -- Basic Output
Write a program that produces the following output, exactly as shown:
Printing some symbols can be tricky
like " or \
Some sequences are also confusing at first
like \n or \f


Part 2 -- Text Patterns
Write a program that prints your first and last initials, each using an array of asterisks of maximum width 5 and height 5. For example, if your initials are J and M, the output might be

      *****    *   *
        *      ** **
        *      * * *
      * *      *   *
       *       *   *


Part 3 -- Calculations
For the programs in this and the next section, you will need to use the Stdin class that can be found in the file

/share/copy/aps105/Stdin.java

You must copy this file to the directory in which you are currently working and compile it there before compiling your program.

Your program should first ask the user to supply a floating point value x of type double and then perform multiple calculations using this single value of x. The program should produce the following output:

(a)
$\sqrt{x}$, rounded to the nearest integer
(b)
$\displaystyle{\left({1\over x^2}\right)^5}$
(c)
$\sin x,$ where x should be in degrees
(d)
$\log x$, rounded to the nearest thousandth


Part 4 -- More Calculations
Write a program that asks for a length of time in hours, reads this value, and then converts this measurement to hours, minutes, and seconds. For example, input of 38.47 should produce output similar to the following:
38.47 hours = 38 hours, 28 minutes, 12 seconds

Do not worry about changing the form of the output if there are zero or one units of any item. For example, output of
1.003 hours = 1 hours, 0 minutes, 11 seconds
is fine.

You must electronically submit this program as your solution to Lab 1. Follow the instructions given in Lab 0, but replace the lab designator `0' with `1'. For example:

        p2.ecf% submitaps105f 1 TimeConversion.java Stdin.java
        p2.ecf% submitaps105f -l 1
        total 8
        -rw-r-----    1 submit   aps105f      2005 Sep 12 17:59 Stdin.java
        -rw-r-----    1 submit   aps105f       759 Sep 12 17:59 TimeConversion.java


next up previous
Up: APS105 Home
Guy G. Lemieux
2000-09-12