Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Create a document using your favorite word processor and type your exercise solutions. At the top of the document be sure to include your name and the homework assignment number, e.g. HW2. Convert this document into Adobe PDF format and name the PDF file .pdf where is your ASURITE user id (for example, my ASURITE user id is kburger2 so my file would be named kburger2.pdf). To convert your document into PDF format, Microsoft Office versions 2008 and newer will export the document into PDF format by selecting the proper menu item from the File menu. The same is true of Open Office and Libre Office. Otherwise, you may use a freeware PDF converter program, e.g., CutePDF is one such program.

Next, create a folder named and copy .pdf to that folder. Copy any Java source code files to this folder (note: Java source code files are the files with a .java file name extension; do not copy the .class files as we do not need those).

Next, compress the folder creating a zip archive file named .zip. Upload .zip to the Homework Assignment 2 by the assignment deadline. The deadline is in course schedule infor. Consult the online syllabus for the late and academic integrity policies.
Note: not all of these exercises will be graded, i.e., random ones will be selected for grading.

2 Learning Objectives
1. Properly use the public, private, and protected accessibility modifiers.
2. Write Java code to override and overload methods.
3. Recognize when inheritance is present among classes in an OOD.
4. Implement classes using inheritance.
5. To recognize when polymorphism is present in an inheritance hierarchy and to implement it.
6. To declare and implement a Java interface.
7. To implement a GUI.
3 Objects, Classes, and Inheritance
Is it required to provide an accessor and/or mutator method for every instance variable of a class? If yes, explain why this is required, and if no, explain why not.
Suppose the class Sub extends Sandwich. Which of the following statements are legal?
Sandwich x = new Sandwich(); Sub y = new Sub();
(a) x = y;
(b) y = x;
(c) Sub y = new Sandwich();
(d) Sandwich x = new Sub();
True or False? A subclass declaration will generally contain declarations for instance variables that are specific to object of that subclass, i.e., those instance variables represent attributes that are not part of superclass objects.
True or False? A superclass declaration will generally contain declarations for instance variables that are specific to objects of that superclass, i.e., those instance variables represent attributes that are not part of subclass objects.

Consider classes C1, C2, and C3. Answer the following questions.

class C1 {
public int x1; protected int x2; private int x3;
public void c1Method1() {} protected void c1Method2() {} private void c1Method3() {}
}

class C2 extends C1 { public int y1; protected int y2; private int y3;
public void c2Method1() {} protected void c2Method2() {} private void c2Method3() {}
}

class C3 extends C2 { public int z1; protected int z2; private int z3;
public void c3Method1() {} protected void c3Method2() {} private void c3Method3() {}
}

1. Which instance variables x1, x2, x3 declared in C1 are directly accessible in c1Method1()?
2. Which instance variables x1, x2, x3 declared in C1 are directly accessible in c1Method2()?
3. Which instance variables x1, x2, x3 declared in C1 are directly accessible in c1Method3()?
4. Which instance variables x1, x2, x3 declared in C1 are directly accessible in c2Method1()?
5. Which instance variables x1, x2, x3 declared in C1 are directly accessible in c2Method2()?
6. Which instance variables x1, x2, x3 declared in C1 are directly accessible in c2Method3()?
7. Which instance variables x1, x2, x3 declared in C1 are directly accessible in c3Method1()?
8. Which instance variables x1, x2, x3 declared in C1 are directly accessible in c3Method2()?
9. Which instance variables x1, x2, x3 declared in C1 are directly accessible in c3Method3()?
10. Which instance variables y1, y2, y3 declared in C2 are directly accessible in c1Method1()?
11. Which instance variables y1, y2, y3 declared in C2 are directly accessible in c1Method2()?
12. Which instance variables y1, y2, y3 declared in C2 are directly accessible in c1Method3()?
13. Which instance variables z1, z2, z3 declared in C3 are directly accessible in c1Method1()?
14. Which instance variables z1, z2, z3 declared in C3 are directly accessible in c1Method2()?
15. Which instance variables z1, z2, z3 declared in C3 are directly accessible in c1Method3()?
16. Which instance methods c1Method1(), c1Method2(), c1Method3() are callable from c2Method1()?
17. Which instance methods c1Method1(), c1Method2(), c1Method3() are callable from c2Method2()?
18. Which instance methods c1Method1(), c1Method2(), c1Method3() are callable from c2Method3()?
19. Which instance methods c1Method1(), c1Method2(), c1Method3() are callable from c3Method1()?
20. Which instance methods c1Method1(), c1Method2(), c1Method3() are callable from c3Method2()?
21. Which instance methods c1Method1(), c1Method2(), c1Method3() are callable from c3Method3()?
22. Which instance methods c2Method1(), c2Method2(), c2Method3() are callable from c1Method1()?
23. Which instance methods c2Method1(), c2Method2(), c2Method3() are callable from c1Method2()?
24. Which instance methods c2Method1(), c2Method2(), c2Method3() are callable from c1Method3()?
25. How many instance variables are encapsulated within a C1 object?
26. How many instance variables are encapsulated within a C2 object?
27. How many instance variables are encapsulated within a C3 object?
Explain what an overloaded method is and give an example.
Explain what an overridden method is and give an example.
Explain what accidental overloading is and the preferred Java method for preventing it.
If an overridden method in a subclass needs to call the overridden superclass method, how is this accomplished?
True or False? It is legal for a method in a class to overload another method also in the same class. Explain.
True or False? It is legal in a class for a method to override another method also in the same class. Explain.
True or False? It is legal in a subclass for a method to overload a method in the superclass. Explain.
True or False? It is legal in a subclass for a method to override a method in the superclass. Explain.

True or False? It is legal in a superclass for a method to overload a method in a subclass. Explain.
True or False? It is legal in a superclass for a method to override a method in a subclass. Explain.
In a subclass constructor, the superclass default constructor is called automatically before the statements of the subclass constructor begin executing. Suppose we wish to call a different superclass constructor (i.e., not the default constructor) from the subclass constructor. Explain how this is accomplished and give an example.
Explain how an abstract class differs from a concrete class.
4 Objects, Classes, Polymorphism, and Interfaces
In the video lecture for Interfaces : Section 6 we discussed an example program that implements an inheritance hierarchy (Mammal is the superclass of Cat and Dog; Insect is the superclass of Cricket). Which method or methods in that program are called polymorphically?
Write the Java code to declare a new class Bee which is a subclass of Insect. The noise made by a Bee is "Buzz".
Write the Java code to declare a new abstract class Amphibian that implements the MakesNoise interface.
Write the Java code to declare a new class Frog which is a subclass of Amphibian. The noise made by a Frog is "Ribbet".
Modify the run() method of Main and add some Bees and Frogs to critters. Build your program and verify that it works correctly. Include all of your .java source code files in the zip archive that you submit for grading.

5 GUI Programming
For these exercises, include your completed .java files in the zip archive that you submit for grading. Complete the code in the provided View class to implement this GUI interface for a calculator. The calculator does not have to be fully functional; the primary objective of the assignment is to implement the GUI.

Create a document using your favorite word processor and type your exercise solutions. At the top of the document be sure to include your name and the homework assignment number, e.g. HW2. Convert this document into Adobe PDF format and name the PDF file .pdf where is your ASURITE user id (for example, my ASURITE user id is kburger2 so my file would be named kburger2.pdf). To convert your document into PDF format, Microsoft Office versions 2008 and newer will export the document into PDF format by selecting the proper menu item from the File menu. The same is true of Open Office and Libre Office. Otherwise, you may use a freeware PDF converter program, e.g., CutePDF is one such program.
Next, create a folder named and copy .pdf to that folder. Copy any Java source code files to this folder (note: Java source code files are the files with a .java file name extension; do not copy the .class files as we do not need those).
Next, compress the folder creating a zip archive file named .zip. Upload .zip to the Homework Assignment 2 by the assignment deadline. The deadline is in course schedule infor. Consult the online syllabus for the late and academic integrity policies.
Note: not all of these exercises will be graded, i.e., random ones will be selected for grading.

2 Learning Objectives
1. Properly use the public, private, and protected accessibility modifiers.
2. Write Java code to override and overload methods.
3. Recognize when inheritance is present among classes in an OOD.
4. Implement classes using inheritance.
5. To recognize when polymorphism is present in an inheritance hierarchy and to implement it.
6. To declare and implement a Java interface.
7. To implement a GUI.

3 Objects, Classes, and Inheritance
Is it required to provide an accessor and/or mutator method for every instance variable of a class? If yes, explain why this is required, and if no, explain why not.
Suppose the class Sub extends Sandwich. Which of the following statements are legal?
Sandwich x = new Sandwich(); Sub y = new Sub();
(a) x = y;
(b) y = x;
(c) Sub y = new Sandwich();
(d) Sandwich x = new Sub();
True or False? A subclass declaration will generally contain declarations for instance variables that are specific to object of that subclass, i.e., those instance variables represent attributes that are not part of superclass objects.
True or False? A superclass declaration will generally contain declarations for instance variables that are specific to objects of that superclass, i.e., those instance variables represent attributes that are not part of subclass objects.

Consider classes C1, C2, and C3. Answer the following questions.

class C1 {
public int x1; protected int x2; private int x3;
public void c1Method1() {} protected void c1Method2() {} private void c1Method3() {}
}

class C2 extends C1 { public int y1; protected int y2; private int y3;
public void c2Method1() {} protected void c2Method2() {} private void c2Method3() {}
}

class C3 extends C2 { public int z1; protected int z2; private int z3;
public void c3Method1() {} protected void c3Method2() {} private void c3Method3() {}
}

