Lab Assignments

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

JAVA LAB EXERCICES

Lab-1

1. Design a class to represent a Bank account includes the following members-name of the
depositor, account number, type of account, balance amount. Methods are assign initial
values, deposit an amount, withdraw amount after checking balance, to display name and
balance
2. Define a class Time with three integer data members hh,mm,ss .Define a no argument
constructor to initialize time value to 10:30:40.Define a three argument Constructor to
Initialize the data members. Define a function to increment time to next second. Write a
method to display the time value.
3. Define a class student with three data members name (string type), roll no (int) and mark
(int) .check status of student whether he is passed or not.For a pass one should have marks
>=50 for first class marks>=60 ,distinction marks>=75.check marks and print status with
name and roll number. Store the student details in an array
4. Write a java program to sort the numbers which is randomly generated. Use the method
sort(double[] num) for sorting and display the sorted numbers in another method

Lab-2

1. Write a program that will prompt the user to enter any number (up to 100) of positive numbers (you
can terminate it by entering ‘q’). On termination, the following information
should be printed out:
The highest number
The lowest number
The average
All numbers greater than 50
All numbers less than 10
Hint: you should create an array, and store the data in that array as it is typed in. You can
then easily do the subsequent processing to calculate the above.
2. Write a "day calculator". This should prompt for the current day of the week (ie 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 in the future : 9
Today is Wednesday, in 9 days time it will be Friday
3. Create a class called "Friend" that contain variables to hold a persons name, address and birthday.
Write a program that creates at least two instances of this class to represent people whom you know,
and print their personal data. Modify the above program so that information about your friends is
stored in a single array.
4. Modify the previous program so that it prompts you for a name, and then prints out that person's
birthday.
Lab-3

1. Create a package called homepack.Create 2 classes called Expenditure and Income .The
Expenditure class has variable to store the values of food,clothing,educational expenses and
methods to input the expenses and find the total expense.The Income class has variables to
store salary,allowance and rent and methods to input the incomes and find the total
income.Create a class Budget outside the package which uses classes of packages to calculate
saving of the family.
2. Write an application to display the current date.

Lab-4
1. Inherit a class from class Time(lab1-qn2) to contain following attributes. Name (String),
subject (String)
2. Define a constructor that receives 5 values including time, name and subject. The
constructor has to initialize its base class attributes by calling base class constructor. Write a
java program to contain a method get() to get 2 numbers from the user in the base classs .
3. The derived class contains a method dismaxi() which displays maximum of two numbers and
a method dismin() which displayed minimum of two numbers.Use constructor
4. Create a class Student that has a variable rollno and methods getnumber and putnumber.
Derive class Test from Student which has 2 variables of type float mark1 and mark2 and a
method called putmarks which displays marks and other method called getmarks to read
the marks
Lab-5
1. 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 2 classes curacct and savacct to
make them more specific requirements. Include necessary methods in order to achieve
following tasks
A. Accept deposit from the customer and update the balance
B. Display the balance
C. Compute and deposit interest.
D. Permit withdrawal and update balance
E. Check the minimum balance, impose penality,if necessary update the balance
F. Use constructors to initialize class members for the three classes

Lab-6
1. Create an interface Sports which has a variable sportwt and a method putwt.Create a
class Results that inherited from Test and uses the interface.It has a variable and method
putwt and display.Write a program to read the values and print the result
2. Define an exception called NoMatchException that is thrown when a string is not
equal to India. Write a program that uses this exception
3. Write a program to illustrates the use of try block with finally clause only.
4. Create a user defined exception which is to be generated whenever the user inputs
the string “Hello”
5. Create a program that handles the above exception s(ie-2 predefined exception and
one user defined exception)
Lab-7
1. Write a program to create multiple threads. The main method sleeps for about 10 seconds
at the end of which all the thread should be terminated
2. Write a program to create threads. Reset their priorities to 2 levels above and below the
NORM_PRIORITY.Displayed the changed priorities
Lab-8
1. Write and run a java program that does the following
a. Declare a string object named s containing the string “Call my name”
Print the entire stringUse the length() method to print the length of the string
b. Use charAt() method to print the first character in the string
c. Use charAt() and the length() methods to print the last character in the string
d. Use indexOf() and the substring() methods to print the first word in the string
2. Write and run a java program that enters a 10 digit string as typical us telephone number
extracts the 3 digit area code ,3 digit “exchange”and the remaining 4 digit number as
separate strings ,prints them and then prints the complete telephone number in the usual
formatting.A sample run might look like this
Enter 10 – digit telephone number : 1234567890
You entered 1234567890
The area code is 123
The exchange is 456
The number is 7890
3. Write and run a java program that capitalizes a two word name. For example, the input
north CARolina
would produce the output
North Carolina

You might also like