Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Part A: Multiple Choice

Circle the *most appropriate answer (i.e. only select one answer):
Part A Question 1. Which one of the following is true about a class in java?
a) It can extend multiple classes, and implement many interfaces.
b) It can extend only one class, but implement many interfaces.
c) It can extend multiple classes, but only implement one interface.
d) It can extend only one class and implement only one interface.

Part A Question 2. Assume that there is an abstract class called Vehicle, which has two concrete subclasses, Car and Truck. There is also an interface Loadable, which only Truck implements. Which statement below will cause a compilation error?
a) Loadable item = new Truck();
b) Vehicle item = new Car();
c) Vehicle item = new Truck();
d) Vehicle item = new Vehicle();

Part A Question 3. If two algorithms A and B perform the same function and algorithm A has performance O(log n) and algorithm B has performance O(n), which one of the following is true?
a) Algorithm A has better performance scalability than algorithm B
b) Algorithm B has better performance scalability than algorithm A
c) Algorithm A uses less memory than algorithm B
d) Algorithm B uses less memory than algorithm A
e) None of the above

Part A Question 4. Which one statement is true about the code fragment listed below?

public class Mylistener extends WindowAdapter
{
public void windowClosed (WindowEvent e)
{
System.exit (0);
}
}

a) This code compiles without error but could not be used as a window listener because it does not implement all WindowAdaptor methods.
b) The code will not compile correctly, because the class does not provide all the methods of the WindowListener interface.
c) The code compiles without error and the words extends WindowAdapter could be changed to implements WindowListener without changing the behaviour.
d) The code compiles without error and will do nothing if a windowClosing event is generated.
e) The code compiles without error and will throw an exception if a windowClosing event is generated.

Part A Question 5. Which one of the following is true about an abstract class in Java?
a) It cannot implement interfaces.
b) It cannot be instantiated.
c) It is not allowed to have constructors.
d) All of the above are true.


Part A Question 6. Which of the following statements about interfaces in Java is false?

a) You can extend an interface.
b) You can implement multiple interfaces.
c) Interfaces can have abstract methods.
d) Interface can have member variables.
Part A Question 7. Consider the following class hierarchy and code fragment:
Java.lang.Exception
|
Java.io.exception
/ \
Java.io.StreamCorruptedException java.net.MalformedURLException

1. try {
2. URL u = new URL(http://www.rmit.edu.au);
3. int ch = System.in.read();
4. System.out.print("char read");
5. }
6. catch (MalformedURLException e) {
7. System.out.print("MalformedURLException,");
8. }
9. catch (ObjectStreamException e) {
10. System.out.print("ObjectStreamException,");
11. }
12. catch (Exception e) {
13. System.out.print("general exception,");
14. }
15. finally {
16. System.out.print("executing finally block,");
17. }
18. System.out.print("continuing");

What will be output if the code at line 3 throws an IOException?
a) char read
b) general exception, continuing
c) MalformedURLException, OjectStreamException,general exception, executing finally block, continuing
d) char read, general exception, executing finally block, continuing
e) general exception, executing finally block, continuing

Part A Question 8. Consider again the class hierarchy and code fragments in Question 7. What will be output if the code at line 2 throws a MalformedURLException?
a) general exception, executing finally block, continuing
b) MalformedURLException, ObjectStreamException, general exception, executing finally block, continuing
c) MalformedURLException, general exception, executing finally block, continuing
d) MalformedURLException, executing finally block, continuing
e) MalformedURLException, general exception, continuing

Part A Question 9. Consider the hierarchy (note that the abstract classes are indicated by italic font):

416_java.png

Consider the following code:
1. Dog rover, fido;
2. Animal animal;
3.
4. rover = new Dog();
5. animal = rover;
6. fido = (Dog)animal;

Which one of the statement below is true?
a) Line 5 will not compile.
b) Line 6 will not compile.
c) The code will compile but throw an exception at line 6
d) The code will compile and run
e) The code will compile and run but the cast in line 6 is not required and can be eliminated.

