Public class tictactoeclass public void start string

This preview shows page 9 - 14 out of 22 pages.

public class TicTacToeClass { public void start() { String[] board; for (int i=0; i<9; i++){ board[i] = " "; } } } (2 marks)
Image of page 9

Subscribe to view the full document.

- 10 - COMPSCI 101 Question/Answer Sheet ID: ..................................................................... CONTINUED Question 6 (10 marks) The Tank class keeps track of the amount of petrol in a car’s petrol tank. Any Tank has a capacity – the maximum amount of petrol that fits into the tank. It also has a currentLevel how much petrol is currently in the tank. If the Tank class has been defined correctly, the following code: Tank myTank = new Tank(50); creates a Tank named myTank with a capacity of 50 litres and a currentLevel of 0 litres. You need to complete the following definition of the Tank class, according to the comments that precede each method: public class Tank { private double capacity; private double currentLevel; // constructor of Tank with capacity c // initially with empty tank public Tank(double c) { // complete } // method to add amount litres of petrol to the tank. // If this would cause the capacity to be exceeded, // fill the tank up to its capacity only public void addPetrol(double amount) { // complete } // method to use amount of petrol from the tank, // or if this is more than is currently in the tank, // empties the tank public void usePetrol(double amount) { // complete } } (10 marks)
Image of page 10
- 11 - COMPSCI 101 Question/Answer Sheet ID: ..................................................................... CONTINUED Question 7 (9 marks) a) What is the output when the following code is executed? Point point1 = new Point(10, 20); point1.move(30, 55); System.out.println(point1.x + "," + point1.y); (1.5 marks) b) What is the output when the following code is executed? Point point2 = new Point(10, 12); point2.translate(8, 8); System.out.println(point2.x + "," + point2.y); (1.5 marks) c) What is the output when the following code is executed? Point point1 = new Point(10, 20); point1.x = point1.y; point1.y = point1.x; System.out.println(point1.x + "," + point1.y); (1.5 marks)
Image of page 11

Subscribe to view the full document.

- 12 - COMPSCI 101 Question/Answer Sheet ID: ..................................................................... CONTINUED For the following three parts of this question assume that Point and Rectangle objects have been created as follows: Point point3 = new Point(10, 20); Rectangle rect1 = new Rectangle (100, 192, 20, 30); Rectangle rect2 = new Rectangle (100, 192, 20, 30); d) Complete the Java if...else statement which prints "INSIDE" if point3 is inside rect1 , and prints "NOT INSIDE" otherwise. if ( ) { System.out.println( ); } else { System.out.println( ); } (1.5 marks) e) Complete the Java if...else statement which prints "OVERLAP" if rect1 intersects rect2 , and prints "NO OVERLAP" otherwise. if ( ) { System.out.println( ); } else { System.out.println( ); } (1.5 marks) f) Complete the Java if...else statement which prints "SAME" if rect1 and rect2 represent rectangles at the same x, y position and with the same width and height, and prints "NOT SAME" otherwise. if ( ) { System.out.println( ); } else { System.out.println( ); } (1.5 marks)
Image of page 12
- 13 - COMPSCI 101 Question/Answer Sheet ID: ..................................................................... CONTINUED Question 8 (6 marks) For this question, you need to complete the overlapsAll() method. This method is passed a single Rectangle object, toCheck , and an array of Rectangle objects, rects , as parameters, and should return: true : if ALL the Rectangle objects in the rects array intersect the single Rectangle object, toCheck , false : otherwise.
Image of page 13

Subscribe to view the full document.

Image of page 14
You've reached the end of this preview.
  • Summer '12
  • AdrianaFerraro
  • Computer Science, Following, Christopher Nolan, Tank, public void, JPanel

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern