Overview
This lab gives you practice writing user-defined Java methods.
- Correct Javadoc header comments, including Java Class name, description, @author and @version tags.
- Correct Javadoc method comments, including a description of what it does, along with @param and @args as appropriate.
- A comment at the end of each import line, indicating why you need to import that class. For example:
import javax.swing.* // for JOptionPane methods
LEGEND: Keyboard Screen
Task 1: ShowChar
(From Task 5.1) Create a Java main class called ShowChar, with a method named showChar. The method should accept two arguments: a String object and an integer. The integer argument is a character position within the String, with the first position being 0. When the method executes, it should check to make sure the position number is valid for the String given (i.e., that it's in the right range), and then display the character at that position. If the position is out of range, the showChar method should say so.
Use this ShowChar main method to test your showChar method.
Task 2: AreaRectangle
Use the code provided in AreaRectangle as the starting point for a program that asks the user to enter width and length of a rectangle, and then displays the rectangle's area. The program calls the following methods, which have not been written:
- getLength -- asks user to enter rectangle's length, and returns the value as a double.
- getWidth -- asks user to enter rectangle's width, and returns the value as a double.
- getArea -- accepts two doubles representing length and width as arguments, and then calculates and returns the rectangles area (width * length)
- displayData -- accepts length, width, and area as arguments, and displays them in an appropriate message on the screen.
Task 3: TempConverter
Write a Java program named TempConverter that prompts the user for a temperature, then for a scale (fahrenheit or celsius) and responds by displaying the equivalent temperature in the other scale. You should write the following two methods:
- fahrenheitToCelsius() -- takes a double as an argument representing a fahrenheit temperature, and returns the celsius equivalent as a double.
- celsiusToFahrenheit() -- takes a double as an argument representing a celsius temperature, and returns the fahrenheit equivalent as a double.
Some notes to follow:
- User interaction should be via javax.swing methods .
- When the user enters a scale, accept anything starting with 'f' or 'F' as fahrenheit; and anthing starting with 'c' or 'C' as celsius.
- Use a loop to repeat the interaction.
- Stop looping when the user just hits <Enter> for either entry ( hint: you can test something like userInput.length()==0 )
- User input should be through JOptionPane. Output should be to the console using System.out.
- Print appropriate messages at the beginning and end.
Welcome to TempConverter!
32 degrees Fahrenheit == 0 degrees Celsius
212 degrees Fahrenheit == 100 degrees Celsius
32 degrees Celsius == 89.6 degrees Fahrenheit
Goodbye!
