Course Hero Logo
Question
Answered step-by-step

ASSIGNMENT 3 CCCS 300, Winter 2022 See MyCourses Please read the...

ASSIGNMENT 3

CCCS 300, Winter 2022

See MyCourses

Please read the entire PDF before starting. You must do this assignment individually.

It is very important that you follow the directions as closely as possible. The directions, while perhaps tedious, are designed to make it as easy as possible for the TAs to mark the assignments by letting them run your assignment, in some cases through automated tests. While these tests will never be used to determine your entire grade, they speed up the process significantly, which allows the TAs to provide better feedback and not waste time on administrative details.

Up to 30% can be removed for bad indentation of your code as well as omitting comments, or poor coding structure.

To get full marks, you must:

  • Follow all directions below
    • In particular, make sure that all classes and method names are spelled and capitalized exactly as described in this document. Otherwise, you will receive a 50% penalty.
  • Make sure that your code compiles
    • Non-compiling code will receive a 0.
  • Write your name and student ID as a comment in all .java files you hand in
  • Indent your code properly
  • Name your variables appropriately
    • The purpose of each variable should be obvious from the name
  • Comment your work
    • A comment every line is not needed, but there should be enough comments to fully understand your program

1

Part 1 (0 points): Warm-up

Do NOT submit this part, as it will not be graded. However, doing these exercises might help you to do the second part of the assignment, which will be graded. If you have difficulties with the questions of Part 1, then we suggest that you consult the TAs during their office hours; they can help you and work with you through the warm-up questions. You are responsible for knowing all of the material in these questions.

Warm-up Question 1          (0 points)

Create a method to print the the following image. This method must have one parameter, which is the length of the sides in number of *'s. This method should use only two for loops, and use if statements within the for loops to decide whether to draw a space or a star. You can assume the parameter is an odd number.

Draw the outline of a square as follows:

 

N.B. It is normal that the square does not appear to be a perfect square on screen as the width and the length of the characters are not equal.

Warm-up Question 2          (0 points)

Change the method you just created to have two parameters, so that you can create rectangles. The first parameter will be the height of the rectangle, and the second parameter will be the width of the rectangle.

Warm-up Question 3          (0 points)

Write a program to display the (x,y) coordinates up to (9,9) of the upper right quadrant of a Cartesian plane. As in the previous warm-up question, your solution should use two nested for loops. Your program should also display the axes, by checking to see if the x-coordinate is zero or if the y-coordinate is zero. Note that when both the x and y coordinates are zero, you should print a + character.

For example, the output of your code should look like:

 

Note that in the above image, all of the coordinates containing 0's are not displayed, since we are printing axes instead.

Warm-up Question 4          (0 points)

Write a method generateRandomArray() that takes as input an integer n and returns an array of size

n. The elements of the array should be random doubles between 0 (included) and 5 (excluded). You can use Math.random() to do this.

Warm-up Question 5          (0 points)

Write a method getLargestElement() that takes an array of integers as input and returns the largest element inside the array. For example, if the input is: int[] arr= {1, 5, -3, 15, 4}; then getLargestElement(arr) should return 15.

Warm-up Question 6          (0 points)

Write a method getSum() that takes an array of integers as input and returns the sum of all the elements inside the array. For example, if the input is:

int[] arr= {1, 5,-3, 15, 4}; 

then getSum(arr) should return 22.

Warm-up Question 7          (0 points)

Write a method countNegatives() that takes an array of integers as input and returns the number of negative numbers inside the array. For example, if the input is:

int[] arr= {1,5,-3, 15, -13}; 

then countNegative(arr) should return 2.

Warm-up Question 8          (0 points)

Write a method getVowels() that takes a String as input and returns an array characters containing all the vowels from the given string. For example, if the input is:

String s = "kangaroo"; 

then getVowels(s) should return {'a', 'a', 'o', 'o'}.

Warm-up Question 9          (0 points)

Create a file called Counting.java, and in this file, declare a class called Counting. This class should ask the user when the computer should stop counting.

When should I stop counting to?

