Python Lab Manual
Python Lab Manual
BELAGAVI -590009
LABORATORY MANUAL
Prepared By
Prof. PRIYANKA.SHEELAVANTAR
Assistant Professor, Dept. of CSE,
AITM, Belagavi.
2022-23
OOP with Java Lab /21CSL35
Course Objectives:
1. Demonstrate the use of Eclipse/Netbeans IDE to create Java Applications.
2. Using java programming to develop programs for solving real-world problems.
3. Reinforce the understanding of basic object-oriented programming concepts.
2022-23
OOP with Java Lab /21CSL35
EXPERIMENT LIST
PART A
1.Write a java program that prints all real solutions to the quadratic equation ax2+bx+c=0. Read in a, b,
c and use the quadratic formula.
2.Create a Java class called Student with the following details as variables within it. USN,Name,
Branch and Phone Write a Java program to create n Student objects and print the USN, Name, Branch,
and Phone of these objects with suitable headings.
4.Design a super class called Staff with details as StaffId, Name, Phone, Salary. Extend this class by
writing three subclasses namely Teaching (domain, publications), Technical (skills), and Contract
(period). Write a Java program to read and display at least 3 staff objects of all three categories.
6. Develop a java application to implement currency converter (Dollar to INR, EURO to INR, Yen to
INR and vice versa), distance converter (meter to KM, miles to KM and vice versa), time converter
(hours to minutes, seconds and vice versa) using packages.
7.Write a program to generate the resume. Create 2 Java classes Teacher (data: personal information,
qualification, experience, achievements) and Student (data: personal information, result, discipline)
which implements the java interface Resume with the method biodata().
8. Write a Java program that implements a multi-thread application that has three threads. First thread
generates a random integer for every 1 second; second thread computes the square of the number and
prints; third thread will print the value of cube of the number.
9.Write a program to perform string operations using ArrayList. Write functions for the following a.
Append - add at end b. Insert – add at particular index c. Search d. List all string starts with given
letter.
10. Write a Java program to read two integers a and b. Compute a/b and print, when b is not zero.
Raise an exception when b is equal to zero.
11.Write a java program that reads a file name from the user, displays information about whether the
file exists, whether the file is readable, or writable, the type of file and the length of the file in bytes.
12. Develop an applet that displays a simple message in center of the screen. Develop a simple
calculator using Swings.
2022-23
OOP with Java Lab /21CSL35
A problem statement for each batch is to be generated in consultation with the co-examiner and student
should develop an algorithm, program and execute the program for the given problem with appropriate
outputs.
2022-23
OOP with Java Lab /21CSL35
1.Write a java program that prints all real solutions to the quadratic equation ax2+bx+c=0.Read in
a,b,c and use the quadratic formula.
PROGRAM:
Import
java.util.Scanner;public
class Quadratic
{
Public static void main(String[]args)
{
//calculate thedeterminant(b2-4ac)
double d = b * b - 4 * a * c;
System.out.println("Determinant="+d)
;
if(d >0) //checkifdeterminantis greaterthan0
{
2022-23
OOP with Java Lab /21CSL35
System.out.format("root1=root2=%.2f;",rotot1);
}
doublereal=-b/ (2*a);
double imaginary = Math.sqrt(-d) / (2 *
a);System.out.println("The roots are
imaginary");System.out.format("root1 = %.2f+%.2fi", real,
imaginary);System.out.format("\nroot2=%.2f-
%.2fi",real,imaginary);
}
}
}
Output:
2022-23
OOP with Java Lab /21CSL35
2. Create a Java class called Student with the following details as variables within it.
USN
Name
Branch
Phone
Write a Java program to create n Student objects and print the USN, Name, Branch, and Phoneof
these objects with suitable headings.
PROGRAM:
import java.util.*;
public class Student
{
String usn,name,branch;
long phone;
void displayStudent()
{
System.out.println("**********************");
System.out.println("USN= "+usn);
System.out.println("NAME= "+name);
System.out.println("BRANCH= "+branch);
System.out.println("PHONE NUMBER= "+phone);
System.out.println("**********************");
}
for(int i=0;i<n;i++)
st[i]=new Student();
for(int j=0;j<n;j++)
2022-23
OOP with Java Lab /21CSL35
2022-23
OOP with Java Lab /21CSL35
System.out.println("E o
nter the n
Usn,Name,Branch,Ph g
one Number"); String
usn=ip.next(); p
S h
t o
r n
i e
n =
g i
p
n .
a n
m e
e x
= t
i L
p o
. n
n g
e (
x )
t ;
( st[j].insertS
) tudent(usn,
; name,branc
h,phone);
S
t }
r for( int
i m=0;m<n;m++)
n {
g S
y
b s
r t
a e
n m
c .
h o
= u
i t
p .
. f
n o
e r
x m
t a
( t
) (
; "
S
l t 2022-23
OOP with Java Lab /21CSL35
udent OOP with Java Lab /21CSL35
%d
details
are\
n",m+1
);
st[m].di
splaySt
udent();
}
}
}
OUTPUT:
2022-23
OOP with Java Lab /21CSL35
PROGRAM :3A
import java.util.Scanner;
class Prime
{
public static void main(String args[])
{
int i,n,count=0;
System.out.println("Enter the number");
Scanner inp=new Scanner(System.in);
n=inp.nextInt();
for(i=1;i<=n;i++)
{
if(n%i==0)
{
Count++;
}
}
if(count==2)
System.out.println("The given number is a Prime");
else
System.out.println("The given number is not a Prime")
}
}
Output:
2022-23
OOP with Java Lab /21CSL35
PROGRAM :3B
3. B.Write a program for Arithmetic calculator using switch case menu
import java.util.*;
class Switch
{
public static void main(String[] args)
{
Scanner inp = new Scanner(System.in);
System.out.println("Enter the Operator (+,-,*,/) : ");
char operator = inp.next().charAt(0);
System.out.println("Enter the First Operand : ");
double first = inp.nextDouble();
System.out.println("Enter the Second Operand : ");
double second = inp.nextDouble();
double result = 0;
switch(operator)
{
case '+':
result = first + second;
System.out.println("The Result is : "+first+" "+operator+" "+second+" = "+result); break;
case '-':
result = first - second;
System.out.println("The Result is : \n "+first+" "+operator+" "+second+" = "+result); break;
case '*':
result = first * second;
System.out.println("The Result is : "+first+" "+operator+" "+second+" = "+result); break;
case '/':
result = first / second;
System.out.println("The Result is : \n "+first+" "+operator+" "+second+" = "+result); break;
default :
System.out.println("Invalid Operator"); break;
}
}
}
2022-23
OOP with Java Lab /21CSL35
OUTPUT:
2022-23
OOP with Java Lab /21CSL35
4. Design a super class called Staff with details as StaffId, Name, Phone, Salary. Extend this class
by writing three subclasses namely Teaching (domain, publications), Technical (skills), and
Contract (period). Write a Java program to read and display at least 3 staff objects of all three
categories.
PROGRAM:
import java.util.Scanner;
class Staff
{
String staffId;
String name;
long phone;
float salary;
public void accept()
{
Scanner scanner = new Scanner(System.in);
System.out.print("Enter Staff Id: ");
staffId = scanner.next();
System.out.print("Enter Name: ");
name = scanner.next();
System.out.print("Enter Phone: ");
phone = scanner.nextLong();
System.out.print("Enter Salary: ");
salary = scanner.nextFloat();
}
public void display()
{
System.out.println("Staff Id: " + staffId);
System.out.println("Name: " + name);
System.out.println("Phone: " + phone);
System.out.println("Salary: " + salary);
}
}
class Teaching extends Staff
{
String domain;
int n;
public void accept()
{
super.accept();
Scanner scanner = new Scanner(System.in);
System.out.print("Enter Domain: ");
2022-23
OOP with Java Lab /21CSL35
domain = scanner.next();
System.out.print("Enter Number of Publications: ");
2022-23
OOP with Java Lab /21CSL35
n = scanner.nextInt();
System.out.println("\n");
}
public void display()
{
super.display();
System.out.println("Domain: " + domain);
System.out.println("Publications:"+n);
System.out.println("\n");
}
}
class Technical extends Staff
{
String skill;
public void accept()
{
super.accept();
Scanner scanner = new Scanner(System.in);
System.out.print("Enter technical Skills: "); skill =
scanner.nextLine(); System.out.println("\n");
}
public void display()
{
super.display();
System.out.println("Technical Skills: " + skill);
System.out.println("\n");
}
}
class Contract extends Staff
{
int period;
public void accept()
{
super.accept();
Scanner scanner = new Scanner(System.in);
System.out.print("Enter Period: ");
period = scanner.nextInt();
System.out.println("\n");
}
public void display()
{
super.display();
System.out.println("Contract Period: " + period);
}
}
class Four
{
public static void main(String[] args)
{
2022-23
OOP with Java Lab /21CSL35
2022-23
OOP with Java Lab /21CSL35
OUTPUT :
2022-23
OOP with Java Lab /21CSL35
2022-23
OOP with Java Lab /21CSL35
OUTPUT:
2022-23
OOP with Java Lab /21CSL35
Output:
2022-23
OOP with Java Lab /21CSL35
6. Develop a java application to implement currency converter (Dollar to INR, EURO to INR,
Yen to INR and vice versa), distance converter (meter to KM, miles to KM and vice versa), time
converter (hours to minutes, seconds and vice versa) using packages.
PROGRAM:
CurrencyC.java
package cc;
import java.util.*;
{
double inr,usd;
double euro,yen;
{
System.out.println("Enter dollars to convert into Rupees:"); usd=in.nextInt();
inr=usd*81.83;
System.out.println("Dollar ="+usd+" equal to INR="+inr);
System.out.println("\
n");
}
public void rupeetodollar()
{
System.out.println("Enter Rupee to convert into Dollars:");
inr=in.nextInt();
usd=inr/81.83;
System.out.println("Rupee ="+inr+"equal to Dollars="+usd);
}
public void eurotorupee()
{
System.out.println("Enter Euro to convert into Rupees:");
euro=in.nextInt();
inr=euro*79.06;
System.out.println("Euro ="+euro+" equal to INR="+inr);
System.out.println("\n");
2022-23
OOP with Java Lab /21CSL35
}
public void rupeetoeuro()
{
System.out.println("Enter Rupees to convert into Euro:");
inr=in.nextInt();
euro=(inr/79.06);
System.out.println("Rupee ="+inr +"equal to Euro="+euro); System.out.println("\n public void yentoruppe()
{
System.out.println("Enter Yen to convert into Rupees:"); yen=in.nextInt();
inr=yen*0.57;
System.out.println("Yen ="+yen+" equal to INR="+inr); System.out.println("\n");
}
public void ruppetoyen()
{
System.out.println("Enter Rupees to convert into Yen:"); inr=in.nextInt();
yen=(inr/0.57);
System.out.println("INR="+inr +"equal to YEN"+yen); System.out.println("\n");
}
}
DistaceC.Java
package dc;
import java.util.*;
{
double km,m,miles;
{
System.out.println("Enter the distance in meter"); m=in.nextDouble();
km=(m/1000);
System.out.println(m+"m" +" is equal to "+km+"km"); System.out.println("\n");
}
public void kmtom()
{
System.out.println("Enter the distance in Kilometer"); km=in.nextDouble();
m=km*1000;
System.out.println(km+"km" +" is equal to "+m+"m"); System.out.println("\n");
}
2022-23
OOP with Java Lab /21CSL35
{
System.out.println("Enter the distance in miles"); miles=in.nextDouble();
km=(miles*1.60934);
System.out.println(miles+"miles" +" is equal to "+km+"km"); System.out.println("\n");
}
{
System.out.println("Enter the distance in km");
km=in.nextDouble();
miles=(km*0.621371);
System.out.println(km+"km" +" is equal to "+miles+"miles");
}
}
TimeC.java
package tc;
import java.util.*;
{
int hours,seconds,minutes;
Scanner in = new Scanner(System.in);
public void hourstominutes()
{
System.out.println("Enter the no of Hours to convert into minutes");
hours=in.nextInt();
minutes=(hours*60); System.out.println("Minutes: " +
minutes);
}
public void minutestohours()
{
System.out.println("Enter the no of Minutes to convert into Hours");
minutes=in.nextInt();
hours=minutes/60; System.out.println("Hours: " +
hours);
}
public void hourstoseconds()
{
System.out.println("Enter the no of Hours to convert into Seconds");
2022-23
OOP with Java Lab /21CSL35
hours=in.nextInt();
seconds=(hours*3600); System.out.println("Seconds: "
+ seconds);
}
public void secondstohours()
{
System.out.println("Enter the no of Seconds to convert into Hours");
seconds=in.nextInt();
hours=seconds/3600;
System.out.println(seconds+"seconds"+ " is equal to "+hours+"hour");
}
}
Main Class
import cc.*;
import dc.*;
import tc.*;
{
public static void main(String args[])
{
CurrencyC obj=new CurrencyC();
DistanceC obj1=new DistanceC(); TimeC obj2=new
TimeC();
obj.dollartorupee(); obj.rupeetodollar();
obj.eurotorupee(); obj.rupeetoeuro();
obj.yentoruppe(); obj.ruppetoyen();
obj1.mtokm();
obj1.kmtom();
obj1.milestokm(); obj1.kmtomiles();
obj2.hourstominutes(); obj2.minutestohours();
obj2.hourstoseconds(); obj2.secondstohours();
}
2022-23
OOP with Java Lab /21CSL35
OUTPUT:
Enter dollars to convert into Rupees:1
Dollar =1.0 equal to INR=81.83
2022-23
OOP with Java Lab /21CSL35
2022-23
OOP with Java Lab /21CSL35
2022-23
OOP with Java Lab /21CSL35
2022-23
OOP with Java Lab /21CSL35
2022-23
OOP with Java Lab /21CSL35
2022-23