Lab 0: Java Practice

This lab contains some short programs to help you reacquaint yourself with programming in Java. It is due Wednesday at the beginning of class. You are welcome to use your text as a reference (it will be particularly helpful with problem 2).

To turn in: Create a directory called "lab0" inside your submit directory. Copy all of your .java files to this directory.

  1. Write a program that converts from Fahrenheit to Celsius. It should prompt the user for a temperature, and then ask whether the input is in Fahrenheit or Celsius. It should then calculate the temperature for the other scale. The relevant formulae are:

    This program should have two static methods, called FtoC and CtoF that do the conversion, plus a main method which is responsible for taking input from the user.

  2. (L & L 2.13) - Write a Java applet that draws the Olympic Logo. The circles in the logo should be colored (L to R): blue, yellow, black, green, red.
  3. Write a program that creates an array of 50 integers. Use a for loop and an if statement to place a 1 in all cells where the index is even, and a 0 in all cells where the index is odd. (the first index is 0.) For example, a[3] should contain a 0, and a[2] should contain a 1. Print out the array after filling it in.