0% found this document useful (0 votes)
17 views5 pages

Homework 1

The document outlines a homework assignment consisting of ten problems related to Java programming, focusing on issues such as compilation errors, logic errors, class hierarchies, and method examples. Each problem requires explanations, solutions, and values assigned to instance variables. Additionally, a grading rubric is provided to assess the completeness and correctness of the responses.

Uploaded by

mwaqasakhtar101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views5 pages

Homework 1

The document outlines a homework assignment consisting of ten problems related to Java programming, focusing on issues such as compilation errors, logic errors, class hierarchies, and method examples. Each problem requires explanations, solutions, and values assigned to instance variables. Additionally, a grading rubric is provided to assess the completeness and correctness of the responses.

Uploaded by

mwaqasakhtar101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Homework 1

If a problem consists of multiple classes, you can assume the classes are contained in the same .java file.

1. (5 pts) Explain why this code does not compile. Explain two solutions for fixing the error. What
value is assigned to instance variable v for each proposed solution?

2. (5 pts) Explain why this code does not compile. How would you fix it? What value is assigned to
instance variable v based on your solution?

3. (5 pts) Explain why this code has a logic error. How would you fix it? What value is assigned to
instance variable v based on your solution?
4. (5 pts) Explain why this code does not compile. How would you fix it? What value is assigned to
instance variable v based on your solution?

5. (5 pts) Given all the issues identified in problems 1 through 4, explain in detail why the following
code compiles without errors and initializes the instance variable based on the existing constructor
call in the main method. What value is assigned to instance variable v?

6. (5 pts) Explain why the following class hierarchy is not reasonable:

• DefenseDepartment
o General
▪ Private
7. (5 pts) Give at least one example of a reasonable field for each class in the following class hierarchy.
Be sure the field is at the right level of the hierarchy.

• Vehicle
o Car
o Airplane
▪ Passenger
▪ Fighter
▪ Bomber
o Spaceship

8. (5 pts) Give at least one example of a reasonable method for each class in the following class
hierarchy. Be sure the method is at the right level of the hierarchy. Do not include constructors,
getters, or setters.

• Vehicle
o Car
o Airplane
▪ Passenger
▪ Fighter
▪ Bomber
o Spaceship

9. (5 pts) Describe a class model consisting of three classes where two of the classes are in an
association relationship with each other, and two of the classes are in an inheritance relationship.

10. (5 pts) Describe a class hierarchy containing at least 5 classes to model trees (like the kind you find in
a forest). Give a short explanation for why the classes you are proposing are in good parent-child
relationships.
Grading Rubric:

Attribute Meets Does not meet


Problem 1 5 points 0 points
Explains the compiler error. Does not explain compiler error.

Explains two solutions for fixing the Does not explain two solutions for fixing the
error. error.

Describes correct value assigned to Does not describe correct value assigned to
instance variable v for each solution. instance variable v for each solution.
Problem 2 5 points 0 points
Explains the compiler error. Does not explain compiler error.

Explains how to fix it. Does not explain how to fix it.

Describes correct value assigned to Does not describe correct value assigned to
instance variable v. instance variable v.
Problem 3 5 points 0 points
Explains the logic error. Does not explain logic error.

Explains how to fix it. Does not explain how to fix it.

Describes correct value assigned to Does not describe correct value assigned to
instance variable v. instance variable v.
Problem 4 5 points 0 points
Explains the compiler error. Does not explain compiler error.

Explains how to fix it. Does not explain how to fix it.

Describes correct value assigned to Does not describe correct value assigned to
instance variable v. instance variable v.

Problem 5 5 points 0 points


Given the issues identified in problems Given the issues identified in problems 1
1 through 4, explains in detail why the through 4, does not adequately explain why
code compiles without errors and the code compiles without errors and
initializes the instance variable based on initializes the instance variable based on the
the constructor call in the main method. constructor call in the main method.

Describes the correct value assigned to Does not describe the correct value
instance variable v. assigned to instance variable v.

Problem 6 5 points 0 points


Explains why the class hierarchy is not Does not explain why the class hierarchy is
reasonable. not reasonable.
Problem 7 5 points 0 points
Gives at least one example of a Does not give at least one example of a
reasonable field for each class. reasonable field for each class.
The field is at the right level of the The field is not at the right level of the
hierarchy. hierarchy.
Problem 8 5 points 0 points
Gives at least one example of a Does not give at least one example of a
reasonable method for each class. reasonable method for each class.
The method is at the right level. The method is not at the right level.
Does not include constructors, getters Includes constructors, getters or setters.
or setters.

Problem 9 5 points 0 points


Describes a class model consisting of Does not describe a class model consisting
three classes. of three classes.
Describes an association relationship Does not describe an association
between two of the classes. relationship between two of the classes.
Describes an inheritance relationship Does not describe an inheritance
between two of the classes. relationship between two of the classes.

Problem 10 5 points 0 points


Describes a class hierarchy containing at Does not describe a class hierarchy
least 5 classes to model trees. containing at least 5 classes to model trees.
Gives a short explanation for why the Does not give a short explanation for why
classes are in good parent-child the classes are in good parent-child
relationships. relationships.

You might also like