Académique Documents
Professionnel Documents
Culture Documents
to
Write a program to create two Clock objects and test the methods.
3. Design a class to represent a Bank account with the following members (name of the
depositor, account number, type of account, balance amount). Include necessary
constructor and methods to deposit an amount, withdraw amount after checking
balance and to display name and balance.
4. Write an application to display the current date. Also find new date by adding 10
months to the current date. (Hint : use java.util.Calendar class)
5. Write a java program to sort the numbers, which are randomly generated. Use the
static method sort (double []) from java.util.Arrays class for sorting and display the
sorted list using another method.
6. Write a "day calculator". This should prompt for the current day of the week (i.e. an
integer from 0 to 6 representing Sunday to Saturday), and it should then prompt for
any number of days in the future (also an integer) and display the result. The output
might look something like the following:
Day Calculator
Enter the day (integer): 3
Enter the number of days to add: 9
Include a parameterized constructor and use super to initialize the base class
members.
2. Create an abstract class Student that has data member rollNum and methods
setRollNum(int ) and getRollNum() and contains abstract method show(). Derive
class Test from Student which has two data members of type float (mark1 and
mark2) and methods called setMarks(float, float) and getMarks(). Class Test must
override show() method.
3. Assume the bank maintain two types of accounts for customer, one is called saving
account and the other is current account .the saving account provides compound
interest and withdrawal facilities but no cheque book facility. The current account
provides chequebook facility but no interest. Current account holders should also
maintain a minimum balance falls below this, a service charge is imposed. Create a
class Account that stores customer name, account number and account type. From
this, derive two classes CurrentAccount and SavingsAccount to make them more
specific requirements. Include necessary methods in order to achieve following tasks
a.
b.
c.
d.
e.
f.
4. Create an interface Area having a method compute .Use this interface to find the
area of rectangle and circle. Create separate class for shapes circle and rectangle,
both implements Area.
5. Create a package called homepack. Create two classes called Expenditure and
Income and include them in homepack. The Expenditure class has data-members
food, clothing, educational expenses etc. The Income class has data-members
salary, allowance and rent. Create a class Budget (outside of the package) which
uses classes of the packages to calculate saving of the family.
LAB 4( Exception Handling and Multithreading)
1. Define
checked
exception
classes
NoSufficientAmountException
and
NegativeAmountException. Create a class to encapsulate a bank Account. The
withdraw method throws NoSufficientAmountException if balance is not sufficient for
withdrawal. The deposit method should throw a NegativeAmountException if an
amount less than 0 is passed into it. Write a Bank application, which makes use of
the Account class. The program should handle the exceptions effectively.
2. Create an unchecked user-defined exception, which is to be generated
4. Try the following example and make necessary modification so that makeDrink()
works for only one customer at a time. Only after serving first customer it should
consider another one. Also make necessary modifications to set different priorities for
the customer threads. Execute the program and see the order in which they are
served.
/*This class simulates a Hotel where the Customers are considered as threads. Each
customer is given the reference of a JuiceStall from where he can call makeDrink to
prepare the juice he like.*/
//The JuiceStall
class JuiceStall{
void makeDrink(String item){
System.out.println("[Started making\t"+item);
try{
Thread.sleep(1000);
}catch(InterruptedException e){
System.out.println("Interrupted");
}
System.out.println("\t"+item+"is ready]");
}
}
//The Customer
class Customer implements Runnable{
Thread service;
String item;
JuiceStall juice;
Customer(JuiceStall juice, String item){
this.juice=juice;
this.item=item;
service = new Thread(this);
service.start();
}
public void run(){
juice.makeDrink(item);
}
}
//The Hotel
class Hotel{
public static void main(String arg[]){
JuiceStall juice = new JuiceStall();
Customer c1 = new Customer(juice,"Lemon juice");
Customer c2 = new Customer(juice,"Orange juice");
Customer c3 = new Customer(juice,"Grape juice");
try{
c1.service.join();
c2.service.join();
c3.service.join();
}catch(InterruptedException e) {
}
}
4. Write a program to list the system properties to the console. Find the name of current
user and java version. Also store the system properties list into a file.
5. Use HashMap to map names to account balances. Put five pairs into the collection.
Use Map.Entry to get the key and value of each pair in the collection. Also update the
account balance of a specified person.
LAB 7 ( I/O streams )
1. Write a program to delete all files with extension .txt from the U:\home directory.
2. Write an application to search for a file in a directory tree (use recursive function).
3. Write an application to append the contents of one file to another.
4. Write a program to accept n products and save the objects into a file. Read the
objects back and display.
5. Write a program to read and show the contents of three different files as a sequence.
6. Modify the above program to work with three different byte arrays.
7. Modify program 3 using character oriented stream classes.
8. Use PrintStream to write line by line output to a file (Hint: use println() method).
LAB 8 ( Applet and AWT and Swing )
1. Write an applet, which will show the contents of file located in its code base in a text
area.
2. Create a scrolling banner applet. When mouse is pressed on it, scrolling stops and
when mouse is released, start scrolling. The text to scroll is given as parameter to
the applet.
3. Create 3 horizontal scrollbars each for the colours Red, Green and Blue with value 0
to 255. Change the fill colour of an oval, when scroll bars are adjusted.
4. Create an image viewer applet with Next and Previous buttons. The applet should
show the images from a directory located at its code base.
5. Rewrite the above programs to incorporate Swing.
LAB 9 ( JDBC )
1. Create a database in MS Access, containing a single table. The schema of the table
is shown below:
StudentID
number
StudentName
text
Age
number
Mothertounge
text
Write a java program to list out ID and Name of all the students whose mother
tongue is Hindi and whose age is less than 15. Assume that the database is on the
local machine (use JDBC-ODBC bridge).
2. Write a java program using type-4 driver for Oracle, to insert records into the
following table in Oracle.
Employee
EmployeeID
EmployeeName
Date_of_birth
Department
LAB 12 (JSP)
1.
3.
4.
5.
Write a JSP/HTML set that allows a user to enter the name of a system property,
and then displays the value returned by System.getProperty for that property name
(handle errors appripriately.) 2) Go back to the exercises where you manually
modified boolean variables. Instead of a boolean variable, make these come from a
HIDDEN form field that can be set to true or false.
6.
7.
Design an application using JSP and Beans to collect name and phone number,
and display all entered names and phone numbers in another page.