Question
The project name of this exercise is LetterSize . The purpose of this assignment is for you to write more of your own javadoc comments
The project name of this exercise is LetterSize.
The purpose of this assignment is for you to write more of your own javadoc comments and to use constants in your program.
Problem Description
Write a program that will create a LetterSize object. You specify the objects width and height in the constructor in inches. You can then call accessor methods that give you the width and height in millimeters. You will also write test code (in your Program.java) that will test the case for a letter that has the dimensions of 8.5 x 11 inches. Be sure to print it out so that there are two numbers after the decimal point for the conversions.
Hints:
- There are 25.4 millimeters per inch.
- You can use
printf
to format the output for two digits. Here is an example for using printf(). If you have n = 15.451217 and you use printf("%.4f" , n); it will display only 4 digits to the right of the decimal (15.4512).
Getting Started
Like our last exercise, we are going to do this exercise by writing the object that solves the problem first (in a source file called LetterSize.java) and then testing it using code we write into Program.java. Using the techniques shown on the web page titled "How to Start Every Project in this Class" create a source file called LetterSize.java as well as a file called Program.java.
Open up the LetterSize.java file and replace the code with the code contained in the box below:
package edu.sbcc.cs105; /** * This class converts the size of letters. * */ public class LetterSize { public LetterSize(double widthInInches, double heightInInches) { } public double getWidthInMillimeters() { } public double getHeightInMillimeters() { } }
In this case you'll notice that not only do we have a code skeleton but the methods don't have any documentation. You'll have to add the proper Javadoc documentation as well as the proper code to solve the problem. You will have to add instance variables, a constant, and code to get this class defined properly. Read the comments (and the assignment) to understand what the problem is and how you will solve it.
Replace the code in your Program.java file with the code in the grey box below:
package edu.sbcc.cs105; /** * This class tests the LetterSize object. * */ public class Program { public static void main(String[] args) { // TODO Test the LetterSize class by creating an 8.5 x 11 inch // letter and getting the size in millimeters. } }
You will also notice that Program.java does not contain any code to test the LetterSize.java source code. Write some test routines based upon the problem description.
Once you've written your code run the code by single clicking on Program.java in the package explorer and selecting Run->Run from the menu or using the keyboard shortcut. Examine the output. Does it do what you want? If not, how can you modify the code to do what you want?
Using the Unit Test
Next, we are going to use the unit test to test your code. You are supposed to use this unit test after you have written (and passed) the test code that you have written in Program.java.
Download the unit test file from canvas. It should be called LetterSizeTester.java and is located right underneath this assignment. Once downloaded, single-click on the unittest.cs105 package and then right-click and select Import... Unlike other imports the import source this time is File System. Navigate to the directory where you downloaded LetterSizeTester.java and select it. You should see a list of things to import appear. Check the checkbox next to LetterSizeTester.java and press Finish.LetterSizeTester.java should appear in the unittest.cs105 package. Now select the new tester file and run, what are your results?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started