Part A Question 10. The following code relates to the hierarchy in question 9.

1. Dog rover, fido;
2. Animal animal;
3.
4. animal = new Animal();
5. rover = (Dog)animal;

Which one of the statements below is true?
a) Line 4 will not compile.
b) The code will compile but throw an exception at line 5
c) The code will compile and run
d) The code will compile and run but the cast in line 5 is not required and can be eliminated.

Part B: Java Programming

Part B Question 1. Consider the class diagram below. Presently, neither a class hierarchy nor polymorphism is used.

844_java1.png

a) Identify common functionality (e.g. methods and variables) and place it in an abstract superclass called AbstractRunnable which has an additional instance variable boolean isRunning which is set appropriately.
b) Modify the Microwave class to use the superclass (from part a) making sure to include all necessary variables/methods. The constructor should set the powerLevel to 100.0 by default and the start() and stop() methods should be overridden to call the appropriate superclass method, with the remainder of the method body left empty with //TODO comment.
NOTE: The answer must be written using the actual Java code.

Part B Question 2. Consider the following interface, which is designed to calculate a rental fee for different types of borrowable media (e.g. books, videos, dvds)

Public interface Rentable
{
Public double getRentalFee();
}

a) Write an abstract class called AbstractMedia that implements Rentable to provide a predefined fee based on a constant called BASE_RENTAL_FEE which is set to $5.
b) Write a concrete subclass DVD that provides a concrete representation of the AbstractMedia class but does not provide any additional functionality.
c) Write another subclass DVDSeries that extends DVD and takes an int constructor parameter numDiscs (number of dvds in the series). This class should override getRentalFee() based on the default fee plus $1 for each dis in the series. For example, a dvd series with 5 discs would incur a rental fee of $10.
d) Write a declaration for a variable starwars of type DVDSeries which has 3 discs. You should use the most abstract static type.

Part B Question 3. Show the steps to insert the following numbers (one at a time) into a binary search tree. Show the complete tree at each stage (after each number is inserted):

Data: 32,12,21,1,47,37,24,9,66

Part B Question 4. Show the result of performing a pre-order traversal on the final tree above (you only need to show the final order of visited elements).

Part B Question 5. Draw the layout produced by the following code i.e Using the JFrame below, draw all of its contained components paying attention to size and position

Part C: GUI Programming

1890_java2.png

Implement a GUI as shown below:

642_java3.png

Note the following requirements:

• The title of the frame is "Programming 2 Exam Tool Selector".
• The frame has size of 320x200 pixels.
• There is a status message at the bottom that shows "Select Tool" (see figure 1).
• There are three buttons, equally sized.
• The buttons have an image but no text. The filenames of the images are "circle.png", "rect.png", "triangle.png". You may assume these files are found in the source directory.
• When a tool is selected the tool icon is displayed in the center of the main panel and the status bar message is updated to reflect the selected tool (see figure 2).
• When the frame is closed, a window pops up with the text "Thank you for coding during exam conditions" (see figure 3).
• When the dialog box is dismissed, the application closes.

Implementation:

• Your program must use WindowListener to handle the exit event.

• You may use anonymous Inner classes to implement your controllers.

• Since there is no real model functionality, MVC need not be used. However, you should use appropriate classes and packages to separate the various UI components but can use package scope fields to simplify object referencing.

• You should show all code but do not need to show imports. Where you are not sure of exact Java API syntax, you should provide comments describing which method you are trying to invoke.

Java, Programming

  • Category:- Java
  • Reference No.:- M9897089
  • Price:- $60

Priced at Now at $60, Verified Solution

Have any Question?


Related Questions in Java

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

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

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

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?

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

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Part a specification - robot simulationpart a

PART A Specification - Robot Simulation PART A Requirements To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm movement loop which you will build ...

  • 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