CIS 357 Assignment 1

Ratings: 1 Star2 Stars3 Stars4 Stars5 Stars (4.00 out of 5) - Rate Now!
Loading...

Download Category: ,

homework1.zip - (110.58 KB)
[
homework1/.classpath
homework1/.project
homework1/homework1.class
homework1/homework1.java
homework1/Position.class
homework1/Question.txt
homework1/Screenshot_1.png
]

CIS 357 Assignment 1

Refer to problem 8.19 in page 314 – 315. Name your program to Homework1.java.

In addition to the given problem in the textbook, you want to provide the following additional methods:

public static int[][] generate2DArray(int row, int col)
public static void minimumConsecutiveSum(int[][] values, int num)
public static void testWithFixedValues()
public static void testWithRandomValues()

• generate2DArray() generates a two dimensional array (row X col) with array element values ranging between 0 and 9. Use the random number generator.
• minimumConsecutiveSum() finds the num consecutive numbers either horizontally, vertically, or diagonally, whose sum is minimum
• testWithFixedValues() tests the program with 6 x 7 array and fixed values of elements. Use the first array shown above. It needs to call minimumConsecutiveSum(4) to find the minimum sum of consecutive 4 numbers.
• testWithRandomValues() tests the program with number of rows and columns entered by the user. It calls generate2DArray() to generate a random 2D array. Make sure that the number of rows and columns entered by the user are greater than 4 and less than 11. It asks the user to enter num which is between 3 and 5 to find the minimum consecutive sum.
• you can add more methods if the length of any method exceeds 60 lines of code.
Ask the user for fixed value testing or random value testing. The following shows a sample output. Note that the bold face is used to indicate user input.
> java Homework1-LastName
Enter a choice: (1 for fixed value, 2 for random values) 1
Consecutive four: found ([5,0] – [5,3]) ([0,6] – [3,6]) ([3,2] – [0,5])
0 1 0 3 1 4 1
0 1 6 8 4 0 1
5 6 2 4 8 2 1
6 5 4 1 1 9 1
1 3 6 1 4 0 7
3 3 3 3 4 0 7

Minimum of consecutive four: 4 ([0,6] – [3,6])

> java Homework1-LastName
Enter a choice: (1 for fixed value, 2 for random values) 2
Enter row and column: 7 7
Consecutive four: not found
0 1 0 3 1 6 1
0 1 6 8 6 0 1
5 6 2 4 8 2 9
6 5 6 1 1 9 1 <== Note: your array element values should look different 1 3 6 1 4 0 7 3 3 3 2 4 0 7 1 1 1 2 1 1 3 Enter consecutive number (3, 4, 5): 6 Enter consecutive number (3, 4, 5): 3 Minimum sum of consecutive three: 3 ([6,0] – [6,2]) > java Homework1-LastName
Enter a choice: (1 for fixed value, 2 for random values) 3
Wrong input. Try again!

Enter a choice: (1 for fixed value, 2 for random values) 2
Enter row and column: 4 5
Consecutive four: found ([0,3] – [3,3])
0 1 0 2 1
0 1 6 2 6
5 6 2 2 8 <== Note: your array element values should look different 6 1 1 2 1 Enter consecutive number: 3 Minimum sum of consecutive three: 18 ([0,3] – [1,2]) • Provide four more outputs for random value test with the size of 7x9, 9x9, 10x10, and 5x10 arrays. Important Notes and Requirements: ? Use the Scanner class for the user input. ? Format your code nicely (indenting, layout, etc.) and be sure to use Javadoc comments to explain your code where appropriate. Minimally you should provide a program description with homework title, your name, course, instructor, date and a brief description at the beginning of your program, and method description as shown: // homework1: ... // Name: // Course, semester: // Instructor: // Date finished: // Program description: public class Homework1LastName { ... /** * method description for main */ public void static main(String[] args) { ... } /** * method description for ... */ ... } ? Your output should also be nicely formatted. ? Follow the Java convention to get a full credit. • Start a class name with a capital letter • Start a variable name with a lower case letter • Use descriptive name for the class, variable, member data, and member function. • Be consistent in formatting and indenting your code. Refer to code layout provided in the textbook. ? Modularize your code. If you have a method that contains more than 60 lines of code, there will be a deduction, up to 5%. You can use multiple classes if you want, but it is not required. You can use static functions. ? Do not use packages. If you do, you will get a 3 point deduction. If your IDE automatically added a package name, remove them before submitting them. ? Program that does not compile will not get more than 40 point. ? Program without proper description/comments will lose up to 10 point ? Codes with poor and inconsistent layout will lose up to 5 point ? You can follow the code layout from the codes in the textbook. You can also use the pretty print feature in Eclipse (CTRL + SHIFT + F) to format your codes. ? Use Courier New font or type face font to print your code ? (bonus 10pt) Support warp around feature. That is, Refer to the following code for random number generation by using the Random class. The seed value used is 1, but you can use different values to generate different sequence of random numbers. However, be sure to use 1 for your submitted code. import java.util.Random; public class RandomDemo { public static void main(String[] args) { Random rand = new Random(1); // seed is 1 for (int i = 0; i < 10; i++) System.out.println(rand.nextInt(10)); } }

Get a fresh solution of this question. Ask it now to our experts.
doubt

Ask Your Question

We have verified professionals who are ready to answer your question.

time

Save Time and Money

We choose experts who can quickly answer your question and that suit your budget.

download

Get Your Answer

Your satisfaction is 100% guaranteed. You can keep on asking questions until you get the answer you need.