Overview

In this activity, you will revisit the Paint program from Module Six. Your original program calculated the amount of paint needed, but depending on the width and height, that value could be a long decimal. Your program will better suit the needs of the user if it can calculate the number of cans needed as an integer value. For example, given that 1 gallon = 1 can of paint, we might expect the Paint program from Module Six to output:

Paint needed: 2.142857142857143 gallons
Cans needed: 3.0 can(s)

You might at first think that you could just cast the gallonsPaintNeeded variable from a double to an integer type. However, that would merely cut off the decimal portion of the value, resulting in an underestimate of the number of cans needed. You might also consider rounding the number, but that would not work for the sample output provided above since normal rounding rules would suggest 2.0 cans, an underestimate. So, the computational problem you are faced with is to calculate the number of cans and round up to the nearest whole number. In order to determine if that method for rounding up exists as part of one of Java’s core classes, we need to consult the documentation. There might be a single method that we can use or we might have to use more than one method.

Prompt

For this assignment, you will complete the Paint program by adding code that calculates the number of cans of paint needed. Use the Uploading Files to Eclipse and the Downloading Files From Eclipse tutorials to help you with this project.

  1. Consult the official Java documentation for the Math class.
    1. Scroll to the Method Summary section of the Math class and review the methods and their descriptions. Look for a method that will help you.
    2. If a method looks promising, click on its name to see a more detailed description. Pay special attention to the argument(s) and the data type of the return value.
    3. Based on your review, select one or more methods from the Math class to use in your solution.
    4. When using a method from the Math class, use the syntax Math.methodname() when you implement the method. For example, if you decided to use the absolute value method, you would write something like: Math.abs().
  2. Open the Virtual Lab by clicking on the link in the Virtual Lab Access module. Then open your IDE and upload the Paint2.zip folder. Review the code for the Paint2.java class. Look for where it says //Complete this code block. Make sure the code you write does the following:
    1. Calculates the number of paint cans needed to paint the wall
    2. Rounds up to the nearest integer (use the test cases below to check your work)
    3. Outputs the number of cans needed for the user

    Input:Input:Input:Input:30
    257.5
    22.820
    3525.4
    21.6Output:Output:Output:Output:Paint needed: 2.142857142857143 gallons
    Cans needed: 3.0 can(s)Paint needed: 0.48857142857142855 gallons
    Cans needed: 1.0 can(s)Paint needed: 2.0 gallons
    Cans needed: 2.0 can(s)Paint needed: 1.5675428571428571 gallons
    Cans needed: 2.0 can(s)

Guidelines for Submission

Attach your completed Paint2.java file to the assignment submission page.

Module Seven Assignment Rubric

CriteriaProficient (100%)Needs Improvement (75%)Not Evident (0%)
ValueMethod SelectionSelects a method that appropriately handles all test casesMeets some “Proficient” criteria but with errors, such as not handling all test casesDoes not attempt criterion65Method ImplementationUses the selected method such that the accurate value is calculated and output to the user is correctMeets some “Proficient” criteria, but with errors or exclusionsDoes not attempt criterion35Total:100%

Module Seven Assignment Guidelines and Rubric.html

Overview

In this activity, you will revisit the Paint program from Module Six. Your original program calculated the amount of paint needed, but depending on the width and height, that value could be a long decimal. Your program will better suit the needs of the user if it can calculate the number of cans needed as an integer value. For example, given that 1 gallon = 1 can of paint, we might expect the Paint program from Module Six to output:

Paint needed: 2.142857142857143 gallons Cans needed: 3.0 can(s) You might at first think that you could just cast the gallonsPaintNeeded variable from a double to an integer type. However, that would merely cut off the decimal portion of the value, resulting in an underestimate of the number of cans needed. You might also consider rounding the number, but that would not work for the sample output provided above since normal rounding rules would suggest 2.0 cans, an underestimate. So, the computational problem you are faced with is to calculate the number of cans and round up to the nearest whole number. In order to determine if that method for rounding up exists as part of one of Java’s core classes, we need to consult the documentation. There might be a single method that we can use or we might have to use more than one method.

Prompt

For this assignment, you will complete the Paint program by adding code that calculates the number of cans of paint needed. Use the Uploading Files to Eclipse and the Downloading Files From Eclipse tutorials to help you with this project.

  1. Consult the official Java documentation for the Math class.
  1. Scroll to the Method Summary section of the Math class and review the methods and their descriptions. Look for a method that will help you.
  2. If a method looks promising, click on its name to see a more detailed description. Pay special attention to the argument(s) and the data type of the return value.
  3. Based on your review, select one or more methods from the Math class to use in your solution.
  4. When using a method from the Math class, use the syntax Math.methodname() when you implement the method. For example, if you decided to use the absolute value method, you would write something like: Math.abs().
  1. Open the Virtual Lab by clicking on the link in the Virtual Lab Access module. Then open your IDE and upload the Paint2.zip folder. Review the code for the Paint2.java class. Look for where it says //Complete this code block. Make sure the code you write does the following:
  1. Calculates the number of paint cans needed to paint the wall
  2. Rounds up to the nearest integer (use the test cases below to check your work)
  3. Outputs the number of cans needed for the user
