Professional Documents
Culture Documents
PRIYANSHU_WT_FILE_p
PRIYANSHU_WT_FILE_p
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
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);
Case 1:
Case2:
Experiment – 6
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
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:
return {
userAgent,
browserName,
browserVersion
};
}
document.getElementById('browser-name').textContent = browserName;
document.getElementById('browser-version').textContent = browserVersion;
document.getElementById('user-agent').textContent = userAgent;
}
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: