Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

Experiment- 1

Objective: Write a program to perform multiple inheritance in java using


interface.
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Registration Form</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
padding: 20px;
}h2 {
text-align: center;
} form {
background-color: #ffffff;
padding: 20px;
border-radius: 5px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
width: 400px;
margin: auto;
} label {
font-weight: bold;
display: block;
margin-bottom: 8px;
} input[type="text"], input[type="email"], select {
width: 100%;
padding: 8px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
} input[type="submit"] {
background-color: #4CAF50;
color: white;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
width: 100%;
}input[type="submit"]: hover {
background-color: #45a049; }
</style>
</head>
<body>
<h2>Student Registration Form</h2>
<form action="#" method="post">
<label for="name">Full Name</label>
<input type="text" id="name" name="name" placeholder="Enter your full name"
required>
<label for="email">Email</label>
<input type="email" id="email" name="email" placeholder="Enter your email address"
required>
<label for="dob">Date of Birth</label>
<input type="text" id="dob" name="dob" placeholder="YYYY-MM-DD" required>
<label for="gender">Gender</label>
<select id="gender" name="gender" required>
<option value="">Select</option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
</select>
<label for="address">Address</label>
<input type="text" id="address" name="address" placeholder="Enter your address"
required>
<label for="phone">Phone Number</label>
<input type="text" id="phone" name="phone" placeholder="Enter your phone number"
required>
<input type="submit" value="Submit">
</form>
</body> </html>
Output:
Experiment- 2

Objective: Write a program to perform multiple inheritance in java using


interface.
Code:
interface Animal {
void eat();
void sleep();
}
// Define the second interface
interface Pet {
void play();
}
// Implementing class that inherits from both interfaces
class Dog implements Animal, Pet {
public void eat() {
System.out.println("Dog is eating");
}
public void sleep() {
System.out.println("Dog is sleeping");
}
public void play() {
System.out.println("Dog is playing");
}
} public class Main {
public static void main(String[] args) {
// Create an instance of Dog
Dog myDog = new Dog();
// Call methods inherited from Animal interface
myDog.eat();
myDog.sleep();
// Call method inherited from Pet interface
myDog.play();
} }
Output:
Experiment – 3

Objective: Write a program to calculate the area of circle, rectangle and tringle
using method overloading.

Code:
import java.util.Scanner;
public class AreaCalculator {
// Method to calculate area of a circle
public static double calculateCircleArea(double radius) {
return Math.PI * radius * radius; }
// Method to calculate area of a rectangle
public static double calculateRectangleArea(double length, double width) {
return length * width;
}
// Method to calculate area of a triangle
public static double calculateTriangleArea(double base, double height) {
return 0.5 * base * height; }
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("1. Calculate Area of Circle");
System.out.println("2. Calculate Area of Rectangle");
System.out.println("3. Calculate Area of Triangle");
System.out.print("Enter your choice (1, 2, or 3): ");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.print("Enter radius of the circle: ");
double radius = scanner.nextDouble();
double circleArea = calculateCircleArea(radius);
System.out.println("Area of the circle: " + circleArea);
break;
case 2:
System.out.print("Enter length of the rectangle: ");
double length = scanner.nextDouble();
System.out.print("Enter width of the rectangle: ");
double width = scanner.nextDouble();
double rectangleArea = calculateRectangleArea(length, width);
System.out.println("Area of the rectangle: " + rectangleArea);
break;
case 3:
System.out.print("Enter base of the triangle: ");
double base = scanner.nextDouble();
System.out.print("Enter height of the triangle: ");
double height = scanner.nextDouble();
double triangleArea = calculateTriangleArea(base, height);
System.out.println("Area of the triangle: " + triangleArea);
break;
default:
System.out.println("Invalid choice. Please enter 1, 2, or 3.");
break;
}
scanner.close();
}
}
Output:
Case 1: For Circle

Case 2: For Rectangle

Case 3: For Triangle


Experiment -4

Objective: Write a program to calculate the table of 2 & 6 to demonstrate the


concept of multithreading by implementing runnable interface.