Input: Input: Input: Input:
30 25 7.5 22.8 20 35 25.4 21.6
Output: Output: Output: Output:
Paint needed: 2.142857142857143 gallons Cans needed: 3.0 can(s) Paint needed: 0.48857142857142855 gallons Cans needed: 1.0 can(s) Paint needed: 2.0 gallons Cans needed: 2.0 can(s) Paint needed: 1.5675428571428571 gallons Cans needed: 2.0 can(s)

 

Guidelines for Submission

Attach your completed Paint2.java file to the assignment submission page.

Module Seven Assignment Rubric

Criteria Proficient (100%) Needs Improvement (75%) Not Evident (0%) Value
Method Selection Selects a method that appropriately handles all test cases Meets some “Proficient” criteria but with errors, such as not handling all test cases Does not attempt criterion 65
Method Implementation Uses the selected method such that the accurate value is calculated and output to the user is correct Meets some “Proficient” criteria, but with errors or exclusions Does not attempt criterion 35
Total: 100%

course_documents/Uploading Files to Eclipse Tutorial.pdf

 

 

Uploading Files to Eclipse This tutorial will guide you through the process of uploading a project into Eclipse via the STEM Lab.

1. Open the STEM Lab and select the Launch button for the Java Programming app. The virtual environment can take a couple of minutes to load.

 

2. Once the STEM Lab opens, be sure your browser window is in full-screen mode. Select the

upload icon on the STEM Lab tool bar.

 

3. In the File upload window, select a destination folder by clicking the Upload button. This is where the file will appear when you upload it. For this example, we will select Desktop.

 

4. Next, you are provided with a File Upload dialog box. Navigate to and select the file you want to

upload. Then, click the Open button. In this example, we’ve selected the studentproject.zip file.

 

 

 

 

 

5. Once the file uploads, it will be listed in the File Upload window and in the destination folder you selected. In this example, the studentproject.zip file appears in the File upload window, and the destination folder is the Desktop.

 

 

6. Close the File upload dialog window.

 

 

 

7. Locate the studentproject.zip folder. In this case, it is saved on the Desktop. Right-click on the folder and select Extract All…

 

 

8. This will bring up a dialog box asking you to select a destination for your extracted files. In this example, the default location is the Desktop. Click Extract, which will create an unzipped folder in the destination you have selected.

 

 

 

 

 

9. Next, open Eclipse by double-clicking the Eclipse icon located on the Desktop.

 

10. Select the Launch button in the Eclipse Launcher window to open Eclipse.

 

11. From the File menu, select Open Projects from File System. This will open up a dialog window.

 

 

 

 

12. You will use the Import dialog window to navigate to the project you uploaded. Next to the Import Source text box, click the Directory… button to browse for your project folder.

 

 

13. In the dialog box, navigate to the destination folder where you uploaded your project. In this example, the destination folder is the Desktop. Select your project folder and click the OK button.

 

 

 

 

 

14. After selecting the file to import, you should see the folder’s address in the Import Source textbox. Select the Finish button in the Import dialog window.

 

 

 

 

15. To access the project files, navigate to the Package Explorer workspace. You can view and open your project files in this workspace.

a) In the Package Explorer workspace, click on the arrow next to the project folder to view the

files. In this example, the folder is called studentproject. b) To open your files in the Package Explorer workspace and begin working, double-click on

each class file. Each file will have its own tab, so you can easily switch back and forth between them. Your project is now in Eclipse and ready for you to use!

 

 

 

course_documents/Paint2.zip

Paint2.java

Paint2.java

import  java . util . Scanner ;

public   class   Paint2   {

public   static   void  main ( String []  args )   {

Scanner  scnr  =   new   Scanner ( System . in );
double  wallHeight  =   0.0 ;
double  wallWidth  =   0.0 ;
double  wallArea  =   0.0 ;
double  gallonsPaintNeeded  =   0.0 ;
double  cansNeeded ;

final   double  squareFeetPerGallons  =   350.0 ;
final   double  gallonsPerCan  =   1.0 ;

// Prompt user to input wall's height
System . out . println ( "Enter wall height (feet): " );
wallHeight  =  scnr . nextDouble ();

// Prompt user to input wall's width
System . out . println ( "Enter wall width (feet): " );
wallWidth  =  scnr . nextDouble ();

// Calculate and output wall area
wallArea  =  wallHeight  *  wallWidth ;
System . out . println ( "Wall area:  “ + wallArea + “ square feet" );

// Calculate and output the amount of paint in gallons needed to paint the wall
gallonsPaintNeeded  =  wallArea  /  squareFeetPerGallons ;
System . out . println ( "Paint needed: "   +  gallonsPaintNeeded  +   " gallons" );

// Calculate and output the number of paint cans needed to paint the wall,
// rounded up to nearest integer
// Complete this code block
}

Leave a Reply

Your email address will not be published. Required fields are marked *