Java Programs for Prime Check and Inheritance
Java Programs for Prime Check and Inheritance
java
slip1_1.java
// output =
// //? javac slip1_1.java
// //? java slip1_1 3 4 5 6 7 8 9
// //! ==========> 3 5 7
localhost:58390/6ad842fb-bcf6-4701-8303-ba50edc188f4/ 1/1
10/13/24, 9:12 PM slip1_2.java
slip1_2.java
//? Define an abstract class Staff with protected members id and name. Define a parameterized
//? constructor. Define one subclass OfficeStaff with member department. Create n objects of
//? OfficeStaff and display all details.
import [Link];
@Override
public void displayDetails() {
[Link]("ID: " + id);
[Link]("Name: " + name);
[Link]("Department: " + department);
}
}
localhost:58390/d52f7cea-9b03-4b49-b5cb-25df8ba048a0/ 1/2
10/13/24, 9:12 PM slip1_2.java
[Link]();
}
}
// output =
// Enter the number of Office Staff: 3
localhost:58390/d52f7cea-9b03-4b49-b5cb-25df8ba048a0/ 2/2
10/13/24, 9:12 PM slip3_1.java
slip3_1.java
//? Write a program to accept ‘n’ name of cities from the user and sort them in ascending order.
import [Link].*;
[Link]();
}
}
// output =
// Enter the number of cities: 5
// Enter city name 1: pune
// Enter city name 2: mumbai
// Enter city name 3: new york
// Enter city name 4: delhi
// Enter city name 5: jaipur
localhost:58390/4d3883c6-f7c0-470a-b052-22b57fcb12f9/ 1/1
10/13/24, 9:12 PM slip3_2.java
slip3_2.java
// Patient Class
class Patient {
String name;
int age;
int oxyLevel;
int hrctReport;
// Main Class
public class slip3_2 {
public static void main(String[] args) {
Patient patient = new Patient("John Doe", 45, 92, 12);
try {
[Link]();
} catch (CovidPositiveException e) {
[Link]([Link]());
}
localhost:58390/5538dad4-8b9e-4aa7-ae93-3dd33fef741e/ 1/2
10/13/24, 9:12 PM slip3_2.java
}
}
// output =
// Patient is Covid Positive(+) and Needs to be Hospitalized?
localhost:58390/5538dad4-8b9e-4aa7-ae93-3dd33fef741e/ 2/2
10/13/24, 9:13 PM slip5_1.java
slip5_1.java
//? Write a program for multilevel inheritance such that Country is inherited from Continent.
//? State is inherited from Country. Display the place, State, Country and Continent.
class Continent {
String name;
Continent(String name) {
[Link] = name;
}
}
void display() {
[Link]("continent Name : " + name);
[Link]("County Name : "+ countryName);
[Link]("State Name :"+ stateName);
[Link]("place name " + placeName);
}
}
// output =
// continent Name : Asia
localhost:58390/6157321f-7ade-4b27-9a6a-a7451cb0ee77/ 1/2
10/13/24, 9:13 PM slip5_1.java
localhost:58390/6157321f-7ade-4b27-9a6a-a7451cb0ee77/ 2/2
10/13/24, 9:13 PM slip5_2.java
slip5_2.java
//? Write a menu driven program to perform the following operations on multidimensional array
//? ie matrices :
//? = Addition
//? = Multiplication
//? = Exit
import [Link];
do {
[Link]("\nMatrix Operations Menu:");
[Link]("1. Addition");
[Link]("2. Multiplication");
[Link]("3. Exit");
[Link]("Enter your choice: ");
choice = [Link]();
switch (choice) {
case 1:
addMatrices(sc);
break;
case 2:
multiplyMatrices(sc);
break;
case 3:
[Link]("Exiting the program.");
break;
default:
[Link]("Invalid choice. Please try again.");
}
} while (choice != 3);
[Link]();
}
localhost:58390/456386ca-7e8b-4aa0-a41b-d5bd433cacea/ 1/4
10/13/24, 9:13 PM slip5_2.java
fillMatrix(matrixA, sc);
// Adding matrices
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
sumMatrix[i][j] = matrixA[i][j] + matrixB[i][j];
}
}
// Multiplying matrices
for (int i = 0; i < rowsA; i++) {
for (int j = 0; j < colsB; j++) {
productMatrix[i][j] = 0; // Initialize to 0
for (int k = 0; k < colsA; k++) {
productMatrix[i][j] += matrixA[i][k] * matrixB[k][j];
}
}
}
}
}
}
// output =
// Matrix Operations Menu:
// 1. Addition
// 2. Multiplication
// 3. Exit
// Enter your choice: 1
// Enter number of rows: 3
// Enter number of columns: 3
// Enter elements of Matrix A:
// Element [0][0]: 1
// Element [0][1]: 2
// Element [0][2]: 3
// Element [1][0]: 4
// Element [1][1]: 5
// Element [1][2]: 6
// Element [2][0]: 7
// Element [2][1]: 8
// Element [2][2]: 9
// Enter elements of Matrix B:
// Element [0][0]: 1
// Element [0][1]: 2
// Element [0][2]: 3
// Element [1][0]: 4
// Element [1][1]: 5
// Element [1][2]: 6
// Element [2][0]: 7
// Element [2][1]: 8
// Element [2][2]: 9
// Result of Matrix Addition:
// 2 4 6
// 8 10 12
// 14 16 18
localhost:58390/456386ca-7e8b-4aa0-a41b-d5bd433cacea/ 4/4
10/13/24, 9:13 PM slip6_1.java
slip6_1.java
//? Write a program to display the Employee(Empid, Empname, Empdesignation, Empsal) information
using toString().
class Employee {
private int empId;
private String empName;
private String empDesignation;
private double empSal;
// Constructor
public Employee(int empId, String empName, String empDesignation, double empSal) {
[Link] = empId;
[Link] = empName;
[Link] = empDesignation;
[Link] = empSal;
}
// output =
// Employee Information:
// Employee ID: 101
// Employee Name: Mohan prakash
// Employee Designation: Software Engineer
// Employee Salary: $75000.0
localhost:58390/04cf3d8e-4f08-4e5f-8322-db7da314ec85/ 2/2
10/13/24, 9:14 PM slip6_2.java
slip6_2.java
//? Create an abstract class “order” having members id, description. Create two subclasses
//? “PurchaseOrder” and “Sales Order” having members customer name and Vendor name
//? respectively. Definemethods accept and display in all cases. Create 3 objects each of
Purchase
//? Order and Sales Order and accept and display details.
import [Link];
// Abstract methods
public abstract void accept();
public abstract void display();
}
// Subclass PurchaseOrder
class PurchaseOrder extends Order {
private String vendorName;
@Override
public void accept() {
Scanner sc = new Scanner([Link]);
[Link]("Enter Purchase Order ID: ");
id = [Link]();
[Link](); // Consume newline
[Link]("Enter Description: ");
description = [Link]();
[Link]("Enter Vendor Name: ");
vendorName = [Link]();
@Override
public void display() {
[Link]("Purchase Order Details:");
[Link]("ID: " + id);
[Link]("Description: " + description);
[Link]("Vendor Name: " + vendorName);
}
}
// Subclass SalesOrder
class SalesOrder extends Order {
private String customerName;
@Override
public void accept() {
Scanner sc = new Scanner([Link]);
[Link]("Enter Sales Order ID: ");
localhost:58390/a78efed1-4e0c-4e47-8575-17b2252c4a28/ 1/4
10/13/24, 9:14 PM slip6_2.java
id = [Link]();
[Link](); // Consume newline
[Link]("Enter Description: ");
description = [Link]();
[Link]("Enter Customer Name: ");
customerName = [Link]();
@Override
public void display() {
[Link]("Sales Order Details:");
[Link]("ID: " + id);
[Link]("Description: " + description);
[Link]("Customer Name: " + customerName);
}
}
localhost:58390/a78efed1-4e0c-4e47-8575-17b2252c4a28/ 2/4
10/13/24, 9:14 PM slip6_2.java
// output =
// --- Enter details for Purchase Order 1 ---
// Enter Purchase Order ID: 101
// Enter Description: toy
// Enter Vendor Name: dev
// Description: toy
// Customer Name: rohan
localhost:58390/a78efed1-4e0c-4e47-8575-17b2252c4a28/ 4/4
10/13/24, 9:14 PM slip7_1.java
slip7_1.java
// Design a class for Bank. Bank Class should support following operations;
// a. Deposit a certain amount into an account
// b. Withdraw a certain amount from an account
// c. Return a Balance value specifying the amount with details
import [Link];
class Bank {
private String accountHolderName;
private String accountNumber;
private double balance;
// Constructor
public Bank(String accountHolderName, String accountNumber) {
[Link] = accountHolderName;
[Link] = accountNumber;
[Link] = 0.0; // Initial balance is set to 0
}
localhost:58390/e2fc8092-81f2-4493-a598-b6abd19ca076/ 1/3
10/13/24, 9:14 PM slip7_1.java
int choice;
do {
[Link]("\nBank Operations Menu:");
[Link]("1. Deposit");
[Link]("2. Withdraw");
[Link]("3. Check Balance");
[Link]("4. Exit");
[Link]("Enter your choice: ");
choice = [Link]();
switch (choice) {
case 1:
[Link]("Enter amount to deposit: $");
double depositAmount = [Link]();
[Link](depositAmount);
break;
case 2:
[Link]("Enter amount to withdraw: $");
double withdrawAmount = [Link]();
[Link](withdrawAmount);
break;
case 3:
[Link]("\n--- Account Balance ---");
[Link]([Link]());
break;
case 4:
[Link]("Exiting the program.");
break;
default:
[Link]("Invalid choice. Please try again.");
}
} while (choice != 4);
// output =
// Enter Account Holder Name: rohan
localhost:58390/e2fc8092-81f2-4493-a598-b6abd19ca076/ 2/3
10/13/24, 9:14 PM slip7_1.java
localhost:58390/e2fc8092-81f2-4493-a598-b6abd19ca076/ 3/3
10/13/24, 9:14 PM slip7_2.java
slip7_2.java
//? Write a program to accept a text file from user and display the contents of a file in
//? reverse order and change its case.
import [Link].*;
import [Link];
try {
File file = new File(path);
Scanner fileSc = new Scanner(file);
StringBuilder content = new StringBuilder();
while ([Link]()) {
[Link]([Link]()).append("\n");
}
[Link]();
} catch (FileNotFoundException e) {
[Link]("File not found: " + [Link]());
}
}
// output =
// MAr EERHs IAj , GNINROm DOOg OLLEh
localhost:58390/16095990-cfba-4fc1-b571-e68b199dbd87/ 1/1
10/13/24, 9:11 PM [Link]
[Link]
localhost:58390/98ceab08-3982-412f-b8e8-2287ab0b3887/ 1/1
10/13/24, 9:15 PM slip8_1.java
slip8_1.java
// Create a class Sphere, to calculate the volume and surface area of sphere.
// (Hint : Surface area=4*3.14(r*r), Volume=(4/3)3.14(r*r*r))
import [Link];
class Sphere {
private double radius;
[Link]();
}
}
// output =
// Enter the radius of the sphere: 2.5
// Surface Area: 78.54
// Volume: 65.45
localhost:58390/462b27d7-becf-4afc-b844-c94e5698d5ab/ 1/1
10/13/24, 8:37 PM slip8_2.java
slip8_2.java
import [Link].*;
import [Link].*;
[Link](new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// Display mouse click coordinates in the text field
[Link]("Mouse Clicked at: (" + [Link]() + ", " + [Link]() + ")");
}
});
[Link](new MouseAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
localhost:58315/31b3e87f-095e-441b-9e87-5723744528e4/ 1/1
10/13/24, 9:15 PM slip9_1.java
slip9_1.java
import [Link];
class Clock {
private int hours;
private int minutes;
private int seconds;
private String period; // AM or PM
localhost:58390/dba779fb-ff60-41bc-abae-e1800b9593fe/ 1/2
10/13/24, 9:15 PM slip9_1.java
try {
// Create a Clock object
Clock clock = new Clock(hours, minutes, seconds, period);
[Link](); // Display the set time
} catch (IllegalArgumentException e) {
[Link]([Link]());
}
[Link]();
}
}
// output =
// Enter hours (1-12): 2
// Enter minutes (0-59): 52
// Enter seconds (0-59): 54
// Set the period of time (AM/PM) : pM
// Time: 02:52:54 PM
localhost:58390/dba779fb-ff60-41bc-abae-e1800b9593fe/ 2/2
10/13/24, 9:15 PM slip9_2.java
slip9_2.java
interface PMarker {
}
public P() {
[Link] = 0;
[Link] = "Unknown";
[Link] = 0.0;
[Link] = 0;
cnt++;
}
[Link]("Product Details:");
localhost:58390/a4ea0f40-c70a-4ab1-8bc8-d009ae866a37/ 1/2
10/13/24, 9:15 PM slip9_2.java
[Link]();
[Link]();
[Link]();
// output =
// Product Details:
// ID: 101
// Name: Laptop
// Cost: 75000.00
// Qty: 10
// -----------------------------
// ID: 102
// Name: Smartphone
// Cost: 30000.00
// Qty: 25
// -----------------------------
// ID: 0
// Name: Unknown
// Cost: 0.00
// Qty: 0
// -----------------------------
// Total Products: 3
localhost:58390/a4ea0f40-c70a-4ab1-8bc8-d009ae866a37/ 2/2
10/13/24, 9:16 PM slip10_1.java
slip10_1.java
import [Link];
interface Cube {
int calculate(int n);
}
[Link]();
}
}
// output =
// Enter a number: 2
// Cube of 2 is: 8
localhost:58390/f11cb392-c338-4d74-8ea0-f59afa13f6df/ 1/1
10/13/24, 8:52 PM [Link]
[Link]
slip10_2
package student;
// Constructor
public StudentInfo(int rollNo, String name, String
className, double percentage) {
[Link] = rollNo;
[Link] = name;
[Link] = className;
[Link] = percentage;
}
localhost:50192/1a65f010-edd2-42c9-9ce8-79c77e3185d0/ 1/1
10/13/24, 8:53 PM [Link]
[Link]
localhost:50192/b4c4f048-5c80-4305-a6fa-3e273448536b/ 1/2
10/13/24, 8:53 PM [Link]
// Calculate percentage
double percentage = (double) totalMarks / 6;
[Link]();
}
}
// output =
// Enter Roll No: 45
// Enter Name: rohit
// Enter Class: fy
// Enter marks for subject 1: 85
// Enter marks for subject 2: 85
// Enter marks for subject 3: 95
// Enter marks for subject 4: 95
// Enter marks for subject 5: 80
// Enter marks for subject 6: 85
// Student Roll No: 45
// Student Name: rohit
// Class: fy
// Percentage: 87.5%
localhost:50192/b4c4f048-5c80-4305-a6fa-3e273448536b/ 2/2
10/13/24, 9:16 PM slip11_1Cylinder.java
slip11_1Cylinder.java
interface Operation {
double PI = 3.142;
double volume();
}
@Override
public double volume() {
return PI * radius * radius * height;
}
[Link]();
}
}
// output =
// Enter radius of the cylinder: 2
// Enter height of the cylinder: 2
// Volume of the cylinder: 25.136
localhost:58390/14ad55ac-bc0a-4c92-92f6-3004cb6a2723/ 1/1
10/13/24, 9:16 PM slip11_2UserAuth.java
slip11_2UserAuth.java
import [Link];
try {
// Accept username and password from user
[Link]("Enter Username: ");
String user = [Link]();
[Link]("Login successful!");
} catch (InvalidPwdException e) {
[Link]([Link]());
} finally {
[Link]();
}
}
}
// output =
// Enter Username: rohit@999
// Enter Password: rohit@999
// Login successful!
localhost:58390/8114f089-6fe1-49b1-81dd-509f67d5cc23/ 1/1
10/13/24, 9:16 PM slip14_1.java
slip14_1.java
import [Link];
try {
[Link]("Enter a number: ");
int n = [Link]();
if (n == 0) {
throw new ZeroEx("Number is 0");
}
if (isPrime(n)) {
[Link](n + " is a prime number.");
} else {
[Link](n + " is not a prime number.");
}
} catch (ZeroEx e) {
[Link]([Link]());
} finally {
[Link]();
}
}
}
// output =
// Enter a number: 5
// 5 is a prime number.
localhost:58390/b4b272ba-e67a-45cc-a778-1170329036dc/ 1/1
10/13/24, 8:56 PM [Link]
SY\[Link] slip14_2
package SY;
public class SM {
public int cTotal;
public int mTotal;
public int eTotal;
localhost:50520/938fb6f2-f062-42f2-a649-28adf10282ac/ 1/1
10/13/24, 8:56 PM [Link]
TY\[Link]
package TY;
public class TM {
public int theory;
public int practicals;
localhost:50520/e3ab8081-240d-4a08-a8a5-e8abb00e113a/ 1/1
10/13/24, 8:57 PM [Link]
[Link]
//? Write a Java program to create a Package “SY” which has a class SYMarks (members —
//? ComputerTotal, MathsTotal, and ElectronicsTotal). Create another package TY which has a
//? class TYMarks (members — Theory, Practicals). Create ‘n” objects of Student class (having
//? rolINumber, name, SYMarks and TYMarks). Add the marks of SY and TY computer subjects
//? and calculate the Grade (‘A” for >= 70, ‘B’ for >= 60 ‘C” for >= 50, Pass Class for > =40
//? else‘FAIL’) and display the result of the student in proper format.
import [Link];
import [Link];
import [Link];
localhost:50520/620965bb-7dff-4a60-a83d-2a5a880785cf/ 1/3
10/13/24, 8:57 PM [Link]
[Link]("\nResults:");
for (student student : students) {
[Link]();
}
[Link]();
}
}
// output =
// Enter number of students: 3
// Enter Roll No for Student 1: 11
// Enter Name for Student 1: suresh
// Enter SY Computer Total: 400
// Enter SY Maths Total: 300
// Enter SY Electronics Total: 350
// Enter TY Theory Marks: 400
// Enter TY Practical Marks: 100
// Enter Roll No for Student 2: 12
// Enter Name for Student 2: ritesh
// Enter SY Computer Total: 400
// Enter SY Maths Total: 456
// Enter SY Electronics Total: 125
// Enter TY Theory Marks: 500
// Enter TY Practical Marks: 100
// Enter Roll No for Student 3: 13
// Enter Name for Student 3: mayur
// Enter SY Computer Total: 300
// Enter SY Maths Total: 350
// Enter SY Electronics Total: 400
localhost:50520/620965bb-7dff-4a60-a83d-2a5a880785cf/ 2/3
10/13/24, 8:57 PM [Link]
// Results:
// Roll No: 11
// Name: suresh
// Grade: A
// Roll No: 12
// Name: ritesh
// Grade: A
// Roll No: 13
// Name: mayur
// Grade: A
localhost:50520/620965bb-7dff-4a60-a83d-2a5a880785cf/ 3/3
10/13/24, 9:17 PM slip15_1.java
slip15_1.java
// Accept the names of two files and copy the contents of the
// first to the second. First file having Book name and
// Author name in file.
import [Link].*;
import [Link];
// output =
// Enter source file name (with .txt): [Link]
// Enter destination file name (with .txt): [Link]
// Contents copied from [Link] to [Link]
localhost:58390/e3a73939-c899-4e42-be82-a0965aa85bc3/ 1/1
10/13/24, 9:17 PM slip15_2.java
slip15_2.java
// Write a program to define a class Account having members custname, accno. Define default
// and parameterized constructor. Create a subclass called SavingAccount with member savingbal,
// minbal. Create a derived class AccountDetail that extends the class SavingAccount with
// members, depositamt and withdrawalamt. Write a appropriate method to display customer
// details.
class Acc {
String cName;
String accNo;
Acc() {
cName = "Unknown";
accNo = "0000";
}
SavAcc() {
super();
sBal = 0.0;
minBal = 1000.0;
}
AccDetail() {
super();
depAmt = 0.0;
withAmt = 0.0;
}
AccDetail(String cName, String accNo, double sBal, double minBal, double depAmt, double
withAmt) {
super(cName, accNo, sBal, minBal);
localhost:58390/48dcfcad-e158-423b-bfb8-9ae1a45594d3/ 1/2
10/13/24, 9:17 PM slip15_2.java
[Link] = depAmt;
[Link] = withAmt;
}
void showDetails() {
[Link]("Customer Name: " + cName);
[Link]("Account Number: " + accNo);
[Link]("Saving Balance: " + sBal);
[Link]("Minimum Balance: " + minBal);
[Link]("Deposit Amount: " + depAmt);
[Link]("Withdrawal Amount: " + withAmt);
}
}
// output =
// Customer Name: John Doe
// Account Number: 12345
// Saving Balance: 5000.0
// Minimum Balance: 1000.0
// Deposit Amount: 1500.0
// Withdrawal Amount: 200.0
localhost:58390/48dcfcad-e158-423b-bfb8-9ae1a45594d3/ 2/2
10/13/24, 9:17 PM [Link]
[Link]
localhost:58390/7af7d021-e33b-4b01-bb12-815fd57457e2/ 1/1
10/13/24, 9:17 PM [Link]
[Link]
localhost:58390/74770c9d-3429-40e3-8ea3-5f3d15fb0de7/ 1/1
10/13/24, 8:37 PM slip18_1.java
slip18_1.java
import [Link].*;
import [Link].*;
[Link](btnNorth, [Link]);
[Link](btnSouth, [Link]);
[Link](btnEast, [Link]);
[Link](btnWest, [Link]);
[Link](btnCenter, [Link]);
[Link](true);
}
}
localhost:58315/6fa9fa5b-7a7a-4940-9ee2-8f0c60cc79c4/ 1/1
10/13/24, 9:18 PM slip18_2.java
slip18_2.java
import [Link].*;
class Player {
String n;
int innings;
int notOut;
int runs;
double avg;
void display() {
[Link]("Name: %s, Innings: %d, Not Out: %d, Total Runs: %d, Batting Average:
%.2f%n",
n, innings, notOut, runs, avg);
}
}
[Link](p);
[Link]();
}
}
// output =
// Enter number of players: 2
// Enter name of player 1: rohit
// Enter number of innings: 2
// Enter number of times not out: 1
// Enter total runs: 100
// Enter name of player 2: xyz
// Enter number of innings: 3
// Enter number of times not out: 1
// Enter total runs: 99
localhost:58390/1a390e0f-4d7c-468a-ab82-64faa93c21a4/ 2/2
10/13/24, 9:18 PM slip19_1.java
slip19_1.java
import [Link];
int primaryDiagonalSum = 0;
int secondaryDiagonalSum = 0;
[Link]();
}
}
// output =
// Enter the number of rows: 3
// Enter the number of columns: 3
// Enter the elements of the matrix:
// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 9
// Sum of primary diagonal: 15
// Sum of secondary diagonal: 15
localhost:58390/ece5404a-35b5-48db-b766-6ff8ff57d691/ 1/1
10/13/24, 8:38 PM slip19_2.java
slip19_2.java
// Write a program which shows the combo box which includes list of [Link].(Comp. Sci)
// subjects. Display the selected subject in a text field.
import [Link].*;
class slip19_2 {
public static void main(String[] args) {
JFrame f = new JFrame("[Link]. (Comp. Sci) Subjects");
[Link](JFrame.EXIT_ON_CLOSE);
[Link](300, 100);
String[] s = {
"Data Structures",
"Database Management",
"Operating Systems",
"Computer Networks",
"Software Engineering",
"Web Technologies"
};
[Link](p);
[Link](true);
}
}
localhost:58315/bee085f3-d6e5-4b4a-8769-9212ed6a6a3c/ 1/1
10/13/24, 9:18 PM slip20_1.java
slip20_1.java
// output =
// continent Name : Asia
// County Name : India
// State Name :Maharashtra
// place name pune
localhost:58390/997e9f32-6bfa-49e2-92db-456adceabcbb/ 1/1
10/13/24, 8:58 PM [Link]
slip20_2
Operation\[Link]
package Operation;
localhost:58106/3272f14a-2e0a-40d7-92a0-a2fa0a6ab784/ 1/1
10/13/24, 9:00 PM [Link]
Operation\[Link]
package Operation;
localhost:58106/673ccdd5-8e17-4734-9175-ed7108d3c19b/ 1/1
10/13/24, 9:00 PM [Link]
[Link]
import [Link];
import [Link];
public class op {
public static void main(String[] args) {
Addition add = new Addition();
Maximum max = new Maximum();
// Addition
int sum = [Link](5, 10);
float diff = [Link](15.5f, 10.2f);
// Maximum
int maximum = [Link](20, 35);
[Link]("Maximum: " + maximum);
}
}
// output =
// Sum: 15
localhost:58106/f056d5b6-96a6-4eec-9b23-88d28cd0b1fe/ 1/2
10/13/24, 9:00 PM [Link]
// Difference: 5.3
// Maximum: 35
localhost:58106/f056d5b6-96a6-4eec-9b23-88d28cd0b1fe/ 2/2
10/13/24, 9:19 PM slip21_1.java
slip21_1.java
// Define a class MyDate(Day, Month, year) with methods to accept and display a MyDateobject.
// Accept date as dd,mm,yyyy. Throw user defined exception "InvalidDateException” if the date
// is invalid.
import [Link];
class MyDate {
private int day;
private int month;
private int year;
int[] daysInMonth = {31, (isLeapYear(y) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30,
31};
return d > 0 && d <= daysInMonth[m - 1];
}
try {
[Link]();
[Link]();
} catch (InvalidDateException e) {
[Link]([Link]());
}
}
}
// output =
// Enter date (dd mm yyyy): 12
// 03
// 2020
// Date: 12/03/2020
localhost:58390/cc40d28a-c7f3-4a57-8bf0-dd74a6ee9bab/ 2/2
10/13/24, 9:19 PM slip21_2.java
slip21_2.java
class Employee {
private int id;
private String name;
private String deptName;
private double salary;
private static int count = 0; // Static variable to count objects
// Default constructor
public Employee() {
[Link] = 0;
[Link] = "Unknown";
[Link] = "Not Assigned";
[Link] = 0.0;
count++;
display();
}
// Parameterized constructor
public Employee(int id, String name, String deptName, double salary) {
[Link] = id;
[Link] = name;
[Link] = deptName;
[Link] = salary;
count++;
display();
}
localhost:58390/d2598bfb-96a9-4b53-b11e-c7cd0428d0cc/ 1/2
10/13/24, 9:19 PM slip21_2.java
// ouitput =
// Employee ID: 101
// Name: Alice
// Department: IT
// Salary: 60000.00
// Total Employees Created: 1
// Employee ID: 102
// Name: Bob
// Department: HR
// Salary: 50000.00
// Total Employees Created: 2
// Employee ID: 103
// Name: Charlie
// Department: Finance
// Salary: 70000.00
// Total Employees Created: 3
// Employee ID: 0
// Name: Unknown
// Department: Not Assigned
// Salary: 0.00
// Total Employees Created: 4
// Final Count of Employees: 4
localhost:58390/d2598bfb-96a9-4b53-b11e-c7cd0428d0cc/ 2/2
10/13/24, 9:19 PM slip25_1.java
slip25_1.java
// Create a class Student(rollno, name ,class, per), to read student information from the
console
// and display them (Using BufferedReader class)
import [Link].*;
class Student {
int rollNo;
String name, cls; // Changed to 'cls' to avoid conflict with the keyword 'class'
float per;
[Link]("\nStudent Information:");
for (Student student : students) {
[Link](); // Display each student's information
}
} catch (IOException | NumberFormatException e) {
localhost:58390/8837c9d2-4d12-4301-af51-cccc4d9217a6/ 1/2
10/13/24, 9:19 PM slip25_1.java
// output =
// Enter Roll No: 101
// Enter Name: rohit
// Enter Class: fy
// Enter Percentage: 85
// Enter Roll No: 102
// Enter Name: mayur
// Enter Class: fy
// Enter Percentage: 86
// Enter Roll No: 103
// Enter Name: puja
// Enter Class: ty
// Enter Percentage: 96
// Enter Roll No: 104
// Enter Name: pornema
// Enter Class: sy
// Enter Percentage: 90
// Enter Roll No: 105
// Enter Name: netal
// Enter Class: fy
// Enter Percentage: 85
// Student Information:
// Roll No: 101, Name: rohit, Class: fy, Percentage: 85.00%
// Roll No: 102, Name: mayur, Class: fy, Percentage: 86.00%
// Roll No: 103, Name: puja, Class: ty, Percentage: 96.00%
// Roll No: 104, Name: pornema, Class: sy, Percentage: 90.00%
// Roll No: 105, Name: netal, Class: fy, Percentage: 85.00%
localhost:58390/8837c9d2-4d12-4301-af51-cccc4d9217a6/ 2/2
10/13/24, 8:39 PM slip25_2.java
slip25_2.java
// Create the following GUI screen using appropriate layout manager. Accept the name, class,
// hobbies from the user and display the selected options in a textbox.
import [Link].*;
import [Link].*;
import [Link];
import [Link];
// Your Name
JLabel nameLabel = new JLabel("Your Name");
JTextField nameField = new JTextField();
[Link](nameLabel);
[Link](nameField);
localhost:58315/ac0779cc-1c47-4462-bf8b-4f57482fd406/ 1/2
10/13/24, 8:39 PM slip25_2.java
[Link](sportsCheckBox);
[Link](hobbiesPanel);
// Output TextField
JTextField outputField = new JTextField();
[Link](false);
// Submit Button
JButton submitButton = new JButton("Submit");
[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String name = [Link]();
String selectedClass = [Link]() ? "FY" :
[Link]() ? "SY" : [Link]() ? "TY" : "";
String hobbies = "";
if ([Link]()) hobbies += "Music ";
if ([Link]()) hobbies += "Dance ";
if ([Link]()) hobbies += "Sports ";
[Link]("Name: " + name + " | Class: " + selectedClass + " |
Hobbies: " + hobbies);
}
});
localhost:58315/ac0779cc-1c47-4462-bf8b-4f57482fd406/ 2/2
10/13/24, 9:19 PM slip26_1.java
slip26_1.java
class Item {
private int itemNumber;
private String itemName;
private double itemPrice;
private static int count = 0; // Static variable to count objects
// Default constructor
public Item() {
[Link] = 0;
[Link] = "Unknown";
[Link] = 0.0;
count++;
display();
}
// Parameterized constructor
public Item(int itemNumber, String itemName, double itemPrice) {
[Link] = itemNumber;
[Link] = itemName;
[Link] = itemPrice;
count++;
display();
}
// output =
// Item Number: 101
// Item Name: Laptop
// Item Price: 75000.00
// Total Items Created: 1
// Item Number: 0
// Item Name: Unknown
// Item Price: 0.00
// Total Items Created: 4
localhost:58390/d303af17-3eb4-4512-a2a7-7a0217bd16f8/ 2/2
10/13/24, 9:20 PM slip26_2.java
slip26_2.java
// Define a class “Donor’ to store the below mentioned details of a blood donor. name, age,
// address, contactnumber, bloodgroup, date of last donation. Create ‘n’ objects of this class
for
// all the regular donors at Pune. Write these objects to a file. Read these objects from the
file and
// display only those donors’ details whose blood group is “‘A+ve’ and had not donated for the
// recent six months.
import [Link].*;
import [Link];
import [Link].*;
// Donor Class
class Donor implements Serializable {
private String name;
private int age;
private String address;
private String contactNumber;
private String bloodGroup;
private LocalDate lastDonationDate;
public Donor(String name, int age, String address, String contactNumber, String bloodGroup,
LocalDate lastDonationDate) {
[Link] = name;
[Link] = age;
[Link] = address;
[Link] = contactNumber;
[Link] = bloodGroup;
[Link] = lastDonationDate;
}
@Override
public String toString() {
return "Name: " + name + ", Age: " + age + ", Address: " + address + ", Contact: " +
contactNumber +
", Blood Group: " + bloodGroup + ", Last Donation Date: " + lastDonationDate;
}
}
@SuppressWarnings("unchecked")
localhost:58390/536b63e9-c1e4-4f6d-b366-7d1a126d1688/ 1/3
10/13/24, 9:20 PM slip26_2.java
[Link]();
localhost:58390/536b63e9-c1e4-4f6d-b366-7d1a126d1688/ 2/3
10/13/24, 9:20 PM slip26_2.java
}
}
// output =
// Enter number of donors: 2
// Enter details for donor 1:
// Name: Rohit
// Age: 25
// Address: pune
// Contact Number: 2154873265
// Blood Group: A+ve
// Last Donation Date (yyyy-mm-dd): 2023-01-01
// Enter details for donor 2:
// Name: rohan
// Age: 30
// Address: mumbai
// Contact Number: 9865322154
// Blood Group: B+ve
// Last Donation Date (yyyy-mm-dd): 2024-09-20
localhost:58390/536b63e9-c1e4-4f6d-b366-7d1a126d1688/ 3/3
10/13/24, 9:20 PM slip27_1.java
slip27_1.java
// Define an Employee class with suitable attributes having getSalary() method, which returns
// salary withdrawn by a particular employee. Write a class Manager which extends a class
// Employee, override the getSalary() method, which will return salary of manager by adding
// traveling allowance, house rent allowance etc.
class Employee {
String name;
double basicSalary;
@Override
public double getSalary() {
return basicSalary + travelAllowance + houseRentAllowance;
}
}
// output =
// Employee Salary: 50000.0
// Manager Salary: 85000.0
localhost:58390/fafda058-a5b3-40fc-877f-9631f023faf3/ 1/1
10/13/24, 9:20 PM slip27_2.java
slip27_2.java
// Write a program to accept a string as command line argument and check whether it is a file or
// directory. Also perform operations as follows:
// DIf it is a directory,delete all text files in that directory. Confirm delete operation from
// user before deleting text files. Also, display a count showing the number of files deleted,
// if any, from the directory.
// iD)If it is a file display various details of that file.
import [Link];
import [Link];
if ([Link]()) {
if ([Link]()) {
deleteTextFiles(file);
} else if ([Link]()) {
displayFileDetails(file);
} else {
[Link]("The path is neither a file nor a directory.");
}
} else {
[Link]("The specified path does not exist.");
}
}
int deletedCount = 0;
Scanner scanner = new Scanner([Link]);
localhost:58390/eca80e7f-76cf-4eac-b398-44fa9cf3919f/ 1/2
10/13/24, 9:20 PM slip27_2.java
if ([Link]("yes")) {
for (File file : files) {
if ([Link]() && [Link]().endsWith(".txt")) {
if ([Link]()) {
deletedCount++;
} else {
[Link]("Failed to delete: " + [Link]());
}
}
}
[Link](deletedCount + " text files deleted from the directory.");
} else {
[Link]("Deletion canceled.");
}
[Link]();
}
localhost:58390/eca80e7f-76cf-4eac-b398-44fa9cf3919f/ 2/2
10/13/24, 9:20 PM slip29_1.java
slip29_1.java
import [Link];
import [Link];
import [Link];
class Customer {
int custNo;
String custName;
String contactNumber;
String custAddr;
public slip29_1() {
customers = new ArrayList<>();
[Link](new Customer(1, "John Doe", "9876543210", "123 Main St"));
[Link](new Customer(2, "Jane Smith", "9876543211", "456 Elm St"));
[Link](new Customer(3, "Alice Johnson", "9876543212", "789 Pine St"));
}
[Link]();
}
localhost:58390/871052fd-e6e0-4535-8d53-bb1f1585b3c0/ 1/2
10/13/24, 9:20 PM slip29_1.java
// output =
// Enter contact number to search: 9876543210
// Customer Number: 1
// Customer Name: John Doe
// Contact Number: 9876543210
// Customer Address: 123 Main St
localhost:58390/871052fd-e6e0-4535-8d53-bb1f1585b3c0/ 2/2
10/13/24, 9:20 PM slip29_2.java
slip29_2.java
// Write a program to create a super class Vehicle having members Company and price.
// Derive two different classes LightMotorVehicle(mileage) and HeavyMotorVehicle
// (capacity_in_tons). Accept the information for "n" vehicles and display the information in
// appropriate form. While taking data, ask user about the type of vehicle first.
import [Link];
import [Link];
import [Link];
class Vehicle {
String c; // Company
double p; // Price
@Override
public void displayInfo() {
[Link]();
[Link]("Mileage: " + m + " km/l");
}
}
@Override
public void displayInfo() {
[Link]();
[Link]("Capacity: " + cap + " tons");
localhost:58390/a811a3c4-daf2-40d3-9919-71832f48d72d/ 1/3
10/13/24, 9:20 PM slip29_2.java
}
}
if (v != null) {
[Link](v);
}
[Link](); // Consume newline
}
[Link]("\nVehicle Information:");
for (Vehicle v : vList) {
[Link]();
[Link]("--------------------------");
}
[Link]();
}
}
// output =
// Enter the number of vehicles: 2
// Enter vehicle type (Light/Heavy): light
// Enter Company Name: toyato
localhost:58390/a811a3c4-daf2-40d3-9919-71832f48d72d/ 2/3
10/13/24, 9:20 PM slip29_2.java
// Vehicle Information:
// Company: toyato, Price: $500000.0
// Mileage: 15.0 km/l
// --------------------------
// Company: volva, Price: $200000.0
// Capacity: 20.0 tons
// --------------------------
localhost:58390/a811a3c4-daf2-40d3-9919-71832f48d72d/ 3/3
10/13/24, 9:21 PM slip30_1.java
slip30_1.java
// Write program to define class Person with data member as Personname,Aadharno, Panno.
// Accept information for 5 objects and display appropriate information (use this keyword).
import [Link];
class Person {
String personName;
String aadharNo;
String panNo;
[Link]("\nPerson Information:");
// Display information for each Person object
for (Person person : persons) {
[Link]();
}
[Link]();
}
localhost:58390/c3639455-99ec-440e-942b-01d72bf0f54f/ 1/2
10/13/24, 9:21 PM slip30_1.java
// output =
// Enter Person Name: John Doe
// Enter Aadhar No: 1234-5678-9012
// Enter PAN No: ABCDE1234F
// Enter Person Name: Jane Smith
// Enter Aadhar No: 9876-5432-1098
// Enter PAN No: WXYZT5678G
// Enter Person Name: Alice Johnson
// Enter Aadhar No: 5678-1234-4567
// Enter PAN No: PQRSF2345H
// Enter Person Name: Bob Brown
// Enter Aadhar No: 4321-8765-6789
// Enter PAN No: LMNOP6789J
// Enter Person Name: Charlie Black
// Enter Aadhar No: 3456-7890-1234
// Enter PAN No: UVWXY2345K
// Person Information:
// Name: John Doe
// Aadhar No: 1234-5678-9012
// PAN No: ABCDE1234F
// ----------------------------
// Name: Jane Smith
// Aadhar No: 9876-5432-1098
// PAN No: WXYZT5678G
// ----------------------------
// Name: Alice Johnson
// Aadhar No: 5678-1234-4567
// PAN No: PQRSF2345H
// ----------------------------
// Name: Bob Brown
// Aadhar No: 4321-8765-6789
// PAN No: LMNOP6789J
// ----------------------------
// Name: Charlie Black
// Aadhar No: 3456-7890-1234
// PAN No: UVWXY2345K
// ----------------------------
localhost:58390/c3639455-99ec-440e-942b-01d72bf0f54f/ 2/2
10/13/24, 8:39 PM slip30_2.java
slip30_2.java
import [Link].*;
import [Link].*;
localhost:58315/060e9daa-c308-4521-8347-8b4c922ad3bf/ 1/2
10/13/24, 8:39 PM slip30_2.java
[Link](true);
}
}
localhost:58315/060e9daa-c308-4521-8347-8b4c922ad3bf/ 2/2