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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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