Question

Consider the following classes: Dollhouse, Legos, TeddyBear, Toy, ToyBox Which should not be included in a...

Consider the following classes:

Dollhouse, Legos, TeddyBear, Toy, ToyBox

Which should not be included in a class hierarchy?

  

ToyBox

   

Dollhouse

   

TeddyBear

   

Legos

   

Toy

__________________

Questions 6 - 9 Refer to the following code:

public class WhatsIt {
    private int[] values;
    private double average;

    public WhatsIt () {
        values = new int[10];
        findAvg();
    }

    public WhatsIt (int[] n) {
        values = n;
        findAvg();
    }

    public void findAvg () {
        double sum = 0;
        for (int i =  0; i < values.length; i++) {
            sum += values[i];
        }
        average = 1.0 * sum / values.length;
    }

    public String toString() {
        return "Average: " + average + " Length: " + values.length;
    }
}

What does the line findAvg(); in the constructor do?

  

Creates a reference to the average variable.

   

Calls the constructor findAvg; so the object can be created in memory.

   

This call should be removed.

   

Checks to see if the average variable has been initialized.

   

Calls the method findAvg() so the variable average is updated correctly.

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

1) Legos ,Teddy Bear and DollHouse are all kinds of Toys so they should be child of class Toy . ToyBox should not be included in the class hierarchy.

2)The method findAvg() is called so that the variable average gets updated everytime the constructor is called or object is created.

Add a comment
Know the answer?
Add Answer to:
Consider the following classes: Dollhouse, Legos, TeddyBear, Toy, ToyBox Which should not be included in a...
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
  • This is the assignment..... Write a class DataSet that stores a number of values of type...

    This is the assignment..... Write a class DataSet that stores a number of values of type double. Provide a constructor public DataSet(int maxNumberOfValues) and a method public void addValue(double value) that add a value provided there is still room. Provide methods to compute the sum, average, maximum and minimum value. ​This is what I have, its suppose to be using arrays also the double smallest = Double.MAX_VALUE; and double largest = Double.MIN_VALUE;​ are there so I don't need to create...

  • Consider the following class: public class Sequence { private int[] values; public Sequence(int size) { values...

    Consider the following class: public class Sequence { private int[] values; public Sequence(int size) { values = new int[size]; } public void set(int i, int n) { values[i] = n; } public int get(int i) { return values[i]; } public int size() { return values.length; } } Add a method public boolean sameValues(Sequence other) to the Sequence class that checks whether two sequences have the same values in some order, ignoring duplicates. For example, the two sequences 1 4 9...

  • ​I have to create two classes one class that accepts an object, stores the object in...

    ​I have to create two classes one class that accepts an object, stores the object in an array. I have another that has a constructor that creates an object. Here is my first class named "ShoppingList": import java.util.*; public class ShoppingList {    private ShoppingItem [] list;    private int amtItems = 0;       public ShoppingList()    {       list=new ShoppingItem[8];    }       public void add(ShoppingItem item)    {       if(amtItems<8)       {          list[amtItems] = ShoppingItem(item);...

  • I would like help and there are three different classes in the coding.. 14.11 Prog11 Inheritance(PayrollOvertime)...

    I would like help and there are three different classes in the coding.. 14.11 Prog11 Inheritance(PayrollOvertime) Create three files to submit: • Payroll class.java -Base class definition • PayrollOvertime.jave - Derived class definition • ClientClass.java - contains main() method Implement the two user define classes with the following specifications: Payroll class (the base class) (4 pts) • 5 data fields(protected) o String name - Initialized in default constructor to "John Doe" o int ID - Initialized in default constructor to...

  • Download PartiallyFilledArray.java. Though we studied this in class, you should still take several minutes examining the...

    Download PartiallyFilledArray.java. Though we studied this in class, you should still take several minutes examining the code so that you understand the methods of the class. /** * This is a solution to the lab, "partially filled array". * * * */ import java.util.Scanner; public class CalculateAverage { public static void main(String[] args){ PartiallyFilledArray data = new PartiallyFilledArray(); getInput(data); printResults(data); }    private static void getInput(PartiallyFilledArray data) { Scanner kbd = new Scanner(System.in); System.out.print("Enter a number (negative will end input):");...

  • The current code I have is the following: package uml; public class uml {        public...

    The current code I have is the following: package uml; public class uml {        public static void main(String[] args) {              // TODO Auto-generated method stub        } } class Account { private String accountID; public Account(String accountID) { this.accountID = accountID; } public String getAccountID() { return accountID; } public void setAccountID(String accountID) { this.accountID = accountID; } @Override public String toString() { return "Account [accountID=" + accountID + "]"; } } class SuppliesAccount extends Account { private...

  • How to create a constructor that uses parameters from different classes? I have to create a...

    How to create a constructor that uses parameters from different classes? I have to create a constructor for the PrefferedCustomer class that takes parameters(name, address,phone number, customer id, mailing list status, purchase amount) but these parameters are in superclasses Person and Customer. I have to create an object like the example below....... PreferredCustomer preferredcustomer1 = new PreferredCustomer("John Adams", "Los Angeles, CA", "3235331234", 933, true, 400); System.out.println(preferredcustomer1.toString() + "\n"); public class Person { private String name; private String address; private long...

  • I need help finishing one of four classes for a TowerOfHanoi project. The whole project should...

    I need help finishing one of four classes for a TowerOfHanoi project. The whole project should have a Disk class, a Pole class, a TowerOfHanoi class, and a TowerOfHanoi main method. So far, I have finished the Disk class, and I need help completing the Pole class. 1. I need help figuring out how to create a toString() method within that class that will return a text-based 2D graphic of a pole and any existing disks on it. For example:...

  • According to the following information, define Account, CheckingAccount, and TestPart1 classes. 1. Account and CheckingAccount classes...

    According to the following information, define Account, CheckingAccount, and TestPart1 classes. 1. Account and CheckingAccount classes Account - number: int - openDate: String - name: String - balance: double + Account(int, String, String, double) + deposit(double): void + withdraw (double): boolean + transferTo(Account, double): int + toString(): String CheckingAccount + CheckingAccount(int, String, String, double) + transferTo(Account, double): int Given the above UML diagam, define Account and CheckingAccount classes as follow: Account (8 points) • public Account(int nu, String op, String...

  • Write a program to pack boxes with blobs. Write two classes and a driver program. A...

    Write a program to pack boxes with blobs. Write two classes and a driver program. A Blob class implements the following interface. (Defines the following methods.) public interface BlobInterface { /** getWeight accessor method. @return the weight of the blob as a double */ public double getWeight(); /** toString method @return a String showing the weight of the Blob */ public String toString(); } A Blob must be between 1 and 4 pounds, with fractional weights allowed. A default constructor...

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