Starting from:
$30

$24

Assignment 7 Solution

Preparation




Read Lesson 6



Read text ch 6 and section 3.8. Here are some notes to help you get through the chapter 6 reading. I've classified each section as either "skip", "important", "critical", or "REALLY critical".



6.1: skip




6.2: critical. However, I find the first paragraph of 6.2 and Software Engineering Observation 1 to be confusing. I would skip them and just start with the paragraph right after Software Engineering Observation 1, which starts with the word "Methods".




6.3: important. However, it may be helpful to realize that it is NOT the math methods and constants that are important, but rather the concepts that are being demonstrated (static methods, static variables, the "final" keyword). Don't worry if 6.3 seems a little abstract at this point. Just read it lightly and make a note to yourself to come back to this section when you find you need to use these concepts in a program.




6.4 and 6.5: critical. After reading 6.5 you might want to go back and try 6.3 again.




6.6: skip




6.7: important. It is a technical detail, but you need to know it.




6.8: skip




6.9 and 6.10: important. However, I won't hold you responsible for enum types.




6.11: REALLY critical.




6.12: important.




6.13: skip







For Credit




Assignment 7.1 [15 points]




Complete all of the MyProgrammingLab exercises for chapter 6.




Assignment 7.2 [40 points]




This program is broken down into two phases for your convenience only. Please turn in only your final product.




Phase 1:Write a program that draws a rocket on the screen. Here's what the rocket should look like:




*

* *

* *

*****

* *

* *

* *

* *

*****

*****

* *

* *

* *

* *

*****

*

* *

* *







Your main method in phase 1 must look like this:




public static void main(String[] args) {

drawCone();

drawBox();
drawBox();

drawCone();

}




You may simply use three println() statements (no loops are necessary) in your drawCone() method. For your




drawBox() method, you must use the drawHorizontalLine(), draw2VerticalLines(), and drawOneRow() methods exactly as they appear in lesson 6. For phase 1 you'll be using the versions from lesson 6.3




Phase 2:In this phase you will allow the user to specify three things:




the height of each stage



the width of each stage
how many stages in the rocket



[A "stage" in your rocket is one rectangle. The example rocket above has a stage-height of 6, a stage-width of 5, and the number of stages is 2.]




Your main method in phase 2 must look like this:




public static void main(String[] args) {

<6 statements to prompt for and read the stage-height, stage-width, and number of stages.




drawRocket(<arguments);

}




You must still use the drawHorizontalLine(), draw2VerticalLines(), and drawOneRow() methods exactly as they appear in lesson 6. For phase 2 you'll be using the versions from lesson 6.6.




Notice that if you run the program and choose a different width for your stages, the cone won't really fit correctly anymore. I won't make you fix this, but you can fix it for 5 points of extra credit if you like. However, I will not help you with the extra credit. In order to get the extra credit, the number of rows of your cone must be equal to the width of the stages divided by 2 (plus 1 for odd widths). If the stage width is an even number, your cone must have two stars in the top row instead of one. If you do this perfectly and use good decomposition in the process you'll get 5 extra credit points.




Please make sure to place a detailed comment above each of your method definitions, use good decomposition, and separate your methods with at least 6 blank lines. I suggest that now would be a good time to reread the Style Conventions section of the Syllabus.




Assignment 7.3 [40 points]




Look at Exercises 24 and 25 on page 239. Create a class MyMath with a static method isPerfect() and a static method isPrime(). Each method has a int parameter and returns a boolean value. Create an application MyMathTest that displays a menu allowing the user to choose whether to display the prime numbers 1- 1000, display the perfect numbers 1-10,000, or quit. Be sure to clearly label the output. Output the prime numbers 10 to a line. Use dialog boxes for ALL input and output.




Submit Your Work




Execute your program from assignment 7.2 and copy/paste the output into the bottom of the source code file, making it into a comment. A single output is sufficient, unless you do the extra credit, in which case you should show examples of both even and odd cone widths. Send an email to ta.sanmateo@gmail.com with the subject "CIS 254 a7". Attach your source code files from assignments 7.2 and 7.3 to the email. In the body of the email let me know whether the programs work as required.




Keep in mind that if your code does not compile you will receive a 0.




Note that the gmail email account is for homework submission only. The account is not monitored for any other purpose.

Assignment 7.4 [5 points]




Participate in the assignment 7 discussion. This could involve asking a question, answering another student's question, giving an example of something that you struggled with and then overcame (or didn't!), giving an example of something you found particularly cool, or any other constructive way you can think of to participate.

More products