Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

TCSS 142 Object-Oriented Programming Winter 2020 - Assignment #2 Due 24 January 2020 Value: 4% of the course grade This assignment uses for loops, static

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

TCSS 142 Object-Oriented Programming Winter 2020 - Assignment #2 Due 24 January 2020 Value: 4% of the course grade This assignment uses for loops, static methods, print/println statements, and a class constant and contributes to the following student learning goal for this course: Develop and implement programs involving the fundamental programming constructs (variables, types, expressions, assignment, simple I/O, conditional and iterative control structures, functions and parameter passing, structured decomposition). XX Write a program to generate the following drawing of a chess king: You are to exactly reproduce this output. This includes ++ having identical characters and spacing. XXXX One way to write a Java program to draw this figure would \ \\##/////// be to write a System.out.println statement to print \ \\\##////// each line of the figure. However, that solution would receive \\\\\##///// \\\\##//// very little credit. A major part of this assignment is the use \\\##/// of for loops. Therefore, in lines that have repeated patterns \\##// of characters that vary in number from line to line, represent \##/ the lines and character patterns using appropriate nested for ## loops. (The complex figure in Chapter 2's case study is a @@@@ partial example of this.) It may help you to write pseudo- ## | ## code and tables to understand the patterns in the output, as ## described in the textbook. ## | ##| Another significant component of this assignment is the task of generalizing the program using a class constant that can be | ## changed to adjust the size of the figure. The section in the ## middle of this output has a height of 8. Some other sections /## have the property that their height is related to the height of //## ///## the middle section and their height determines their width, so ////## there is only one constant needed. /////## The output shown here was produced using a class constant 1/1/7/## 1/11/7/##\\ of value 8. The course web site has a file that shows the ////////##\ expected output with the constant changed to various other I @@@@@@@@@@@@@@@@@@ values. Your program should work for any positive integer constant. ## Submission and Grading: Name your file ChessKing.java and turn it in using the Assignment 1" link on the class web page. Your program will be graded on its "external correctness" (whether the program compiles and produces exactly the expected output) and its "internal correctness" (whether your source code follows the stylistic guidelines specified in this document). Stylistic Guidelines: Use of for loops (nested as appropriate) This program is intended to test your knowledge of Chapters 1 and 2, especially nested for loops. Do not use any programming constructs that are not in chapters 1 and 2 of the textbook. Use of static methods for structure and elimination of redundancy Use static methods to structure your solution. Structure your program in such a way that the methods match the structure of the output itself. Avoid significant redundancy; make sure that no substantial groups of identical printed lines or other groups of identical statements appear in your code. No println statements should appear in your main method. Source code conventions (indentation, identifier names, commenting, etc.) Indent your code consistently as discussed in class. Be consistent with the placement of curly braces. Avoid lines longer than 90 characters in length. Use whitespace between methods to improve readability. Use meaningful method names in mixed case such as 'printTopSection()'; ideally method names should be a verb or verb phrase. Give meaningful names to methods and variables. Follow Java's naming conventions about the format of ClassNames, methodAnd VariableNames, and CONSTANT_NAMES. Localize variables whenever possible, that is, declare them in the smallest scope. The only global (class level) variable allowed in this program is the class constant to represent the size of the drawing. Include a multiline comment at the top of your file, as in: * File Name * TCSS 142 - Assignment 2 After the multiline comment above include a line or two of whitespace, then Include a Javadoc comment just before your class with some basic information and a description of the program, as in: * * This program ... (Describe what the class does, not how it does it.) * @author Your Name @version Some date or number public class MyClassName Include a Javadoc comment at the start of each method to explain the purpose of the method: /** * Explain the method's purpose. (Displays..., Calculates..., etc) public static void myMethodName() { Include a Javadoc comment for the class constant: /** * Explain the purpose of the constant here.. */ public static final int MY_CONSTANT_NAME How to Get Started: This program is best completed in stages. It is strongly recommended that you do not worry about the constant at first. Write an initial version of the program without a constant, focusing on each section of the figure individually. Use loop tables and/or pseudocode, as shown in Chapter 2's case study, to help you deduce the patterns in the output. After your figure looks correct at the default size, begin a second version of your program that adds the constant. See Chapter 2's case study in the textbook for an example of a program that uses a constant to scale the drawing of a complex figure. Extra Credit: This extra credit problem is worth an additional 10% on this assignment. In other words, it is possible to score up to 110% on this assignment if you complete this extra credit. The Fibonacci numbers are a sequence of integers in which the first two elements are 1, and each following element is the sum of the two preceding elements. The mathematical definition of the nth Fibonacci number is the following: F(n)=1 when n= 1 or n = 2 F(n) = F(n-1)+F(n-2) when n > 2 Write a program that uses a for loop to compute and display the first 12 Fibonacci numbers. The output should look like: The first 12 Fibonacci numbers are: 1 1 2 3 5 8 13 21 34 55 89 144 Use a class constant to control the number of Fibonacci numbers which are printed so that you could change the constant to make the program print any amount of Fibonacci numbers. For instance: if you change the class constant to 7, your output should be: The first 7 Fibonacci numbers are: 1 1 2 3 5 8 13 if you change the class constant to 1, your output should be: The first 1 Fibonacci numbers are: 1 if you change the class constant to zero, the output should show an empty list: The first O Fibonacci numbers are: I will not test your program with a negative value for the class constant. Follow the coding conventions defined for the ChessKing.java assignment. Write appropriate comments for your code. Name this program Fibonacci.java and turn it in on the course web site. This file displays valid outputs for Assignment 1 using various constants. For size 1: For size 13: XXXX XX ## l@@@@ | ## /## @@@@ For size 2: ++ XXXX XX 11\##//////////// 11\\##/////////// 111111111\##////////// 11111111\##/IIIIIIII W \\\##//////// 1111\##/////// \ \\\##////// \\\\\##///// \\\\##//// \\\##/// \\##// \##/ | ## @@@@ ##| | ## ## ++ XXXX _XX \##/ ## @@@@ ## /## //## @@@@@@ ## ## ##| For size 3: ## ##1 | ## | ## |## | ## ++ XXXX XX \\##// \##/ ## l@@@@ ## |## | ##| /## //## ///## @@@@@@@@ | ## / ## //## ///## 1 ////## 1 1/17/## 1111 //////## ///////## || ////////##\ /////////##\\\\\\ //////////## ///////////##\\\ 1/17/11/17/## 1 11111111117/## 111 I@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | The assignment instructions show Output for size 8. TCSS 142 Object-Oriented Programming Winter 2020 - Assignment #2 Due 24 January 2020 Value: 4% of the course grade This assignment uses for loops, static methods, print/println statements, and a class constant and contributes to the following student learning goal for this course: Develop and implement programs involving the fundamental programming constructs (variables, types, expressions, assignment, simple I/O, conditional and iterative control structures, functions and parameter passing, structured decomposition). XX Write a program to generate the following drawing of a chess king: You are to exactly reproduce this output. This includes ++ having identical characters and spacing. XXXX One way to write a Java program to draw this figure would \ \\##/////// be to write a System.out.println statement to print \ \\\##////// each line of the figure. However, that solution would receive \\\\\##///// \\\\##//// very little credit. A major part of this assignment is the use \\\##/// of for loops. Therefore, in lines that have repeated patterns \\##// of characters that vary in number from line to line, represent \##/ the lines and character patterns using appropriate nested for ## loops. (The complex figure in Chapter 2's case study is a @@@@ partial example of this.) It may help you to write pseudo- ## | ## code and tables to understand the patterns in the output, as ## described in the textbook. ## | ##| Another significant component of this assignment is the task of generalizing the program using a class constant that can be | ## changed to adjust the size of the figure. The section in the ## middle of this output has a height of 8. Some other sections /## have the property that their height is related to the height of //## ///## the middle section and their height determines their width, so ////## there is only one constant needed. /////## The output shown here was produced using a class constant 1/1/7/## 1/11/7/##\\ of value 8. The course web site has a file that shows the ////////##\ expected output with the constant changed to various other I @@@@@@@@@@@@@@@@@@ values. Your program should work for any positive integer constant. ## Submission and Grading: Name your file ChessKing.java and turn it in using the Assignment 1" link on the class web page. Your program will be graded on its "external correctness" (whether the program compiles and produces exactly the expected output) and its "internal correctness" (whether your source code follows the stylistic guidelines specified in this document). Stylistic Guidelines: Use of for loops (nested as appropriate) This program is intended to test your knowledge of Chapters 1 and 2, especially nested for loops. Do not use any programming constructs that are not in chapters 1 and 2 of the textbook. Use of static methods for structure and elimination of redundancy Use static methods to structure your solution. Structure your program in such a way that the methods match the structure of the output itself. Avoid significant redundancy; make sure that no substantial groups of identical printed lines or other groups of identical statements appear in your code. No println statements should appear in your main method. Source code conventions (indentation, identifier names, commenting, etc.) Indent your code consistently as discussed in class. Be consistent with the placement of curly braces. Avoid lines longer than 90 characters in length. Use whitespace between methods to improve readability. Use meaningful method names in mixed case such as 'printTopSection()'; ideally method names should be a verb or verb phrase. Give meaningful names to methods and variables. Follow Java's naming conventions about the format of ClassNames, methodAnd VariableNames, and CONSTANT_NAMES. Localize variables whenever possible, that is, declare them in the smallest scope. The only global (class level) variable allowed in this program is the class constant to represent the size of the drawing. Include a multiline comment at the top of your file, as in: * File Name * TCSS 142 - Assignment 2 After the multiline comment above include a line or two of whitespace, then Include a Javadoc comment just before your class with some basic information and a description of the program, as in: * * This program ... (Describe what the class does, not how it does it.) * @author Your Name @version Some date or number public class MyClassName Include a Javadoc comment at the start of each method to explain the purpose of the method: /** * Explain the method's purpose. (Displays..., Calculates..., etc) public static void myMethodName() { Include a Javadoc comment for the class constant: /** * Explain the purpose of the constant here.. */ public static final int MY_CONSTANT_NAME How to Get Started: This program is best completed in stages. It is strongly recommended that you do not worry about the constant at first. Write an initial version of the program without a constant, focusing on each section of the figure individually. Use loop tables and/or pseudocode, as shown in Chapter 2's case study, to help you deduce the patterns in the output. After your figure looks correct at the default size, begin a second version of your program that adds the constant. See Chapter 2's case study in the textbook for an example of a program that uses a constant to scale the drawing of a complex figure. Extra Credit: This extra credit problem is worth an additional 10% on this assignment. In other words, it is possible to score up to 110% on this assignment if you complete this extra credit. The Fibonacci numbers are a sequence of integers in which the first two elements are 1, and each following element is the sum of the two preceding elements. The mathematical definition of the nth Fibonacci number is the following: F(n)=1 when n= 1 or n = 2 F(n) = F(n-1)+F(n-2) when n > 2 Write a program that uses a for loop to compute and display the first 12 Fibonacci numbers. The output should look like: The first 12 Fibonacci numbers are: 1 1 2 3 5 8 13 21 34 55 89 144 Use a class constant to control the number of Fibonacci numbers which are printed so that you could change the constant to make the program print any amount of Fibonacci numbers. For instance: if you change the class constant to 7, your output should be: The first 7 Fibonacci numbers are: 1 1 2 3 5 8 13 if you change the class constant to 1, your output should be: The first 1 Fibonacci numbers are: 1 if you change the class constant to zero, the output should show an empty list: The first O Fibonacci numbers are: I will not test your program with a negative value for the class constant. Follow the coding conventions defined for the ChessKing.java assignment. Write appropriate comments for your code. Name this program Fibonacci.java and turn it in on the course web site. This file displays valid outputs for Assignment 1 using various constants. For size 1: For size 13: XXXX XX ## l@@@@ | ## /## @@@@ For size 2: ++ XXXX XX 11\##//////////// 11\\##/////////// 111111111\##////////// 11111111\##/IIIIIIII W \\\##//////// 1111\##/////// \ \\\##////// \\\\\##///// \\\\##//// \\\##/// \\##// \##/ | ## @@@@ ##| | ## ## ++ XXXX _XX \##/ ## @@@@ ## /## //## @@@@@@ ## ## ##| For size 3: ## ##1 | ## | ## |## | ## ++ XXXX XX \\##// \##/ ## l@@@@ ## |## | ##| /## //## ///## @@@@@@@@ | ## / ## //## ///## 1 ////## 1 1/17/## 1111 //////## ///////## || ////////##\ /////////##\\\\\\ //////////## ///////////##\\\ 1/17/11/17/## 1 11111111117/## 111 I@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | The assignment instructions show Output for size 8

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions

Question

Different formulas for mathematical core areas.

Answered: 1 week ago