CSE1020 Labtest 2C

Please read this part carefully

No collaboration is allowed during a labtest. Refrain from speaking with other students during the test. If you have a question, please ask the teaching assistants or the instructor.

In your home directory you will find a copy of your submitted work from Labs 03–06 in the directory unsubmit. You may use pens/pencils and blank sheets of paper. No other aids are allowed.

Your work will be evaluated based on its correctness and conformance to the style rules. Your code must compile to receive a passing grade.

Remember to save your work and submit your work at regular intervals during the test.

APIs

Test Problem 1 of 2

Cut-and-paste the following program into your editor:

import java.io.PrintStream;

public class Test2C
{
   public static void main(String[] args)
   {
      PrintStream out = System.out;
      
      final int START = Integer.parseInt(args[0]);
      final int STOP = Integer.parseInt(args[1]);
      
   }
}


START and STOP are both integer amounts of time in seconds. You may assume that START and STOP are both zero or greater, and that START is smaller than STOP.

Complete the program so that it counts the time up from START to STOP in increments of 1 second, and outputs each increment on a separate line.

For a maximum of 6 out of 10 marks: The output is simply each time increment in seconds; for example, counting up from 0 seconds to 5 seconds (you type in the text in red to run your program, your program outputs the text in black):

java Test2C 0 5
0
1
2
3
4
5


For a maximum of 10 out of 10 marks: The output is formatted like a digital clock showing minutes followed by a colon followed by 2 digits for the seconds. for example, counting up from 0 seconds to 5 seconds:

java Test2C 0 5
0.00
0:01
0:02
0:03
0:04
0:05


and counting up from 598 seconds to 602 seconds

java Test2C 598 602
9:58
9:59
10:00
10:01
10:02
 

Submit

Submit your program using the command:

submit 1020 test02 Test2C.java

 

Test Problem 2 of 2

Cut-and-paste the following program into your editor:

import test2.TestUtility;
import java.io.PrintStream;
import java.util.ArrayList;

public class Test2D
{
   public static void main(String[] args)
   {
      PrintStream out = System.out;
      
      // get and print a random row of a sudoku puzzle
      // ROW is guaranteed to have size equal to 9
      // ROW is guaranteed to only contain digits 1-9
      // ROW might contain repeated digits
      final ArrayList<Integer> ROW = TestUtility.sudokuRow();
      out.println(ROW);
      
      // the number of elements in a row
      final int MAX = 9;
      
   }
}


Sudoku is a popular puzzle game where the player must arrange the numbers 1, 2, 3, 4, 5, 6, 7, 8, 9 on a square grid. One of the rules of sudoku is that no digit may be repeated on any row of the grid. For example, the row

[5, 1, 2, 9, 8, 3, 4, 7, 6]

is legal because no digit is repeated, but the row

[7, 4, 5, 6, 8, 1, 7, 2, 9]

is not legal because the 7 occurs twice. Similarly the row

[8, 5, 5, 5, 5, 8, 8, 8, 8]

is not legal because the 5 occurs four times and the 8 occurs five times (obviously, this player is very bad at sudoku).

For a maximum of 15 out of 20 marks: Complete the program so that it prints true if ROW contains all of the digits from 1 through 9, and false otherwise (if one or more of the digits are repeated). Some examples:

java Test2D
[2, 6, 8, 9, 3, 7, 1, 5, 4]
true

java Test2D
[1, 6, 4, 2, 9, 7, 3, 5, 8]
true

java Test2D
[7, 4, 5, 6, 8, 1, 7, 2, 9]
false

java Test2D
[3, 3, 3, 6, 3, 3, 6, 6, 6]
false


For a maximum of 20 out of 20 marks: Complete the program so that it prints true if ROW contains all of the digits from 1 through 9, and false otherwise (if one or more of the digits are repeated). Also, your program must compute the largest number of repeated digits in ROW; if there are repeated digits, then your program must output the largest number of repeated digits. Some examples:

java Test2D
[2, 6, 8, 9, 3, 7, 1, 5, 4]
true

java Test2D
[1, 6, 4, 2, 9, 7, 3, 5, 8]
true

java Test2D
[7, 4, 5, 6, 8, 1, 7, 2, 9]
false
Maximum repeats: 2

java Test2D
[3, 3, 3, 6, 3, 3, 6, 6, 6]
false
Maximum repeats: 5
 

Here is an explanation of the outputs for the four test cases above (your program should not generate the explanation):

no repeated digits: maximum repeats not output
no repeated digits: maximum repeats not output
7 is repeated 2 times: maximum repeats is 2
3 is repeated 5 times, 6 is repeated 4 times: maximum repeats is 5
 

Submit

Submit your program using the command:

submit 1020 test02 Test2D.java