import java.sql.*;
import java.util.Scanner;
public class Programsb1 {
public static void main(String[] args) throws Exception {
Scanner SC=new Scanner(System.in);
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection con=DriverManager.getConnection("jdbc:derby://localhost:1527/Programsb1","robot","robot");
Statement st=con.createStatement();
int ch;
do{
System.out.println("1.Add new student");
System.out.println("2.Delete student");
System.out.println("3.Update student address");
System.out.println("4.Search student");
System.out.println("5.exit");
System.out.print("Enter Choice:");
ch=SC.nextInt();
SC.nextLine();
switch(ch){
case 1:
System.out.println("Enter Reg No:");
int rno = SC.nextInt();
SC.nextLine();
System.out.println("Enter Name:");
String name=SC.nextLine();
System.out.println("Enter dob:");
String dob=SC.nextLine();
System.out.println("Enter Address:");
String address=SC.nextLine();
System.out.println("Enter Class:");
String sclass=SC.nextLine();
System.out.println("Enter Course:");
String course=SC.nextLine();
String insertQuery="insert into student values("+rno+",'"+name+"','"+dob+"','"+address+"','"+sclass+"','"+course+"')";
st.executeUpdate(insertQuery);
System.out.println("student added");
break;
case 2:
System.out.println("Enter reg no to delete:");
int del=SC.nextInt();
String deleteQuery="delete from student where rno="+del;
st.executeUpdate(deleteQuery);
System.out.println("record deleted");
break;
case 3:
System.out.print("Enter reg no:");
int rollno=SC.nextInt();
SC.nextLine();
System.out.println("Enter new address:");
String newaddress=SC.nextLine();
String updateQuery="update student set address='''+newaddress+'''where rno="+rollno;
st.executeUpdate(updateQuery);
System.out.println("address updated");
break;
case 4:
System.out.println("Enter reg no:");
int s=SC.nextInt();
String searchQuery="select*from student";
ResultSet rs=st.executeQuery(searchQuery);
if(rs.next()){
System.out.println("RegNo:"+rs.getInt(1));
System.out.println("Name:"+rs.getString(2));
System.out.println("DOB:"+rs.getString(3));
System.out.println("Address:"+rs.getString(4));
System.out.println("Class:"+rs.getString(5));
System.out.println("Course:"+rs.getString(6));
}
else{
System.out.println("student not found");
}
break;
case 5:
System.out.println("Thank you");
break;
default: System.out.println("invalid choice");
}
}while(ch!=5);
con.close();
}
}
import java.sql.*;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Programsb2 {
public static void main(String[] args) {
try {
Scanner sc = new Scanner(System.in);
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/Database","robo","robo");
Statement st = con.createStatement();
int choice;
do{
System.out.println("\n--- BANK MENU ---");
System.out.println("1. Add Account");
System.out.println("2. Deposit Amount");
System.out.println("3. Withdraw Amount");
System.out.println("4. Display All Accounts");
System.out.println("5. Exit");
System.out.print("Enter choice: ");
choice = sc.nextInt();
if (choice == 1) {
System.out.print("Enter Account No: ");
int accNo = sc.nextInt();
System.out.print("Enter Name: ");
String name = sc.next();
System.out.print("Enter Initial Balance: ");
double balance = sc.nextDouble();
String sql = "INSERT INTO Bank VALUES(" +accNo + ",'" + name + "'," + balance + ")";
st.executeUpdate(sql);
System.out.println("Account Created Successfully!");
}
else if (choice == 2) {
System.out.print("Enter Account No: ");
int accNo = sc.nextInt();
System.out.print("Enter Deposit Amount: ");
double amount = sc.nextDouble();
String sql = "UPDATE Bank SET balance = balance + " + amount + " WHERE accno = " + accNo;
int rows = st.executeUpdate(sql);
if (rows > 0) {
System.out.println("Amount Deposited Successfully!");
} else {
System.out.println("Invalid account number!!!!");
}
}
else if (choice == 3) {
System.out.print("Enter Account No: ");
String accNo = sc.next();
System.out.print("Enter Withdraw Amount: ");
int amount = sc.nextInt();
ResultSet rs = st.executeQuery("SELECT balance FROM Bank WHERE accno = " + accNo+"");
if (rs.next()) {
int currentBalance = rs.getInt(1);
if (currentBalance - amount >= 500) {
String sql = "UPDATE Bank SET balance = balance - " +amount + " WHERE accno=" + accNo+"";
st.executeUpdate(sql);
System.out.println("Withdrawal Successful!");
} else {
System.out.println("Minimum balance ₹500 required!");
}
}else{
System.out.println("Invalid account number!!!!");
}
}
else if (choice == 4) {
ResultSet rs = st.executeQuery("SELECT * FROM Bank");
System.out.println("\nAccNo Name Balance");
while (rs.next()) {
System.out.println(
rs.getInt(1) + " " +
rs.getString(2) + " " +
rs.getDouble(3));
}
}
} while (choice != 5);
con.close();
sc.close();
System.out.println("Program Ended.");
} catch (ClassNotFoundException ex) {
Logger.getLogger(Programsb2.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(Programsb2.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
import java.util.*;
public class LinkedListMenu {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
LinkedList<Integer> list = new LinkedList<>();
LinkedList<Integer> list2 = new LinkedList<>();
int choice;
do {
System.out.println("\n--- MENU ---");
System.out.println("1. Insert Element at Specified Position");
System.out.println("2. Swap Two Elements");
System.out.println("3. Iterate in Reverse Order");
System.out.println("4. Compare Two LinkedLists");
System.out.println("5. Convert LinkedList to ArrayList");
System.out.println("6. Display LinkedList");
System.out.println("0. Exit");
System.out.print("Enter your choice: ");
choice = sc.nextInt();
switch (choice) {
case 1:
System.out.print("Enter element: ");
int element = sc.nextInt();
System.out.print("Enter position (0-based index): ");
int pos = sc.nextInt();
if (pos >= 0 && pos <= list.size()) {
list.add(pos, element);
System.out.println("Element inserted.");
} else {
System.out.println("Invalid position!");
}
break;
case 2:
System.out.print("Enter first element to swap: ");
int e1 = sc.nextInt();
System.out.print("Enter second element to swap: ");
int e2 = sc.nextInt();
int idx1 = list.indexOf(e1);
int idx2 = list.indexOf(e2);
if (idx1 != -1 && idx2 != -1) {
list.set(idx1, e2);
list.set(idx2, e1);
System.out.println("Elements swapped.");
} else {
System.out.println("Elements not found!");
}
break;
case 3:
System.out.println("Reverse Order:");
Iterator<Integer> itr = list.descendingIterator();
while (itr.hasNext()) {
System.out.print(itr.next() + " ");
}
System.out.println();
break;
case 4:
System.out.print("Enter number of elements for second list: ");
int n = sc.nextInt();
list2.clear();
System.out.println("Enter elements:");
for (int i = 0; i < n; i++) {
list2.add(sc.nextInt());
}
if (list.equals(list2)) {
System.out.println("Both LinkedLists are equal.");
} else {
System.out.println("LinkedLists are NOT equal.");
}
break;
case 5:
ArrayList<Integer> arrayList = new ArrayList<>(list);
System.out.println("Converted ArrayList: " + arrayList);
break;
case 6:
System.out.println("LinkedList: " + list);
break;
case 0:
System.out.println("Exiting...");
break;
default:
System.out.println("Invalid choice!");
}
} while (choice != 0);
sc.close();
}
}
import java.util.Scanner;
class Student {
int rollNo;
String name;
int m1, m2, m3;
double percentage;
String grade;
Student(int rollNo, String name, int m1, int m2, int m3) {
this.rollNo = rollNo;
this.name = name;
this.m1 = m1;
this.m2 = m2;
this.m3 = m3;
}
void calculateResult() {
percentage = (m1 + m2 + m3) / 3.0;
if (percentage > 90)
grade = "A";
else if (percentage >= 80)
grade = "B";
else if (percentage >= 70)
grade = "C";
else if (percentage >= 60)
grade = "D";
else
grade = "E";
}
}
class StudentView {
void display(Student s) {
System.out.println("\n--- STUDENT RESULT ---");
System.out.println("Roll No: " + s.rollNo);
System.out.println("Name : " + s.name);
System.out.println("Percentage: " + s.percentage);
System.out.println("Grade : " + s.grade);
}
}
class StudentController {
Student model;
StudentView view;
StudentController(Student m, StudentView v) {
model = m;
view = v;
}
void process() {
model.calculateResult();
view.display(model);
}
}
public class MainApp {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter Roll No: ");
int r = sc.nextInt();
sc.nextLine();
System.out.print("Enter Name: ");
String n = sc.nextLine();
System.out.print("Enter 3 Marks: ");
int m1 = sc.nextInt();
int m2 = sc.nextInt();
int m3 = sc.nextInt();
Student s = new Student(r, n, m1, m2, m3);
StudentView v = new StudentView();
StudentController c = new StudentController(s, v);
c.process();
sc.close();
}
}
Server.java
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class server {
public static void main(String[] args) {
try {
Registry reg = LocateRegistry.createRegistry(2000);
taximplement obj = new taximplement();
reg.rebind("TaxService", obj);
System.out.println("Tax Server is ready...");
} catch (Exception e) {
System.out.println("Server Error: " + e);
e.printStackTrace();
}
}
}
Client.java
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Scanner;
public class client {
public static void main(String[] args) {
try {
Registry reg = LocateRegistry.getRegistry(2000);
tax t = (tax) reg.lookup("TaxService");
Scanner sc = new Scanner(System.in);
System.out.print("Enter your annual income: ");
double income = sc.nextDouble();
double taxAmount = t.calculatetax(income);
System.out.println("Your Income Tax = " + taxAmount);
sc.close();
} catch (Exception e) {
System.out.println("Client Error: " + e);
e.printStackTrace();
}
}
}
Tax.java
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface tax extends Remote {
double calculatetax(double income) throws RemoteException;
}
Taximplement.java
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class taximplement extends UnicastRemoteObject implements tax {
public taximplement() throws RemoteException {
super();
}
@Override
public double calculatetax(double income) throws RemoteException {
if (income <= 300000) {
return 0;
} else if (income <= 600000) {
return income * 0.05;
} else if (income <= 900000) {
return income * 0.10;
} else if (income <= 1200000) {
return income * 0.15;
} else if (income <= 1500000) {
return income * 0.20;
} else {
return income * 0.30;
}
}
}
simpleinterest.java
import java.rmi.*;
public interface simpleinterest extends Remote {
double si(double p, double r, double t) throws RemoteException;
}
implement.java
import java.rmi.*;
import java.rmi.server.*;
public class implement extends UnicastRemoteObject implements
simpleinterest {
public implement() throws RemoteException
{
}
public double si(double p, double r, double t) throws RemoteException {
return (p * r * t) / 100;
}
}
server.java
import java.rmi.RemoteException;
import java.rmi.registry.*;
public class server {
public static void main(String[] args) throws RemoteException {
implement obj = new implement();
Registry reg = LocateRegistry.createRegistry(2000);
reg.rebind("siservice", obj);
System.out.println("Simple Interest Server is ready...");
}
}
client.java
import java.rmi.registry.*;
import java.util.Scanner;
public class client {
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(System.in);
System.out.print("Enter Principal: ");
double p = sc.nextDouble();
System.out.print("Enter Rate: ");
double r = sc.nextDouble();
System.out.print("Enter Time: ");
double t = sc.nextDouble();
Registry reg = LocateRegistry.getRegistry(2000);
simpleinterest obj = (simpleinterest) reg.lookup("siservice");
System.out.println("Simple Interest = "+obj.si(p, r, t));
}
}