Sei sulla pagina 1di 3

JAVA Lab Assignment 2 /* Concepts covered Classes, Objects, Constructors and Methods Inheritance & super keyword JVM

*/ Q 1. Write a java program to sort the elements of an array in an ascending order using (using switch statement) 1.1 bubble sort 1.2 selection sort 1.3 quick sort 1.4 insertion sort Q2. Write an application to implement 2.1 Stack 2.2 Queue Q3. WAC to create an external class with two instance variable x and y. Now create internal class with single variable z. Try to access x and y in inner class and z in outer class. Q4. Write a simple for loop to add up the numbers from 1 to 100 and print out the result. Disassemble the program and see what you get. Q5. Write a program to create a class hierarchy. Create a class BOXWEIGHT with data members weight which is inherited from the BOX class with data members width, height, depth. 5.1. Find its volume 5.2. Using the super keyword call the super class constructor. Q6. Given the following skeletal code convert it to a full fledged code for implementing a small banking application: class Account { public static final minBalance= 1000; private int accountNo; private String accountHolderName; private float curBalance; // note that the constructor is not public Account (int pAccountNo, String pAccountHolderName float openingBalance) { } int withdraw (float amount) { //return success status } int deposit (float amount) { //return success status

} float getBalance () { } String toString () { } }

public class Bank { private Account accounts []; private int numOfAccounts; public Bank (int count) { } public int openAccount (String accountHolderName, float openingAmount) { //generate account number //allocate memory to (create) the next account reference in the array } public int deposit (int accountNo, float amount) { // search for account having same account number in accounts array //call deposit on searched object //return success status } public int withdraw (int accountNo, float amount) { // search for account having same account number in accounts array //call withdraw on searched object //return success status } public void transfer (int fromAccountNo, int toAccountNumber, float amount)

{ // search for account having specified account numbers in accounts array //call deposit on toAccount withdraw of fromAccount searched object } public void printReport () { // print status of all accounts } } public class BankApplication { //main method to // create bank objects //open account //perform transactions //report invalid transactions //print final report } Q7. Give example usage and expected output for the following methods of Arrays class: a. toString b. copyOf c. sort d. BinarySearch e. Fill f. Equals Q8. Demonstrate the usage of two dimensional arrays using any example. Q9. Use ragged array to provide the output given below 1 123 12345 1234567 123456789 Q10. Create a class called Numeral that accepts an array of ten numbers. Create a subclass called Numplay which has a menu as follows: 10.1. display numbers entered 10.2. sum of the numbers 10.3. average of the numbers 10.4. maximum of the numbers 10.5. minimum of the numbers

Potrebbero piacerti anche