Code:
// Define a class that implements the Runnable interface
class MultiplicationTask implements Runnable {
private int number; // Number for which multiplication table will be calculated
// Constructor to initialize the number
public MultiplicationTask(int number) {
this.number = number;
}
// Run method to be executed by the thread
public void run() {
System.out.println("Multiplication table of " + number + ":");
for (int i = 1; i <= 10; i++) {
System.out.println(number + " * " + i + " = " + (number * i));
try {
Thread.sleep(200); // Introduce a small delay for demonstration
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public class MultiplicationTableDemo {
public static void main(String[] args) {
// Create two instances of MultiplicationTask for numbers 2 and 6
MultiplicationTask task2 = new MultiplicationTask(2);
MultiplicationTask task6 = new MultiplicationTask(6);
// Create and start two threads using the MultiplicationTask instances
Thread thread2 = new Thread(task2);
Thread thread6 = new Thread(task6);
// Start the threads
thread2.start();
thread6.start();
}
}
Output:
Experiment – 5

Objective: WAP in Java to create a user defined exception called Invalid Age
Exception where if the user age < 18 then throw the exception otherwise display
“you are not eligible”.

Code:
import java.util.Scanner;
public class AgeValidator {
// Method to validate age and throw custom exception if age is less than 18
public static void validateAge(int age) throws InvalidAgeException {
if (age < 18) {
throw new InvalidAgeException("You are underage. Age must be 18 or above.");
} else {
System.out.println("You are not eligible.");
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter your age: ");


int age = scanner.nextInt();
try {
validateAge(age);
} catch (InvalidAgeException e) {
System.out.println("Invalid Age: " + e.getMessage());
// Additional handling code (if needed)
}
scanner.close();
}
}
// Custom exception class to represent invalid age scenario
class InvalidAgeException extends Exception {
// Constructor to initialize the exception with a custom message
public InvalidAgeException(String message) {
super(message);
}
}
Output:

Case 1:

Case2:
Experiment – 6

Objective: Write HTML/CSS scripts to display your CV in navigator., your


Institute website should be link.

Code:

Html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My CV</title>
<link rel="stylesheet" href="style.css">
</head>

<body>
<header>
<h1>Priyanshu Sharma </h1>
<p>Andriod Developer</p>
</header>

<section class="contact-info">
<h2>Contact Information</h2>
<ul>
<li>Email: priyanshusharma420@gmail.com</li>
<li>Phone: +918791939108</li>
<li>Location: Baghpat, India</li>
</ul>
</section>

<section class="education">
<h2>Education</h2>
<p>Bachelor of Technology<br>
Bachelor of Technology<br>
Graduated: May 2025</p>
</section>

<section class="experience">
<h2>Work Experience</h2>
<p>Andriod Developer - XYZ Company (2018 - Present)<br>
Responsibilities:
<ul>
<li>Developing and maintaining application</li>
<li>Collaborating with UI and clients</li>
<li>Implementing new features and functionalities</li>
</ul>
</p>
</section>

<section class="skills">
<h2>Skills</h2>
<ul>
<li>HTML5, CSS3, JavaScript</li>
<li>Responsive Web Design</li>
<li>Frontend Frameworks (e.g., Bootstrap)</li>
<li>Version Control (Git)</li>
</ul>
</section>
<footer>
<p>Visit my institute's website: <a
href="https://www.ipec.org.in/">IPEC</a></p>
</footer>
</body>

</html>

CSS
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
}
header {
text-align: center;
margin-bottom: 20px;
}
h1 {
color: #333;
font-size: 36px;
}
.contact-info,
.education,
.experience,
.skills {
margin-bottom: 30px;
}
ul {
list-style-type: none;
padding: 0;
}
a{
color: #007bff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
Output:
Experiment -7

Objective: Write a program in XML for creation of DTD which specify set of
rules. Create a styesheet in CSS/XSL and display the document in internet
explorer.

Code:

Xml file

<?xml version="1.0" encoding="UTF-8"?>


<?xml-stylesheet type="text/css" href="D:\workshop\rule.css"?>
<books>

<heading>Welcome to XML file </heading>


<book>
<title>Title : Web Programming</title>
<author>Author: Chrisbates</author>
<publisher>Publisher: Wiley</publisher>
<edition>Edition : 3</edition>
<price> Price : 300</price>
</book>
<book>
<title>Title: Internet world-wide-web</title>
<author>Author: Ditel</author>
<publisher>Publisher: Pearson</publisher>
<edition>Edition : 3</edition>
<price>Price: 400</price>
</book>
<book>
<title>Title : Computer Networks</title>
<author>Author: Foruouzan</author>
<publisher>Publisher: Mc Graw Hill</publisher>
<edition>Edition : 5</edition>
<price>Price : 700</price>
</book>
</books>

CSS

books {
color: white;
background-color : gray;
width: 100%;
}
heading {
color: green;
font-size : 40px;
background-color : powderblue;
}
heading, title, author, publisher, edition, price {
display : block;
}
title {
font-size : 25px;
font-weight : bold;
}
Output:
Experiment – 8

Objective: Write programs using Java script for Web Page to display browser
information.

JS code:

// Function to get browser information


function getBrowserInfo() {
const userAgent = navigator.userAgent;
const browserName = navigator.appName;
const browserVersion = navigator.appVersion;

return {
userAgent,
browserName,
browserVersion
};
}

// Function to display browser information on the HTML page


function displayBrowserInfo() {
const { userAgent, browserName, browserVersion } = getBrowserInfo();

document.getElementById('browser-name').textContent = browserName;
document.getElementById('browser-version').textContent = browserVersion;
document.getElementById('user-agent').textContent = userAgent;
}

// Call displayBrowserInfo function when the DOM content is loaded


document.addEventListener('DOMContentLoaded', displayBrowserInfo);

Html Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Browser Information</title>
<script src="script.js" defer></script>
</head>
<body>
<h1>Browser Information</h1>
<div>
<p><strong>Browser Name:</strong> <span id="browser-
name"></span></p>
<p><strong>Browser Version:</strong> <span id="browser-
version"></span></p>
<p><strong>User Agent:</strong> <span id="user-agent"></span></p>
</div>
</body>
</html>
Output:

You might also like