0% found this document useful (0 votes)
126 views

Name: Alka Registration Number: 17bce2287 Set A: Ques1

The document describes a Java program that creates classes for different types of employees (Manager, TechLead, Developer, Trainee) that inherit from a base Employee class and override a display method. The program tests objects from each employee class by creating objects, setting their attributes like salary and evaluation points, and calling the display method. It also includes a GUI program using JavaFX that allows calculating the area of different shapes by taking user input for attributes.

Uploaded by

Alka
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views

Name: Alka Registration Number: 17bce2287 Set A: Ques1

The document describes a Java program that creates classes for different types of employees (Manager, TechLead, Developer, Trainee) that inherit from a base Employee class and override a display method. The program tests objects from each employee class by creating objects, setting their attributes like salary and evaluation points, and calling the display method. It also includes a GUI program using JavaFX that allows calculating the area of different shapes by taking user input for attributes.

Uploaded by

Alka
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

NAME : ALKA

REGISTRATION NUMBER : 17BCE2287

SET A

QUES1

Assume you have a class ‘Employee’ with all basic information (e_id, name, sal)
and a method to display its details. Using this class create new classes like
‘Manager’, ‘Team Lead’, ‘Developer’, and ‘Trainee’ with their own specific
information (necessarily, eval_pts). For the yearly appraisal they should earn 10
evaluation points in the last financial year. Add 15% of their salary to their current
salary as an increment if they are eligible. Redefine the display method in the new
classes to display updated details. Write a Java program to test at least one object
in each (four) category of employees.

CODE

import java.util.*;

public class Employee

int id;

static double sal;

String name;

static int eval_pts;

public void get(int id,double sal,String name,int eval_pts)

