Kaushikoop 1
Kaushikoop 1
Practical-6
Program -1: Create ArrayList mover. In which selected
element of one list moved to another.
i.e.
Java
DAA
Maths-I
EME
Database
Maths-I Java
EME DAA
Database
CODE:
import java.util.ArrayList;
Page | 30
KAUSHIK VADOLIYA Practical-6 220470107179
// Define the subjects to move
String[] subjectsToMove = {"COA", "PEM","OS"};
OUTPUT:
Page | 31
KAUSHIK VADOLIYA Practical-6 220470107179
// Scanner for user input
Scanner scanner = new Scanner(System.in);
scanner.close();
}
}
OUTPUT:
Enter name:
a1
Page | 32
KAUSHIK VADOLIYA Practical-6 220470107179
12547895648
Enter name:
a2
1236585965
Enter name:
a3
4585965231
a1
a1=12547895648
a4
Not found
Page | 33
KAUSHIK VADOLIYA Practical-7 220470107179
Practical-7
Program-1: Design program to print a string with TypeWriter
effect.
CODE:
public class TypeWriterEffect {
public static void main(String[] args) {
String text = "Hello, this is a TypeWriter effect!";
int delay = 100; // delay in milliseconds
typeWriter(text, delay);
}
OUTPUT:
Page | 34
KAUSHIK VADOLIYA Practical-7 220470107179
public class PrettyPrinter {
private final Lock lock = new ReentrantLock();
thread1.start();
thread2.start();
}
}
OUTPUT:
Thread 1: Hello!
Thread 2: Hi there!
Page | 35
KAUSHIK VADOLIYA Practical-8 220470107179
Practical-8
Program-1: Write a program to export book data in csv
format.
CODE:
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
exportToCsv(books, "books.csv");
}
Page | 36
KAUSHIK VADOLIYA Practical-8 220470107179
public Book(String isbn, String title, String author, double price) {
this.isbn = isbn;
this.title = title;
this.author = author;
this.price = price;
}
OUTPUT:
Page | 37
KAUSHIK VADOLIYA Practical-8 220470107179
String filePath = "data.txt";
// Write to file
writeToFile(filePath, "Hello, world!");
// Append to file
appendToFile(filePath, "\nThis is a new line.\n this is file read");
content = readFromFile(filePath);
System.out.println("Updated file content: " + content);
}
OUTPUT:
___________________________________________________________________________
Page | 39
KAUSHIK VADOLIYA Practical-9 220470107179
Practical-9
Program-1: Implement a utility to get content from input url.
COAD:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
try {
String content = getContentFromUrl(url);
System.out.println("Content from URL: \n" + content);
} catch (IOException e) {
System.out.println("Error reading content from URL: " + e.getMessage());
}
}
return contentBuilder.toString();
}
}
OUTPUT:
Page | 40
KAUSHIK VADOLIYA Practical-9 220470107179
Content from URL:
<!doctype html>
<html>
<head>
<title>Example Domain</title>
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
div {
width: 600px;
padding: 2em;
background-color: #fdfdff;
border-radius: 0.5em;
Page | 41
KAUSHIK VADOLIYA Practical-9 220470107179
box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
a:link, a:visited {
color: #38488f;
text-decoration: none;
div {
margin: 0 auto;
width: auto;
</style>
</head>
<body>
<div>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples in documents. You may use this
</div>
</body>
</html>
Page | 42
KAUSHIK VADOLIYA Practical-10 220470107179
Practical-10
Program-1: Write a javafx form for user signup which
includes username(Textfield), password(passwordfield),
gender(radiobutton),branch(combobox),address(textarea),h
obbies(checkbox). Create two buttons display value of user
data into a label. signup(button), clear(button)
CODE:
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("User Signup Form");
// Create buttons
Button submitButton = new Button("Submit");
Button clearButton = new Button("Clear");
Page | 43
KAUSHIK VADOLIYA Practical-10 220470107179
// Create label to display user data
Label displayLabel = new Label();
// Button actions
submitButton.setOnAction(event -> {
// Gather user data
String username = usernameTextField.getText();
String password = passwordField.getText();
String gender = ((RadioButton)
genderToggleGroup.getSelectedToggle()).getText();
String branch = branchComboBox.getValue();
String address = addressTextArea.getText();
StringBuilder hobbies = new StringBuilder();
if (footballCheckBox.isSelected()) hobbies.append("Football, ");
if (basketballCheckBox.isSelected()) hobbies.append("Basketball, ");
if (cricketCheckBox.isSelected()) hobbies.append("Cricket, ");
// Display user data
displayLabel.setText("Username: " + username + "\nPassword: " + password +
"\nGender: " + gender +
"\nBranch: " + branch + "\nAddress: " + address + "\nHobbies: " +
hobbies.toString());
});
clearButton.setOnAction(event -> {
// Clear all fields
usernameTextField.clear();
passwordField.clear();
genderToggleGroup.selectToggle(null);
branchComboBox.getSelectionModel().clearSelection();
addressTextArea.clear();
footballCheckBox.setSelected(false);
basketballCheckBox.setSelected(false);
cricketCheckBox.setSelected(false);
displayLabel.setText("");
});
// Create layout
GridPane grid = new GridPane();
grid.setPadding(new Insets(20));
grid.setVgap(10);
grid.setHgap(10);
grid.add(new Label("Username:"), 0, 0);
grid.add(usernameTextField, 1, 0);
grid.add(new Label("Password:"), 0, 1);
grid.add(passwordField, 1, 1);
grid.add(new Label("Gender:"), 0, 2);
VBox genderBox = new VBox(5, maleRadioButton, femaleRadioButton);
grid.add(genderBox, 1, 2);
grid.add(new Label("Branch:"), 0, 3);
grid.add(branchComboBox, 1, 3);
Page | 44
KAUSHIK VADOLIYA Practical-10 220470107179
grid.add(new Label("Address:"), 0, 4);
grid.add(addressTextArea, 1, 4);
grid.add(new Label("Hobbies:"), 0, 5);
VBox hobbiesBox = new VBox(5, footballCheckBox, basketballCheckBox,
cricketCheckBox);
grid.add(hobbiesBox, 1, 5);
// Buttons
HBox buttonBox = new HBox(10, submitButton, clearButton);
grid.add(buttonBox, 1, 6);
// Display label
grid.add(displayLabel, 0, 7, 2, 1);
OUTPUT:
Page | 45
KAUSHIK VADOLIYA Practical-10 220470107179
Program-2: Write a javafx program to move a circle from left
to right when navigation keys been clicked. when mouse
hovered over the circle then it change the color of circle.
CODE:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
@Override
public void start(Stage primaryStage) {
Circle circle = new Circle(CIRCLE_RADIUS, Color.BLUE);
circle.setTranslateX(250);
circle.setTranslateY(250);
scene.setOnKeyPressed(e -> {
if (e.getCode() == KeyCode.LEFT) {
circle.setTranslateX(circle.getTranslateX() - MOVE_DISTANCE);
} else if (e.getCode() == KeyCode.RIGHT) {
circle.setTranslateX(circle.getTranslateX() + MOVE_DISTANCE);
} else if (e.getCode() == KeyCode.UP) {
circle.setTranslateY(circle.getTranslateY() - MOVE_DISTANCE);
} else if (e.getCode() == KeyCode.DOWN) {
circle.setTranslateY(circle.getTranslateY() + MOVE_DISTANCE);
}
});
primaryStage.setScene(scene);
primaryStage.setTitle("Circle Movement");
primaryStage.show();
}
Page | 46
KAUSHIK VADOLIYA Practical-10 220470107179
OUTPUT:
Page | 47
KAUSHIK VADOLIYA Practical-10 220470107179
import javafx.stage.Stage;
import java.io.File;
@Override
public void start(Stage primaryStage) {
String mp3File = "sample.mp3";
String mp4File = "sample.mp4";
mediaPlayer.play();
videoPlayer.play();
}
Page | 48