Assignment
Goals
This lab is focused on gaining experience with variables, assignment statements, basic arithmetic, and console output. There will also be some time devoted to basic error correction.
For this lab, name your project FNameLName_Lab1. For example, if you were me, your project would be ThomasBolinger_Lab1
Part 1 (8 pts) Pattern Print
(a) Create a Java class named PatternPrint
(b) Store the pattern in a variable of type String. Make sure to give the variable a good name!
(c) The pattern should be made of the whitespace character (a press of the spacebar), the *, the \n (newline), and maybe the \t (tab) character. It may be useful to use string concatenation using the + sign.
(d) Use a single print statement to print the pattern.
(e) Use an int variable and assign it the value of your favorite number, then print the following message two spaces below the pattern:
This program was created by . My favorite number is .
Replace and appropriately. Number must be from the favorite number variable defined above.
Part 2
LandCalculation
(a) Make a class called LandCalculation
(b) Declare the following variables: area: an int holding the square footage 534,521 acres: a double that will hold the acreage
(c) Declare a constant, CONVERSION, to store the conversion factor between square feet to acres. There are 43,560 square feet in one acre. Think about unit changing in math and physics as a hint.
(d) Print out the results, such that it looks like:
The area of the land in square feet is: square feet The area of the land in acres is: acres
(e) Now we will try to use DecimalFormat! a. Declare DecimalFormatdf; Eclipse will complain and tell you that your program is missing an import. Use the auto correct to import DecimalFormat. b. Use the following line of code to finish your declaration: df = new DecimalFormat("##.000"); c. Use df.format(acres) to print out the results from c again, this time with a formatted acres value d. Finally, change your DecimalFormat object. Use df = new DecimalFormat() and set up the object such that it features 5 decimal places, not 3, and only if they aren't 0s. Remember # is used for non-zero numbers, as we discussed during lecture.
Print the output one last time with the new Decimal Format object you created.
Part 3
For this part of the lab, edit Part 1. These edits are to be temporary
. Make an edit, try and run the code, and then report on whether the edit succeeded or failed by writing a comment. If the code doesn't run, be sure to include a small description of the error that kept the code from running.
a. Delete the keyword void from the main method b. Change ‘main' to ‘starting' c. Change the data type of number from int to Integer d. Change the ‘args' in main to a different name e. Change all () to {} f. Replace a semicolon, ‘;' with a colon, ‘:' g. Change println to printf
Format your assignment according to the following formatting requirements:
1. The answer should be typed, double spaced, using Times New Roman font (size 12), with one-inch margins on all sides.
2. The response also include a cover page containing the title of the assignment, the student's name, the course title, and the date. The cover page is not included in the required page length.
3. Also Include a reference page. The Citations and references should follow APA format. The reference page is not included in the required page length.