Java Programming: Assessment-5

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

JAVA PROGRAMMING

Assessment-5
NAME: Asmit Gupta
REG. NO.:18BCE0904
SLOT: L53+L54
FACULTY: ASIS KUMAR TRIPATHY
Q1. Write a program to demonstrate the object serialization and
deserialization when one object holds information about the salary
the employees of an organization.
Code:-
import java.io.*;

class Employee implements Serializable


{
String name;
int age;
int salary;

// Default constructor
public Employee(String name, int age, int salary)
{
this.name = name;
this.age = age;
this.salary = salary;
}

public class asmitda5q1


{
public static void main(String[] args)
{
Employee object = new Employee("Asmit Gupta", 18, 25000);
String filename = "file.ser";
// Serialization
try
{
FileOutputStream file = new FileOutputStream(filename);
ObjectOutputStream out = new ObjectOutputStream(file);

out.writeObject(object);

out.close();
file.close();

System.out.println("Object has been serialized");

catch(IOException ex)
{
System.out.println("IOException is caught");
}

Employee object1 = null;

// Deserialization
try
{
FileInputStream file = new FileInputStream(filename);
ObjectInputStream in = new ObjectInputStream(file);

object1 = (Employee)in.readObject();

in.close();
file.close();

System.out.println("Object has been deserialized ");


System.out.println("Name = " + object1.name);
System.out.println("Age = " + object1.age);
System.out.println("Salary = " + object1.salary);
}

catch(IOException ex)
{
System.out.println("IOException is caught");
}
catch(ClassNotFoundException ex)
{
System.out.println("ClassNotFoundException is caught");
}

}
}

OUTPUT:-

Q2:- Create a LinkedHashmap and store the name and regd no of your
ten number of friends, finally delete one of your friend data from the
map
CODE:-

import java.util.*;

public class asmitda5q2 {

public static void main(String args[])


{

LinkedHashMap<String, String> newmap= new LinkedHashMap<String, String>();

newmap.put("18bce0904", "asmit");

newmap.put("18bce0956", "anmol");
newmap.put("18bce0456", "ankit");
newmap.put("18bce2254", "yash");
newmap.put("18bee2044", "aman");
System.out.println("Mappings of LinkedHashMap : "+ newmap);

System.out.println();
newmap.remove("18bce904");
System.out.println("Updated mappings: " + newmap);

System.out.println();
}
}

OUTPUT:-

Q3:- Show one stage using JAVAFX where your name will be displayed
in red color
CODE:-
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;

public class App extends Application {


@Override
public void start(Stage stage) {
Text text = new Text();
text.setX(50);
text.setY(130);
text.setFill(Color.RED);
text.setText("Asmit Gupta");
Group root = new Group(text);
Scene scene = new Scene(root, 600, 300);
stage.setTitle("Asmit Gupta(18bce0904)");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}

OUTPUT:-
Q4:- Show one stage using JAVAFX where your name will be displayed
in red color.
CODE:-
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;

public class App extends Application {

@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("ASMIT GUPTA");

Button button1 = new Button("1");


Button button2 = new Button("2");
Button button3 = new Button("3");
Button button4 = new Button("4");
Button button5 = new Button("5");
Button button6 = new Button("6");
Button button7 = new Button("7");
Button button8 = new Button("8");
Button button9 = new Button("9");
Button button0 = new Button("0");
Button buttonp = new Button(". ");
Button buttone = new Button("=");
Button buttonac = new Button("C");

Button buttonmul = new Button("+");


Button buttonmin = new Button("- ");
Button buttondiv = new Button("/ ");
TextField b = new TextField();
StackPane r = new StackPane();
r.getChildren().add(b);
GridPane gridPane = new GridPane();

gridPane.add(r, 0, 0, 4, 1);
gridPane.add(button1, 0, 1, 1, 1);
gridPane.add(button2, 1, 1, 1, 1);
gridPane.add(button3, 2, 1, 1, 1);
gridPane.add(buttonmul, 3, 1, 1, 1);
gridPane.add(button4, 0, 2, 1, 1);
gridPane.add(button5, 1, 2, 1, 1);
gridPane.add(button6, 2, 2, 1, 1);
gridPane.add(buttonmin, 3, 2, 1, 1);
gridPane.add(button7, 0, 3, 1, 1);
gridPane.add(button8, 1, 3, 1, 1);
gridPane.add(button9, 2, 3, 1, 1);
gridPane.add(buttondiv, 3, 3, 1, 1);
gridPane.add(button0, 0, 4, 1, 1);
gridPane.add(buttonp, 1, 4, 1, 1);
gridPane.add(buttone, 2, 4, 1, 1);
gridPane.add(buttonac, 3, 4, 1, 1);

Scene scene = new Scene(gridPane, 500, 500);


primaryStage.setScene(scene);
primaryStage.show(); }

public static void main(String[] args) {


Application.launch(args);
}
}
OUTPUT:-
Q5:- Write a program to design your mobile screen where the icons
available on your screen will be present and your image will be
displayed in the middle
CODE:-

import java.io.FileInputStream;

import java.io.FileNotFoundException;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
public class App extends Application {
@Override
public void start(Stage stage) throws FileNotFoundException {
Image imagepp = new Image(new FileInputStream("C:\\Users\\TEMP.LAPTOP-
KROJC7S1.009\\Pictures\\Screenshots\\pp.jpeg"));
Image imagefb = new Image(new FileInputStream("C:\\Users\\TEMP.LAPTOP-
KROJC7S1.009\\Pictures\\Screenshots\\fb.png"));
Image imageinst = new Image(new FileInputStream("C:\\Users\\TEMP.LAPTOP-
KROJC7S1.009\\Pictures\\Screenshots\\instagram.png"));
Image imagesp = new Image(new FileInputStream("C:\\Users\\TEMP.LAPTOP-
KROJC7S1.009\\Pictures\\Screenshots\\snapchat.png"));
Image imagewh = new Image(new FileInputStream("C:\\Users\\TEMP.LAPTOP-
KROJC7S1.009\\Pictures\\Screenshots\\whatsapp.png"));
Image imagewo = new Image(new FileInputStream("C:\\Users\\TEMP.LAPTOP-
KROJC7S1.009\\Pictures\\Screenshots\\word.png"));
Image imageyo = new Image(new FileInputStream("C:\\Users\\TEMP.LAPTOP-
KROJC7S1.009\\Pictures\\Screenshots\\youtube.png"));

ImageView imageView1 = new ImageView(imagesp);


imageView1.setX(50);
imageView1.setY(25);
imageView1.setFitHeight(100);
imageView1.setFitWidth(100);
imageView1.setPreserveRatio(true);
ImageView imageView4 = new ImageView(imagefb);
imageView4.setX(50);
imageView4.setY(150);
imageView4.setFitHeight(100);
imageView4.setFitWidth(100);
imageView4.setPreserveRatio(true);
ImageView imageView5 = new ImageView(imageinst);
imageView5.setX(50);
imageView5.setY(275);
imageView5.setFitHeight(100);
imageView5.setFitWidth(100);
imageView5.setPreserveRatio(true);
ImageView imageView2 = new ImageView(imagepp);
imageView2.setX(175);
imageView2.setY(25);
imageView2.setFitHeight(380);
imageView2.setFitWidth(350);
ImageView imageView3 = new ImageView(imagewh);
imageView3.setX(550);
imageView3.setY(25);
imageView3.setFitHeight(100);
imageView3.setFitWidth(100);
imageView3.setPreserveRatio(true);
ImageView imageView6 = new ImageView(imageyo);
imageView6.setX(550);
imageView6.setY(150);
imageView6.setFitHeight(100);
imageView6.setFitWidth(100);
imageView6.setPreserveRatio(true);
ImageView imageView7 = new ImageView(imagewo);
imageView7.setX(550);
imageView7.setY(250);
imageView7.setFitHeight(100);
imageView7.setFitWidth(100);
imageView7.setPreserveRatio(true);
Group root = new Group(imageView1,imageView5,imageView4, imageView2,imageView
3,imageView6,imageView7);
Scene scene = new Scene(root, 800, 500);
stage.setTitle("Asmit Gupta(18bce0904)");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]) {
launch(args);
}
}
OUTPUT:-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy