Opp Lab Assignment 5 and 6
Opp Lab Assignment 5 and 6
Question no 1::
package cost;
package cost;
import java.io.*;
import java.util.Scanner;
package cost;
}
}
Output::
Enter the height of the Rectangular
45
Enter the width of the Rectangular
36
Area of the Rectangular is1620.0
Question no 2::
import java.util.*;
// Loop statement
System.out.println("Enter 1 to insert your own values. " +
"Enter 2
to use preset values.");
loopDecision = console.nextInt();
System.out.println();
System.out.println("Radius = " + p.getR());
// Display the area and circle
System.out.println("Area of the circle = " + p.area());
System.out.println("Circumference of the circle = " +
p.circumference());
}
System.out.println();
System.out.println("Initial radius = " + p.getR());
System.out.println();
System.out.println("Now changing the values.");
System.out.println();
System.out.println();
System.out.println();
System.out.println("Radius = " + p.getR());
// Show area and circumference with the new values
System.out.println("Area of the circle = " + p.area());
System.out.println("Circumference of the circle = " +
p.circumference());
}
}
}
class Point
{
// Declare variables
private double x;
private double y;
// Empty constructor
public Point()
{
}
import java.util.Scanner;
getdata();
display();
package person1;
}
package person1;
Question No 4
In a bank, different customers having saving account. Some customers may have taken a loan from the
bank. So bank always maintains information about bank depositors and borrowers. Design a Base class
Customer (name, phone-number).Derive a class Depositor (accno, balance) from Customer. Again derive
a class Borrower (loan-no, loan-amt) from Depositor. Write necessary member functions to read and
display the details of ‘n’ customers.
import java.sql.*;
import java.io.*;
import javax.sql.*;
class Slip2
Connection con;
Statement state;
ResultSet rs;
int ch;
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded");
con=DriverManager.getConnection("jdbc:odbc:mydsn");
do
System.out.println("\n");
System.out.println("Menu:");
System.out.println("4.Exit");
ch=Integer.parseInt(br.readLine());
switch(ch)
case 1:
int no=Integer.parseInt(br.readLine());
String name=br.readLine();
int sal=Integer.parseInt(br.readLine());
PreparedStatement p=con.prepareStatement(sql);
p.setInt(1,no);
p.setString(2,name);
p.setInt(3,sal);
p.executeUpdate();
System.out.println("Record Added");
//p.close();
//con.close();
break;
case 2:
System.out.println("Enter Employee Number for the record you wish to Update: ");
no=Integer.parseInt(br.readLine());
name=br.readLine();
sal=Integer.parseInt(br.readLine());
p=con.prepareStatement(sql);
p.setString(1,name);
p.setInt(2,sal);
p.setInt(3,no);
p.executeUpdate();
System.out.println("Record Updated");
//p.close();
//con.close();
break;
case 3:
state=con.createStatement();
while(rs.next())
System.out.println("\n");
System.out.print("\t" +rs.getInt(1));
System.out.print("\t" +rs.getString(2));
System.out.print("\t" +rs.getInt(3));
break;
case 4:
System.exit(0);
default:
System.out.println("Invalid Choice");
break;
}while(ch!=4);
}catch(Exception e)
System.out.println(e);