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

  What are the characterstics of sql

What makes it different than other languages?

  Display student details and classes in applet

Display student details and classes they have enrolled in Applet. The Applet should have following features. Update and View.

  Summary of the case astrazeneca-unitedhealth

What is the summary of the case "AstraZeneca, UnitedHealth, and Others: IT-Asset Management- Do you know what youv've got?"

  Write a recursive method that converts a decimal integer

Write a recursive method that converts a decimal integer to a binary swing. Write a recursive method that converts a binary string to a decimal integer.

  Program that inputs a degree of difficulty

Write a computer program that inputs a degree of difficulty and seven judges' scores and outputs the overall score for that dive. The program should ensure that all inputs are within the allowable data ranges.

  Method that accepts a string object

Word Counter Write a method that accepts a String object as an argument and returns the number of words it contains. For instance, if the argument is "Four score and seven years ago" the method should return the number

  Define variables constructors and methods

It defines variables, constructors, and methods. The second class is ClassClient. In ClassClient, the constructor for FirstClassOOPS is called.

  When the user presses a button

When the user presses a button, get the text from text field. Now extract the words from the text one at a time and find the largest word of length 4 or more. Let's call this largest word X for now. In response, create a question based on the length ..

  Hash-join algorithm

In this assignment, you will have a chance to implement the hash-join algorithm for a DBMS. You can use C, C++, or Java to write the program. However, your program should include su- cient comments to make it readable. You need to turn in

  Accepts a string as its parameter and returns an integer

Write a method in java named secondHalfLetters that accepts a string as its parameter and returns an integer representing how many of letters in the string come from the second half of the alphabet

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

  Design a program in pseudocode

Design a program in pseudocode that solves this problem. You are required to generate only the pseudocode - No charting or analysis section is required, but you may have to incorporate the bubble sort algorithm to determine the minimum and maximum..

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