CSE1020 Labtest 2G

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 test2.TestUtility;
import java.io.PrintStream;
import java.util.ArrayList;

public class Test2G
{
   public static void main(String[] args)
   {
      PrintStream out = System.out;
      
      // get and print a random list of integers
      final ArrayList<Integer> LIST = TestUtility.randomList();
      out.println(LIST);
      
      // the number of elements in the list
      final int N = LIST.size();
      
      // YOUR CODE GOES AFTER HERE

   }
}


Complete the program so that it computes the sum of the elements in LIST. Notice that LIST is already created for you, and already contains N random integers. You MUST NOT assume that N is always the same value for each run of your program.

For a maximum of 7 out of 10 marks: The output is simply the list on one line (already done for you), followed by the sum of the elements on the next line. Some examples (where you type what is in red to run the program, and your program outputs what is in black):

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

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

java Test2G
[5, 6, 7, 6, 6, 6, 6, 6, 3]
51


For a maximum of 10 out of 10 marks: The output shows the list on one line (already done for you), followed by the sum of the first two elements on the next line, followed by the sum of the first three elements on the next line, and so on:

java Test2G
[8, 7, 2, 3, 5, 6, 9, 4, 1]
8 + 7 = 15
8 + 7 + 2 = 17
8 + 7 + 2 + 3 = 20
8 + 7 + 2 + 3 + 5 = 25
8 + 7 + 2 + 3 + 5 + 6 = 31
8 + 7 + 2 + 3 + 5 + 6 + 9 = 40
8 + 7 + 2 + 3 + 5 + 6 + 9 + 4 = 44
8 + 7 + 2 + 3 + 5 + 6 + 9 + 4 + 1 = 45

java Test2G
[3, 5, 7, 6, 9, 2, 4, 1, 8]
3 + 5 = 8
3 + 5 + 7 = 15
3 + 5 + 7 + 6 = 21
3 + 5 + 7 + 6 + 9 = 30
3 + 5 + 7 + 6 + 9 + 2 = 32
3 + 5 + 7 + 6 + 9 + 2 + 4 = 36
3 + 5 + 7 + 6 + 9 + 2 + 4 + 1 = 37
3 + 5 + 7 + 6 + 9 + 2 + 4 + 1 + 8 = 45

java Test2G
[5, 6, 7, 6, 6, 6, 6, 6, 3]
5 + 6 = 11
5 + 6 + 7 = 18
5 + 6 + 7 + 6 = 24
5 + 6 + 7 + 6 + 6 = 30
5 + 6 + 7 + 6 + 6 + 6 = 36
5 + 6 + 7 + 6 + 6 + 6 + 6 = 42
5 + 6 + 7 + 6 + 6 + 6 + 6 + 6 = 48
5 + 6 + 7 + 6 + 6 + 6 + 6 + 6 + 3 = 51
 

Submit

Submit your program using the command:

submit 1020 test02 Test2G.java

 

Test Problem 2 of 2

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

import princeton.introcs.Picture;
import java.awt.Color;
import java.io.PrintStream;

public class Test2H
{
   public static void main(String[] args)
   {
      PrintStream out = System.out;

      // the original picture
      final String FILE = "/cse/course/1020/labtest/tile.png";
      Picture pic = new Picture("tile.png");

      // dimensions of the picture
      final int PIC_WIDTH = pic.width();
      final int PIC_HEIGHT = pic.height();
      
      // the scale factor
      final int F = Integer.parseInt(args[0]);
      
      // the scaled picture
      Picture scaled = new Picture(F * PIC_WIDTH, F * PIC_HEIGHT);


      // YOUR CODE SHOULD BEGIN HERE
      

      // YOUR CODE SHOULD STOP BEFORE HERE
      pic.show();
   }
}


Suppose that you have a digital picture that you want to scale up in size. For example, here is a picture with size 100x100:

 

And here is the picture scaled up in size by a factor of two (both horizontally and vertically):

 

For a maximum of 15 out of 20 marks: Complete the program so that it creates a scaled picture that is two times the size of the original picture. For example

java Test2H 2




For a maximum of 20 out of 20 marks: Complete the program so that it creates a scaled picture that is F times the size of the original picture where you can assume F is an integer value greater than or equal to 1. For example

java Test2H 1




java Test2H 2




java Test2H 3




java Test2H 4


 

Submit

Submit your program using the command:

submit 1020 test02 Test2H.java