1. Which instance variables x1, x2, x3 declared in C1 are directly accessible in c1Method1()?
2. Which instance variables x1, x2, x3 declared in C1 are directly accessible in c1Method2()?
3. Which instance variables x1, x2, x3 declared in C1 are directly accessible in c1Method3()?
4. Which instance variables x1, x2, x3 declared in C1 are directly accessible in c2Method1()?
5. Which instance variables x1, x2, x3 declared in C1 are directly accessible in c2Method2()?
6. Which instance variables x1, x2, x3 declared in C1 are directly accessible in c2Method3()?
7. Which instance variables x1, x2, x3 declared in C1 are directly accessible in c3Method1()?
8. Which instance variables x1, x2, x3 declared in C1 are directly accessible in c3Method2()?
9. Which instance variables x1, x2, x3 declared in C1 are directly accessible in c3Method3()?
10. Which instance variables y1, y2, y3 declared in C2 are directly accessible in c1Method1()?
11. Which instance variables y1, y2, y3 declared in C2 are directly accessible in c1Method2()?
12. Which instance variables y1, y2, y3 declared in C2 are directly accessible in c1Method3()?
13. Which instance variables z1, z2, z3 declared in C3 are directly accessible in c1Method1()?
14. Which instance variables z1, z2, z3 declared in C3 are directly accessible in c1Method2()?
15. Which instance variables z1, z2, z3 declared in C3 are directly accessible in c1Method3()?
16. Which instance methods c1Method1(), c1Method2(), c1Method3() are callable from c2Method1()?
17. Which instance methods c1Method1(), c1Method2(), c1Method3() are callable from c2Method2()?
18. Which instance methods c1Method1(), c1Method2(), c1Method3() are callable from c2Method3()?
19. Which instance methods c1Method1(), c1Method2(), c1Method3() are callable from c3Method1()?
20. Which instance methods c1Method1(), c1Method2(), c1Method3() are callable from c3Method2()?
21. Which instance methods c1Method1(), c1Method2(), c1Method3() are callable from c3Method3()?
22. Which instance methods c2Method1(), c2Method2(), c2Method3() are callable from c1Method1()?
23. Which instance methods c2Method1(), c2Method2(), c2Method3() are callable from c1Method2()?
24. Which instance methods c2Method1(), c2Method2(), c2Method3() are callable from c1Method3()?
25. How many instance variables are encapsulated within a C1 object?
26. How many instance variables are encapsulated within a C2 object?
27. How many instance variables are encapsulated within a C3 object?
Explain what an overloaded method is and give an example.
Explain what an overridden method is and give an example.
Explain what accidental overloading is and the preferred Java method for preventing it.
If an overridden method in a subclass needs to call the overridden superclass method, how is this accomplished?
True or False? It is legal for a method in a class to overload another method also in the same class. Explain.
True or False? It is legal in a class for a method to override another method also in the same class. Explain.
True or False? It is legal in a subclass for a method to overload a method in the superclass. Explain.
True or False? It is legal in a subclass for a method to override a method in the superclass. Explain.

True or False? It is legal in a superclass for a method to overload a method in a subclass. Explain.
True or False? It is legal in a superclass for a method to override a method in a subclass. Explain.
In a subclass constructor, the superclass default constructor is called automatically before the statements of the subclass constructor begin executing. Suppose we wish to call a different superclass constructor (i.e., not the default constructor) from the subclass constructor. Explain how this is accomplished and give an example.
Explain how an abstract class differs from a concrete class.

4 Objects, Classes, Polymorphism, and Interfaces
In the video lecture for Interfaces : Section 6 we discussed an example program that implements an inheritance hierarchy (Mammal is the superclass of Cat and Dog; Insect is the superclass of Cricket). Which method or methods in that program are called polymorphically?
Write the Java code to declare a new class Bee which is a subclass of Insect. The noise made by a Bee is "Buzz".
Write the Java code to declare a new abstract class Amphibian that implements the MakesNoise interface.
Write the Java code to declare a new class Frog which is a subclass of Amphibian. The noise made by a Frog is "Ribbet".
Modify the run() method of Main and add some Bees and Frogs to critters. Build your program and verify that it works correctly. Include all of your .java source code files in the zip archive that you submit for grading.

5 GUI Programming
For these exercises, include your completed .java files in the zip archive that you submit for grading. Complete the code in the provided View class to implement this GUI interface for a calculator. The calculator does not have to be fully functional; the primary objective of the assignment is to implement the GUI.

762_figure1.jpg

Complete the code in actionPerformed() so when the Exit button is clicked, the application will terminate.

Complete the code in actionPerformed() so when the About button is clicked, the application will display this about dialog:

1302_figure2.jpg

Nested Classes
Explain what an inner class is.
Explain how a local class differs from an inner class.
Explain how an anonymous class differs from an inner and local class.

Java, Programming

  • Category:- Java
  • Reference No.:- M92400345
  • Price:- $15

Priced at Now at $15, Verified Solution

Have any Question?


Related Questions in Java

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As