10 <---- User typed this

I am counting until 10: 1 2 3 4 5 6 7 8 9 10

Warm-up Question 10          (0 points)

For this question you have to generalize the last question. The user will give you the number they want the computer to count up to and the step by which it will do so.

When should I stop counting to?

25 <----

Which step should I use?

3 <----

I am counting to 25 with a step of 3:

1 4 7 10 13 16 19 22 25


 

 

Part 2

The questions in this part of the assignment will be graded.

First, you should download the attached java files to this assignment from MyCourses.

Question 1: ArraySum            (30 points)

 

1a) Method to transform a number of an array

In ArraySum calss, write a method called transform that receives an integer number and transforms it to an integer array such that the array elements are digits of input integer number. 

 

For example: 

int [] transform(1234) should return the integer array [1, 2, 3, 4]

 

1b) Method to compute the sum of two arrays that represent a very big number.

In ArraySum class, write a method called sum that receives two integer arrays of equal size (each of these arrays is created by transformmethod) and returns an array of integer digits that corresponds to the sum.

 

Algorithm for sum function: In math, we first add digits at the rightmost index "i".  If result of "digits addition" is greater than 9 then, we have a carry that needs to be added to digits at index "i-1" location, and so on, to complete addition digit by digit.

 

Example:

transform(1234) -> a which is [1, 2, 3, 4]

transform(1211) -> b which is [1, 2, 1, 1]

sum(a, b) -> [2,4,4,5]

 

transform(9295) -> x which is [9, 2, 9, 5]

sum(a, x) -> [1,0,5,2,9]

 


 

 

 

Question 2: TMax            (40 points)

 

2a) Generate a random array

In TMax.java, complete the getRandomArray() method that is responsible to generate a one dimensional random array with the size of a random number between 2 and 10. Then populate the Array with some random real values from [0, 1].

Note: you can set the seed by using the args in the main method.

 

Output examples:

The output results might be varied depends on the seed that you are using. 

getRandomArray() -> [0.123, 0.235, 0.3573, 0.657] getRandomArray()     ->       [0.067, 0.235, 0.657]

 

2b) Find the third biggest number in the array

Then, complete thirdBiggest(int[] array). This method should accept an array that we generated above and return the third biggest number in this array. When array has only two numbers then the function should return bigger of these two.

 

Test case 1:

a -> [0.123, 0.235, 0.3573, 0.657] thirdBiggest(a) -> 0.235 

 

Test case 2:

a -> [0.067, 0.235] 

thirdBiggest(a) -> 0.235

 


 

 

Question 3: Rotate a 2D Array     (30 points)

In Rotate.java, complete the method of rotate180. The method receives a 2D array of integers and rotates the given 2D array in 1800 degrees (clockwise). 

 

Assume matrix "a" represent a 2D array as follows: 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

 

 

 

 

 

 

 

 

After running the rotate180(a) the matrix should be changed (in-place) such that it has 180 degrees rotation of elements.

Therefore, after running rotate180(a) the matrix "a" will change to the following matrix:

25

24

23

22

21

20

19

18

17

16

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

 

 

 

 

 

 

 

 

 

 

 

Answer & Explanation
Verified Solved by verified expert
<p>e vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna.</p> Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet

Unlock full access to Course Hero

Explore over 16 million step-by-step answers from our library

Subscribe to view answer

elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet.

gue

amet, co

ctum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibu

gue

iscing elit

ng elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices a

gue

gue

sum dolor sit amet, consectetur adipiscing elit. Nam lacin

or nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec fac
Step-by-step explanation
  • congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit a
  • e vel laoreet ac, disus ante, dapibunec facilisi, dictum vicongue velm ipsipsum dolor siitur lentesque dapibus efficitur laitur lng elit. Nam lacinia pulvinar tortor nec fusceu
  • a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tor
  • dictum vitae odio. Donec aliquet. Loreacinia pulviscing elit. Nam lacinia pulvinar tort
  • 28407778

    Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

    at, ultric

1 Attachment
image.png
png