Calculate rental fee for different types of borrowable media

Assignment Help JAVA Programming
Reference no: EM13317779

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(https://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.

Reference no: EM13317779

Questions Cloud

What is the standard deviation of total weekly waiting time : Suppose your wait time for a shuttle bus in the morning is normally distributed with µ=8 minutes and t1=5 minutes. Due to increased congestion in the afternoon, your wait time for a shuttle bus in the afternoon is normally distributed
Write a breadth-?rst search algorithm : Write an algorithm to classify the edges of a directed graph G into the four categories: tree edge, back edge, forward edge and cross edge (de?ned in De?nition 7.14, pages 342-343).
What is the the net capacitance : if 5 capacitors each of 5 micro F are connected in series with 4 capacitors each of 4 uF capacitances in parallel. what is the the net capacitance
Determine the maximum shear stress in the shaft : The motor A delivers 3000 hp to the shaft at 1500 rev/min, of which 1000 hpis removed by gear B and 2000 hp is removed by gear C. Determine (a) the maximum shear stress in the shaft; and (b) the angle of twist of end D relative to end A.
Calculate rental fee for different types of borrowable media : 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 - calculate a rental fee for different types of borrowable media (e.g. books,..
Find the angle of rotation of the free end of the shaft : The solid compound shaft, made of three di¤erent materials, carries the two torques shown. (a) Calculate the maximum shear stress in each material. (b) Find the angle of rotation of the free end of the shaft.
Determine the moment at point e in the compound beam : Point F is located just to the left of the 18kN and 25 kN*m couple moment. A) Determine the internal normal force at point E in the compound beam. B) Determine the shear force at point E in the compound beam.
What is the minimum oscillation frequency for this circuit : A 2.2mH inductor is connected in parallel with a variable capacitor. What is the minimum oscillation frequency for this circuit
What is the value of the inductance : An inductor is connected to a 15kHz oscillator that produces an rms voltage of 7.0V. What is the value of the inductance L

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a program to register students for a college

Students have names, addresses and courses. Implement the interface class RegisterStudent. RegisterStudent has one method, public boolean register, which returns the boolean value of true or false if the student is successfully registered for the ..

  Write an interface for an abstract method

Write an interface, PointingDevice, containing:  an abstract method, getXCoord that returns an int and an abstract method, getYCoord that returns an int.

  Java program ask user to enter 10-character telephone number

Write a Java program that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX. The program should display the telephone number with any alphabetic characters

  User enter a series of numbers

Design a java program with a loop that lets the user enter a series of numbers. The user should enter - 99 to signal the end of the series. After all the numbers have been enter been entered, the program should display the largest and smallest number..

  Design a program that asks the user to enter a series of 20

Number Analysis Program: Design a program that asks the user to enter a series of 20 numbers

  Simple java application that uses the string

Create a simple Java application that uses the String class and/or the StringBuffer class and at least 4 of the class methods. Show the code, demonstrate it works properly and describe what it is doing.

  Three most primary forms of loops: the while loop, the do..

explored the world of loops we have accepted the three most primary forms of loops: the while loop, the do...while loop (even though Python does not use this loop), and the for loop. The for loop has approximately three primary implementations that w..

  Create a package called people

Create a second package called ‘task01'. Within this package provide classes which perform the following tasks.

  The game of pig

Write a program that allows a single player to practice the game (that is, there will be no opponent, just a single player). Play 5 turns in the game to get a total score for the player. Refer to the sample output below for a detailed example.

  Coin change program

coin change program. Make change using fewest number of coins. I'm attempting dynamic programming and i may be misunderstanding the algorithm

  Write a program displaying a text file that is in a text are

Write a program displaying a text file that is in a text area. The user enteres a file name in a text field and clicks the view button; the file is then displayed in the text area. Do not use BufferedInputStream.

  Write complete java program to read from keyboard

Write complete Java program to read, from keyboard, a student's first and last name and six grades. It will display on screen last name then first letter of first name with a period.

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