Assignment-01a

 

 

 

Foreword

Resources

Code Listings

Foil Sets

Assignments

Solutions

External Resources

SiteMap

Search

Home

Up ] [ Assignment-01a ] Assignment-01b ] Assignment-01c ] Assignment-01d ] Assignment-02 ] Assignment-02a ] Assignment-03 ] Assignment-03a ] Assignment-03b ] Assignment-03c ] Assignment-03d ] Assignment-04 ] Assignment-04a ] Assignment-04b ] Assignment-05 ] Assignment-06 ] Assignment-07 ]

There are two types of Java programs: applications and applets. An applet is a web-based Java program embedded in an HTML document. An application, on the other hand, is not web-based. It is developed and run at the command line, much like a C program.

Your first Java programming assignment is to write a small application. Before starting this assignment, you should become familiar with the Java programming environment on osprey7.

Note: You may use Java compilers on other systems if your prefer, or a programming environment such as J++ or Cafe'. For these initial programming assignments, a JDK1.0 compiler is o.k.; later you must use JDK1.1, which is what we have on osprey7.

    Problem 1

    1. Write a Java application that inputs a series of ten single-digit integers as characters, and then prints the two largest values entered. Note: Each number may be input only once.
    2. This is exercise 2.17 on page 115 of the textbook Java How to Program.
    3. On the NPAC Java resources page, you may download any examples to help you. In particular, you may choose to use System.in.read to read a single character from the input, or you may download the Console.java class.
    4. The code should be neatly written, easy to read, and well documented. Programs that are difficult to read or understand will lose points!
    5. Submit your assignment by linking the Java source code to your homework page.
    6. Extra Credit: Modify the program so that it accepts an arbitrary number of single-digit integers by terminating the input when the user presses return in reponse to the input prompt.

    Problem 2

    1. Write a Java application that calculates the value of the constant PI from the infinite series:

      4 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 + . . .

      Print a table that show the value of PI approximated by 1 term of this series, by two terms, and so on. Observe how many terms you have to use before you get 3.14, 3.141, 3.1415, 3.14159.

    2. This is problem 3.17 on page 163 of the text.