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
  • 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...

  • 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. 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...

  • Please help me to answer the 5 programming questions and give some specific explanations, thanks a...

    Please help me to answer the 5 programming questions and give some specific explanations, thanks a lot !!! Question Consider a class hierarchy that includes a class called Creature, with subclasses called Unicorn and Dragon. The Creature class has a method called feelsLike, Not yet answered which is overridden in the Unicorn and Dragon class. Marked out of The feelsLike method of the Creature class returns "smooth", while the feelsLike method is overridden in the Unicorn class to return "fluffy"...

  • 1.The following statement gets an element from position 4 in an array named myArray: x =...

    1.The following statement gets an element from position 4 in an array named myArray: x = myArray[4]; What is the equivalent operation using an array list named list.? A x = list.get(); B x = list.get(4); C x = list.get[4]; D x = list[4]; 2.Consider the following code snippet: ArrayList<Integer> num1 = new ArrayList<Integer>(); int data; Scanner in = new Scanner(System.in); for (int i = 0; i < 5; i++) { data = in.nextInt(); num1.add(data); if (data == 0 &&...

  • need some help on these a little contested right now the answers i have are 18...

    need some help on these a little contested right now the answers i have are 18 : d 19 : e 20 : c would appriacte why i am right or wrong thank you sorry i added the picture of 17 by mistake 19. The default constructor sets x and y to (0,0) by calling the second constructor. What could be used to replace / missing code */ so that this works as intended? a b = = 0; 0;...

  • QUESTION 3 Assume x = 4 and y = 5, which of the following is true?...

    QUESTION 3 Assume x = 4 and y = 5, which of the following is true? x < 5 || y < 5 x > 5 || y > 5 x < 5 && y < 5 x > 5 && y > 5 QUESTION 14 Which of the following statements are the same? (A) x -= x + 4 (B) x = x + 4 - x (C) x = x - (x + 4) (A) and (B) are...

  • Question 1 Not yet answered Marked out of 1.00 Flag question Question text Which of the...

    Question 1 Not yet answered Marked out of 1.00 Flag question Question text Which of the following keywords is useful for skipping to the next iteration of a loop? Select one: a. do b. break c. switch d. continue e. while Clear my choice Question 2 Not yet answered Marked out of 1.00 Flag question Question text Consider the following line of Java code. System.out.println("Hello, World!"); "out" is which of the following? Select one: a. a statement b. a class...

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
ADVERTISEMENT