{
this.id=id;

this.sal=sal;

this.name=name;

this.eval_pts=eval_pts;

public void display()

System.out.println("Name = "+name);

System.out.println("Salary = "+sal);

System.out.println("Id = "+id);

System.out.println("Evalpoint got = "+eval_pts);

public static class Manager

public void evaluate()

if(eval_pts>=10)
{

sal=0.15*sal + sal;

public static class TechLead

public void evaluate()

if(eval_pts>=10)

sal=0.15*sal + sal;

public static class Developer

public void evaluate()

{
if(eval_pts>=10)

sal=0.15*sal + sal;

public static class Trainee

public void evaluate()

if(eval_pts>=10)

sal=0.15*sal + sal;

public static void main(String args[])

{
System.out.println("Manager\n");

Employee obj1 = new Employee();

obj1.get(101,1000,"RAJA",10);

Manager obj2 = new Manager();

obj2.evaluate();

obj1.display();

System.out.print("\n");

System.out.println("TechLead\n");

Employee obj3 = new Employee();

obj3.get(102,2000,"RITA",8);

TechLead obj4 = new TechLead();

obj4.evaluate();

obj3.display();

System.out.print("\n");

System.out.println("Developer\n");

Employee obj5 = new Employee();

obj5.get(103,3000,"RIYA",15);

Developer obj6 = new Developer();


obj6.evaluate();

obj5.display();

System.out.print("\n");

System.out.println("Trainee\n");

Employee obj7 = new Employee();

obj7.get(104,4000,"Raju",6);

Trainee obj8 = new Trainee();

obj8.evaluate();

obj7.display();

}
QUES2

Design a menu driven GUI application using JavaFX classes to compute the area of
different polygons such as

Square

Rectangle

Triangle

Circle

CODE

MAIN.JAVA
package application;

import javafx.application.Application;

import javafx.fxml.FXMLLoader;

import javafx.scene.Parent;

import javafx.scene.Scene;

//import javafx.scene.layout.BorderPane;

import javafx.stage.Stage;

public class Main extends Application {

@Override

public void start(Stage primaryStage) {

try {

// BorderPane root = new BorderPane();

Parent root =
FXMLLoader.load(getClass().getClassLoader().getResource("application/Main.fxml
"));

Scene scene = new Scene(root);

scene.getStylesheets().add(getClass().getResource("application.css").toExte
rnalForm());
primaryStage.setScene(scene);

primaryStage.show();

} catch(Exception e) {

e.printStackTrace();

public static void main(String[] args) {

launch(args);

MAINCONTROLLER.JAVA

package application;

import javafx.event.ActionEvent;

import javafx.fxml.FXML;

import javafx.scene.control.Button;

import javafx.scene.control.Label;

import javafx.scene.control.TextField;

public class MainController {

@FXML
private TextField sq_len;

@FXML

private TextField rect_l;

@FXML

private TextField rect_b;

@FXML

private TextField tri_l;

@FXML

private TextField tri_h;

@FXML

private TextField circle_r;

@FXML

private Label result;

@FXML

private Button sqButton;

@FXML

private Button rectButton;

@FXML

private Button triButton;

@FXML
private Button circleButton;

public void Output1(ActionEvent event) {

float sqLen =Float.parseFloat(sq_len.getText()) ;

float r = sqLen*sqLen;

System.out.print(r);

result.setText(String.valueOf(r));

public void Output2(ActionEvent event) {

float rectLen =Float.parseFloat(rect_l.getText()) ;

float rectb =Float.parseFloat(rect_b.getText()) ;

float r = rectLen*rectb;

System.out.print(r);

result.setText(String.valueOf(r));

public void Output3(ActionEvent event) {

float triangle_l =Float.parseFloat(tri_l.getText()) ;

float triangle_h =Float.parseFloat(tri_h.getText()) ;


float r = triangle_l*triangle_h/2;

System.out.print(r);

result.setText(String.valueOf(r));

public void Output4(ActionEvent event) {

float circle_l =Float.parseFloat(circle_r.getText()) ;

float r = circle_l*circle_l*((float)3.14);

System.out.print(r);

result.setText(String.valueOf(r));

MAIN.FXML

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

<?import javafx.geometry.Insets?>

<?import javafx.scene.control.Button?>

<?import javafx.scene.control.Label?>

<?import javafx.scene.control.TextField?>

<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>

<?import javafx.scene.text.Font?>

<?import javafx.scene.text.Text?>

<AnchorPane prefHeight="600.0" prefWidth="400.0"


xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="application.MainController">

<children>

<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="50.0"


prefWidth="400.0" style="-fx-background-color: grey;" text="LAB-FAT
(CALCULATE AREA)" textAlignment="CENTER">

<font>

<Font name="System Bold" size="18.0" />

</font>

</Label>

<HBox alignment="CENTER_LEFT" layoutY="143.0" prefHeight="50.0"


prefWidth="400.0">

<children>

<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Square:"


wrappingWidth="100.0">

<font>

<Font size="18.0" />

</font>

<HBox.margin>
<Insets left="10.0" />

</HBox.margin>

</Text>

<TextField fx:id="sq_len" prefHeight="26.0" prefWidth="50.0" />

<Button fx:id="sqButton" mnemonicParsing="false" onAction="#Output1"


prefHeight="26.0" prefWidth="84.0" text="Click Here!!"
textAlignment="CENTER">

<HBox.margin>

<Insets left="100.0" />

</HBox.margin>

</Button>

</children>

</HBox>

<HBox alignment="CENTER_LEFT" layoutY="193.0" prefHeight="50.0"


prefWidth="400.0">

<children>

<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Rectangle:"


wrappingWidth="100.0">

<font>

<Font size="18.0" />

</font>

<HBox.margin>

<Insets left="10.0" />


</HBox.margin>

</Text>

<TextField fx:id="rect_l" prefHeight="26.0" prefWidth="50.0" />

<TextField fx:id="rect_b" prefHeight="26.0" prefWidth="50.0">

<HBox.margin>

<Insets left="10.0" />

</HBox.margin>

</TextField>

<Button fx:id="rectButton" mnemonicParsing="false"


onAction="#Output2" prefHeight="26.0" prefWidth="84.0" text="Click Here!!"
textAlignment="CENTER">

<HBox.margin>

<Insets left="40.0" />

</HBox.margin>

</Button>

</children>

</HBox>

<HBox alignment="CENTER_LEFT" layoutY="243.0" prefHeight="50.0"


prefWidth="400.0">

<children>

<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Triangle:"


wrappingWidth="100.0">

<font>
<Font size="18.0" />

</font>

<HBox.margin>

<Insets left="10.0" />

</HBox.margin>

</Text>

<TextField fx:id="tri_l" prefHeight="26.0" prefWidth="50.0" />

<TextField fx:id="tri_h" prefHeight="26.0" prefWidth="50.0">

<HBox.margin>

<Insets left="10.0" />

</HBox.margin>

</TextField>

<Button fx:id="triButton" mnemonicParsing="false" onAction="#Output3"


prefHeight="26.0" prefWidth="84.0" text="Click Here!!"
textAlignment="CENTER">

<HBox.margin>

<Insets left="40.0" />

</HBox.margin>

</Button>

</children>

</HBox>

<HBox alignment="CENTER_LEFT" layoutY="300.0" prefHeight="50.0"


prefWidth="400.0">
<children>

<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Circle: "


wrappingWidth="100.0">

<font>

<Font size="18.0" />

</font>

<HBox.margin>

<Insets left="10.0" />

</HBox.margin>

</Text>

<TextField fx:id="circle_r" prefHeight="26.0" prefWidth="50.0" />

<Button fx:id="circleButton" mnemonicParsing="false"


onAction="#Output4" prefHeight="26.0" prefWidth="84.0" text="Click Here!!"
textAlignment="CENTER">

<HBox.margin>

<Insets left="100.0" />

</HBox.margin>

</Button>

</children>

</HBox>

<Text layoutX="7.0" layoutY="410.0" strokeType="OUTSIDE"


strokeWidth="0.0" text="Result:" wrappingWidth="100.0">

<font>
<Font size="18.0" />

</font>

</Text>

<Label fx:id="result" layoutY="416.0" prefHeight="83.0" prefWidth="400.0">

<font>

<Font size="18.0" />

</font>

</Label>

</children>

</AnchorPane>

OUTPUT

You might also like