Question

1 Suppose you are designing a set of classes intended to represent a solar system and...

1 Suppose you are designing a set of classes intended to represent a solar system and the planets and comets within it.

Which of the following class structures is a correct representation?

 public class Comet {
        ...
    }

    public class Planet {
        ...
    }

    public class SolarSystem extends Planet {
        ArrayList <Comet> comets;
    ...
    }
public class Planet {
        ...
    }

    public class Comet {
        ...
    }

    public class SolarSystem {
        ArrayList <Planet> planets;
        ArrayList <Comet> comets;
           ...
    }
 public class Comet {
        ...
    }

    public class SolarSystem extends Planet {
        ...
    }

    public class Planet {
        ArrayList <Comet> comets;
        ArrayList <SolarSystem> system;
        ...
    }
public class SolarSystem {
        ...
    }

    public class Planet extends SolarSystem {
        ...
    }

    public class Comet extends SolarSystem {
        ...
    }
public class SolarSystem {
    ...
    }

    public class Planet extends SolarSystem {
        ...
    }

    public class Comet extends Planet {
        ...
    }

Flag this Question

Question 21 pts

Consider the following classes.

    public abstract class Insect {
        public void move() {
            ...
        }
        
        ...
    }

    public class Butterfly extends Insect {
        public void move() {
            super.move();
            ...
        }
        ...
    }

Which of the following is a true statement?

The code works as intended.

The code will not compile because Insect is abstract.

The code will not compile because super can only be used in the constructor.

The code will not work because of infinite recursion.

The code will not compile because the super.move() should be this.move().

Flag this Question

Question 31 pts

The following code is intended to test if x and y are equal.

    int x = 2;
    int y = 2;
     
    if (x = y) {
        x++;
    }

Which of the following best describes why the code will not run?

It does not run as intended due to a logic error.

The code runs as intended.

It does not run as intended due to roundoff error.

It does not run as intended due to a run time error.

It does not run as intended due to a compile time error.

Flag this Question

Question 41 pts

Consider the following code.

    interface Vehicle {
        public int getNumWheels();
    }

    public class Scooter implements Vehicle {
        int numWheels;

        public Scooter (int w) {
            numWheels = w;
        }
        ...
    }

For a variable of the class Scooter to be instantiated which of the following must be true?

Scooter must implement a method called getNumWheels.

Scooter must have a default constructor Scooter().

Nothing, Scooter can be instantiated with no changes.

Vehicle must implement a method called getNumWheels.

Scooter must call the constructor in Vehicle.

Flag this Question

Question 51 pts

Consider the following code segment.

    int x = 15;
    int y = 0;
    if (y != 0 && x / y > .5) {
        ...
    }

Which of the following describes the behavior of the code?

Due to short circuit evaluation the x/y > .5 is never reached.

The code will trigger a compile time possible loss of precision error.

Precedence rules mean the x / y is never reached.

Because the x and y are ints the x / y will return a 0, making the if false.

The code will trigger a Divide by Zero ArithmeticException when the code is run.

Flag this Question

Question 61 pts

A cow is an animal, and a farm houses many animals including cows.

Which of the following would be an appropriate set of classes?

public class Animal extends Cow {
        /* code not shown */
    }

    public class Farm {
        ArrayList <Cow> farmAnimals;
        /* code not shown */
    }
 public class Cow extends Animal {
        /* code not shown */
    }

    public class Farm {
        ArrayList <Animal> farmAnimals;
        /* code not shown */
    }
 public class Cow extends Farm {
        /* code not shown */
    }

    public class Animal {
        ArrayList <Cow> farmAnimals;
        /* code not shown */
    }
public class Cow {
        /* code not shown */
    }

    public class Farm extends Animal {
        ArrayList <Cow> farmAnimals;
        /* code not shown */
    }
 public class Cow extends Animal {
        /* code not shown */
    }

    public class Farm {
        ArrayList <Cow> farmAnimals;
        /* code not shown */
    }

Flag this Question

Question 71 pts

The following code is intended to test if x and y are equal.

    int x = 2;
    int y = 2;
      
    if (x != y) {
        x++;
    }

Which of the following best describes why the code will not run as intended?

It does not run as intended due to a run time error.

It does not run as intended due to a logic error.

It does not run as intended due to a compile time error.

It does not run as intended due to roundoff error.

The code runs as intended.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)

public class Planet {
        ...
    }

    public class Comet {
        ...
    }

    public class SolarSystem {
        ArrayList <Planet> planets;
        ArrayList <Comet> comets;
           ...
    }

___________________________

21)

The code works as intended.

___________________________

31)

It does not run as intended due to a compile time error.

___________________________

41)

Ans) Scooter must implement a method called getNumWheels.

___________________________

51)

Ans) Due to short circuit evaluation the x/y > .5 is never reached.

___________________________

61)

Ans)

 public class Cow extends Animal {
        /* code not shown */
    }

    public class Farm {
        ArrayList <Animal> farmAnimals;
        /* code not shown */
    }

__________________________

71)

Ans) It does not run as intended due to a logic error.

_________________________Thank You

Add a comment
Know the answer?
Add Answer to:
1 Suppose you are designing a set of classes intended to represent a solar system and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • QUESTION 1 If we run the following code: A a = new A(1); B b =...

    QUESTION 1 If we run the following code: A a = new A(1); B b = new B(2); System.out.println(b); Select all of the following pieces of code that would compile and run with no errors, printing the value of 1 followed by the value of 2, each on separate lines. A. public class A {     private int y;     public A(int y) {         this.y = y;     }     public int getY() {         return y;     }...

  • 1. What is output by the following code: ArrayList< Integer > a = new ArrayList< Integer...

    1. What is output by the following code: ArrayList< Integer > a = new ArrayList< Integer >(); ArrayList b = a; a.add(new Integer(4)); b.add(new Integer(5)); a.add(new Integer(6)); a.add(new Integer(7)); System.out.println(b.size()); A)1 B)2 C)3 D)4 E)5 2. Assume the Student and Employee classes each extend the Person class. The Student class overrides the getMoney method in the Person class. Consider the following code:     Person p1, p2, p3;     int m1, m2, m3;     p1 = new Person();     m1 = p1.getMoney();     // assignment 1...

  • Question 1 Consider the following code snippet: public class Box<E> { private E data; public Box()...

    Question 1 Consider the following code snippet: public class Box<E> { private E data; public Box() { . . . } public void insert(E value) { . . . } public E getData() { . . . } } What will result from executing the following code? Box<String> box = new Box<>(); . . . box.insert("blue Box"); String b = box.getData(); A.   run-time error B.   compiler warning C.   no error D.   compiler error Question 2 What is used as a...

  • please help Question 2 (1 point) Saved Choose the option that best describes what happens when...

    please help Question 2 (1 point) Saved Choose the option that best describes what happens when the bolded println() statement is executed: public class Point { public static void main(String[] args) { Point p 1 = new Point(3, 4); System.out.println(p1); } public int x, y; public Point(int xx, int yy) { x = xx; y = yy; } سی Point inherited a toString() method, which is called internally by println(). This is a compile error - println doesn't know how...

  • The Bike and EBike classes are implemented as shown by the code below. public class Bike...

    The Bike and EBike classes are implemented as shown by the code below. public class Bike { private String make; private int numGears; private double tirePressure; public Bike(String m, int g, double t) { make = m; numGears = g; tirePressure = t; } public void pumpTire() { tirePressure += 5.0; } } public class EBike extends Bike { private int batteryLevel; public EBike(String m, int g, double t, int b) { super(m, g, t); batteryLevel = b; } public...

  • java This lab is intended to give you practice creating a class with a constructor method,...

    java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...

  • 1. Create two directories from a DOS or Unix prompt. Name one directory 'RMILabServer' and the...

    1. Create two directories from a DOS or Unix prompt. Name one directory 'RMILabServer' and the other directory 'RMILabClient'. 2. Within the server directory, save the following three classes. //************************************************************ // Calculator.java Interface for a Calculator import java.rmi.*; public interface Calculator extends Remote { // this method will be called from remote clients int add (int x, int y) throws RemoteException; } //************************************************************* // CalculatorServant.java // A Remote object class that implements Calculator. import java.rmi.*; import java.rmi.server.UnicastRemoteObject; public class CalculatorServant...

  • ******Java Programming Hi guys, I really need you help. I created a code for my java...

    ******Java Programming Hi guys, I really need you help. I created a code for my java course, but it keep giving me error messages. Majority of my code is fine but some keep display error on my console. I was hoping someone could pin points the problem. .There are three classes with the testCenter class being the main class. In the following is the assignment, and the bottom is my code. Please help! Assignment: Concepts: GUI User Design Graphics Deployment...

  • 1. Which of the following statements is true? I. When an object is serialized, all of...

    1. Which of the following statements is true? I. When an object is serialized, all of its data attributes are always serialized. II. When an object is serialized, its methods are not serialized. III. The Serializable interface does not declare any abstract methods. Select one: A. I only B. II only C. III only D. I and II only E. II and III only 2. For the code below, and assuming widget.dat exists, which of the following statements are false?...

  • 1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System....

    1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System.out.println("test"); } } 1. The code compiles but will not print anything since t does not invoke the run method. 2. The code will not compile since you cannot invoke "this" in a static method. 3. The program compiles, runs, and prints tests on the console. 2. What will the following example...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT