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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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