Copy the directory Lab03 from /home/student/Classes/Cs241/Labs to your account. If you have forgotten how to do this, refer to the steps in Lab01.
Change directories into Lab03 and start BlueJ by entering bluej&.
When you studied geometry you learned how to calculate the area of different geometric shapes. Your instructor found several at this website:
Area formulas (found at: www.math.com/tables/geometry/areas.htm)
These are not written in Java (yet). It takes a little thought to "translate" them, since you can't just copy them directly. One can think of a mathematical formula as a simple algorithm. It contains all the information you need to write a program to calculate it.
Open the project called Calculations and open the editor for the AreaFormulas class. This program looks similar to one of the early versions of the ComputeArea class shown in your textbook. In the comments, it describes what kind of steps need to be coded. By the time you are finished, it should ask for the necessary input values, do the proper calculations for each type of geometric figure's area, and display the results.
Remember, if you need to take the square root of a number, such as 18.2, you have to write
double answer = Math.sqrt(18.2);
Once written, you will also need to test your program. Work with your partner to think of some sample values to try. If you wish to try them in a calculator, you can reach one from the left side of the upper panel on your lab account desktop. Choose Applications-Accessories-Calculator to use it.
Use the comments you see to guide you while you write the code. Write the related code directly below the comment that describes it.
1 Demonstrate your AreaFormulas program with your test data. Be prepared to answer the following questions:A couple of operators you will probably use quite frequently (once we learn about loops) are the ++ (sometimes called "auto-increment") and -- (sometimes called "auto-decrement") operators. They can be quite tricky! The key to using them is to isolate the operator in a single statement. However, it is also important to realize what can happen when they are NOT used in isolation.
Still within the Calculations project, open the IncrDecr class in the editor. This class has some simple and some sample trick statements using ++ and --.
Compile and run the program as it looks now. What do you see printed? Is the effect of the pre- and post- versions the same or different? For this class, we are looking for side effects. Remember, a side effect occurs when more than one variable changes its value in a single assignment statement.
You must have noticed that the trick statements are only in comment form. To see what happens when they run, work with your partner to do the following:
Remember to switch which partner is at the keyboard.
Open the project called ConvertFromSeconds. This project contains a class named SecondsConvert which is supposed to take a total number of seconds and break it into minutes and seconds. But - a lot of the code is missing!
Review the comments to see how the steps are organized. Work with your partner to fill in the missing code. Use Divide (/) and Modulus (%) appropriately as you separate the minutes and seconds. Think about 3 test cases you can try to check your work.
3 Show us that the SecondsConvert program works. Be prepared to answer the following questions:
Switch which partner is working at the keyboard before you continue.
Create a new class named CountSeconds. In this class, write a main method to work backwards from the previous program. In other words, you'll combine days, hours, minutes and seconds and sum up total seconds. Note: The conversion is going in the opposite direction of the previous program. You will need to ask the user for four different input numbers: days, hours, minutes and seconds. To make the task a bit more interesting, allow the user to enter seconds with a decimal point and display an answer that contains total seconds (including a decimal point).
4 Show us that your program runs. Be prepared to answer the following questions:
As usual, time to switch keyboard control with your partner for this exercise.
Create a new class named DivideMod which will do the following:
Original number: 27 Divisor: 12 number / divisor: 2 number mod divisor: 3
5 Show us that your program runs correctly, displaying the test values above plus 2 other tests. Be prepared to answer the following questions: