Explain why the given class hierarchy is not reasonable

Assignment Help JAVA Programming
Reference no: EM131184407

Instructions

For problems 1 through 4, explain why the code as shown is almost certainly not what the programmer intended, and how it should be fixed to work the way the programmer probably had in mind.

1. What is wrong with the following program and how should it be fixed?

1 publicclass MyClassA {
2 int v = 12;
3
4 public MyClassA (int pV) {
5 v = pV;
6 }
7
8 publicstaticvoid main (String args []) {
9 MyClassA m = new MyClassA ();
10 } // end main
11 } // end class MyClassA

2. What is wrong with the following program and how should it be fixed?

1 publicclass MyClassB {

2 int v = 12;

3

4 publicvoid MyClassB (int pV) {

5 v = pV;

6 }

7

8 publicstaticvoid main (String args []) {

9 MyClassB m = new MyClassB (23);

10 } // end main

11 } // end class MyClassB

3. What is wrong with the following program and how should it be fixed?

1 publicclass MyClassD {

2 publicstaticvoid main (String args []) {

3 MyClassC m = new MyClassC (23);

4 } // end main

5 } // end class MyClassD

6

7 class MyClassC {

8 int v = 12;

9

10 public MyClassC (int pV) {

11 int v = pV;

12 }

13

14 } // end class MyClassC

4. What is wrong with the following program and how should it be fixed?

1 publicclass MyClassE {

2 publicstaticvoid main (String args []) {

3 MyClassF m = new MyClassF (23);

4 } // end main

5 } // end class MyClassE

6

7 class MyClassF {

8 int v = 12;

9

10 private MyClassF (int pV) {

11 v = pV;

12 }

13

14 } // end class MyClassF

5. Given all the problems identified in problems 1 through 4, explain in detail why the following code works, ie, compiles without errors or warnings.

1 publicclass MyClassG {

2 publicstaticvoid main (String args []) {

3 MyClassH m = new MyClassH (23, true);

4 } // end main

5 } // end class MyClassG

6

7 class MyClassH {

8 int v = 12;

9

10 public MyClassH (int x, boolean b) {

11 this (x);

12 }

13

14 private MyClassH (int pV) {

15 v = pV;

16 }

17

18 } // end class MyClassH

6. Explain why the following class hierarchy is not reasonable:

DefenseDepartment
General
Private

7. Give at least one example of a reasonable field for each of the following classes in the following class hierarchy. Be sure that the field is at the right level in the hierarchy.

Vehicle
Car
Airplane
Passenger
Fighter
Bomber
SpaceShip

8. Give at least one example of a reasonable method for each of the following classes in the following class hierarchy. Be sure that the method is at the right level in the hierarchy. Constructors, getters and setters don't count for this problem.

Vehicle
Car
Airplane
Passenger
Fighter
Bomber
SpaceShip

9. Are a Private and a Platoon in an encapsulation or an inheritance relationship? Explain

10. Present reasonable parent and child classes for the class Tree (the biological kind). Give a short explanation for why the classes you are proposing are in good parent-child relationships.

Reference no: EM131184407

Questions Cloud

Who is responsible for the child condition : What went wrong in this case? Who is responsible for the child's condition? Is this a "good" malpractice case?
Which is a physical security measure : Which of the following is a physical security measure? A(n) ____ is an electronic audio file that is posted on the Web for users to download to their mobile devices or computers.
How much importance should each organization place in irbs : A special problem in investigating illegal activities of gangs is the multitude of suspects and the. The three-pronged approach to address the gang problem uses a balance of which three strategies? Which of the following is not an important type of ..
How they help clarify the organization core values : Create a 10- to 12- slide Microsoft PowerPoint presentation describing cultural, research-based models and how they help clarify the organization's core values
Explain why the given class hierarchy is not reasonable : Explain why the following class hierarchy is not reasonable. Given all the problems identified in problems 1 through 4, explain in detail why the following code works, ie, compiles without errors or warnings.
Where is this charge density distributed : Calculate the charge density on the inner and outer conductors. Where is this charge density distributed?
Create a plan to implement a firms strategy : Create a plan to implement a firm's strategy and manage the change from current operations.- Describe strategic planning techniques used to formulate alternative strategies designed to achieve stated business goals.
Analyze the meaning that it has to specific group of people : For this week's discussion, post a 2- to 3-paragraph analysis in which you select a technology, analyze the meaning that it has to a specific group of people, and discuss the implications that meaning has for understanding the technology
Effects of intense punishment on a rat : If you were to walk into a laboratory where the effects of intense punishment on a rat's ability to form a discrimination was being studied, you would be in the lab of a __________ psychologist

Reviews

Write a Review

JAVA Programming Questions & Answers

  Modify the java application using netbeans ide

Modify the Java application using NetBeans IDE to meet these additional and changed business requirements:  The application will now compare the total annual compensation of at least two salespersons

  What is the difference between statement

What is the difference between Statement and PreparedStatement interface?

  Design an adt for the problem

Design an ADT for this problem. Be sure to consider all necessary operations to maintain the appointment book for one year, to archive the yearly book and create a new book for the following year.

  Write an interrupt service routine to output brand name

Evaluate the form of the output depended on the coefficients being input - Consider you would like to use PSoC to display a different brand name on the LCD once every 15 s.

  Program to convert fahrenheit to celsius

Layout the planned structure and steps to accomplish the individual programs. Ensure brief, accurate and complete detailed instructions in the form of pseudocode, not code. Construct two brief explanations for the pseudocode. Provide both programs..

  Produce a design document

You will design and deliver a website foes fictional client part-1 Website Design Document and produce a design document

  Write a rap about classes that rivals the javadev group

Write a rap about classes that rivals the JavaDev group. Write just a few sentences and see if your classmates can add on.

  Data streams and how are they used to facilitate storage

What are Java data streams and how are they used to facilitate storage and retrieval of persistent objects?

  Design a program to help a videorental store

Design classes (class video, class customer, etc) based on your analysis above, using LINKED LISTS for the database elements read into the main memory.

  Point class that represents points on an x, y axis

Write a Point class that represents points on an x, y axis. The data members should be doubles x and y plus an int value called count that represents the number of points currently instantiated

  Write a java code that calculates the product

Write a java code that calculates the product of the subsequent sequence of numbers using for/loop and do/while/loop

  A program that reads a four-digit number from the keyb

Write a program that reads a four-digit number from the keyboard as a string and then converts it into decimal. For example, if the input is 1100, the output should be 12. Hint: Break the string into characters and then convert each character to a va..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd