Class Program1


  • public class Program1
    extends Object
    Question 1. Basic Java [27 marks]

    (a) [4 marks] Writing methods.

    Complete the method myMethod(...) below so that printStuff() prints out the example given below.

    printing stuff x=5 y=9 z=45 z=14

    (b) [6 marks] Calling methods on objects.

    Given the Circle class, complete the useCircle() method below so that it: - makes a green circle at (100,150) with a size of 20 - makes a red circle at (150, 200) with a size of 15 - draws both circles on the screen - makes the first circle grow 3 times - makes second circle grow 2 times - shrinks the first circle 10 pixels - shrinks the second circle 2 pixels

    (c) [8 marks] Arrays

    Complete the sumArray() method below so that it adds up all the numbers in the nums array (when testing your code, check that the answer is 27).

    (d) [9 marks] ArrayLists

    Complete the countNegatives() method below so that it counts and prints the number of negative values that appear in the ArrayList of Doubles.

    For example, if the user enters "-1 8.8 -2.1 0 9 2 5", it should print "There were 2 negative numbers."

    • Constructor Summary

      Constructors 
      Constructor Description
      Program1()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void averageArray()
      (c) Complete this method so that it calculates the average of all the numbers in the nums array.
      void countPositives()
      (d) Complete this method so that it counts and prints the number of positive values that appear in the ArrayList of Doubles stored in nums.
      static void main​(String[] args)  
      void printStuff()
      (a).
      void setupGUI()
      YOU CAN IGNORE EVERYTHING BELOW THIS LINE *
      void useCircle()
      (b) Complete this method so that it: - makes a blue circle at (250,100) with a size of 35 - makes a green circle at (75, 300) with a size of 20 - draws both circles on the screen - makes the first circle grow 2 times - makes the second circle grow 3 times - shrinks the first circle 20 pixels - shrinks the second circle 12 pixels
    • Constructor Detail

      • Program1

        public Program1()
    • Method Detail

      • printStuff

        public void printStuff()
        (a). Calls myMethod(...) and prints things out.

        DO NOT CHANGE THIS METHOD.

        Use this to test that your method works correctly.

      • useCircle

        public void useCircle()
        (b) Complete this method so that it: - makes a blue circle at (250,100) with a size of 35 - makes a green circle at (75, 300) with a size of 20 - draws both circles on the screen - makes the first circle grow 2 times - makes the second circle grow 3 times - shrinks the first circle 20 pixels - shrinks the second circle 12 pixels
      • averageArray

        public void averageArray()
        (c) Complete this method so that it calculates the average of all the numbers in the nums array. ( when testing your code, check that the answer is 3.375 ).
      • countPositives

        public void countPositives()
        (d) Complete this method so that it counts and prints the number of positive values that appear in the ArrayList of Doubles stored in nums.

        For example, if the user enters "-1 8.8 -2.1 0 9 2 5", it should print "There were 4 positive numbers." ( Zero is not positive or negative for the purposes of this question )

      • setupGUI

        public void setupGUI()
        YOU CAN IGNORE EVERYTHING BELOW THIS LINE *
      • main

        public static void main​(String[] args)