cbse

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

lOMoARcPSD|6916255

IT PROJECT FOR CLASS 12

physics class 12 (Delhi Public School, Damanjodi)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)
lOMoARcPSD|6916255

PRACTICAL LAB MANUAL

SUBJECT CODE: 802

SUBJECT: IT
CLASS: XII

SUBMITTED TO: SUBMITTED BY:


MONIKA GAUR ARJUN

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

SQL QUERIES

S.NO DATE TOPIC

1 Creation of a database using mysql command.

2 Deletion of a database using mysql command.

3 Creation of a table using mysql command.

4 Show the databases and tables created in mysql.

5 List out the field name along with its field type and
constraints for a table.

6 Set a default value for a field in a table.

7 INSERT VALUES INTO the table.

8 Display the details of a field in a Table based on a given


condition.

9 UPDATE the details of a field in a Table based on a given


condition.

10 AGGREGATE FUNCTIONS in mysql.

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

JAVA PROGRAM

S.NO DATE TOPIC

1 Print the string Hello World.

2 Display character A to Z using for loop.

3 Check if a given Number is Positive or Negative or Zero


using if..else statement.

4 Find the largest among three numbers using if..else


statement.

5 Check whether a number is even or odd using if...else


statement.

6 Generate Multiplication Table (number of iteration from 1


to 10) using for loop.

7 Find the Area of Rectangle by getting the input of length


and breadth from the user during run time.

8 Print the sum of first 10 natural numbers 1 to 10.

9 Generate FIBONACCI SERIES by getting the input of


number of terms in the series during run time.

10 Print the FACTORIAL of a given number.

OPERATING WEB BASED APPLICATION

S.NO DATE TOPIC

1 Online Bill Calculator - Book Rail Ticket

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

SQL
QUERIES

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

1. Write down syntax and mysql program to create a database STUDENT and its
OUTPUT.

AIM

To write a MYSQL code to create a database STUDENT listing out its SYNTAX, and
its OUTPUT.

SYNTAX

PROGRAM

mysql> create database student;

OUTPUT

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

2.Write down syntax and mysql program to delete a database STUDENT and its
OUTPUT.

AIM

To write a MYSQL code to delete a database STUDENT listing out its SYNTAX, and
its OUTPUT.

SYNTAX

PROGRAM

mysql> drop database student;

OUTPUT

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

3.Write down a mysql program to create a table TEACHER with the following field
names given below and its OUTPUT.

⚫ Teacher_ID,
⚫ First_Name,
⚫ Last_Name,
⚫ Gender,
⚫ Salary,
⚫ Date_of_Birth,
⚫ Dept_No

AIM
To write a mysql code to create a table TEACHER with the given field names

⚫ Teacher_ID,
⚫ First_Name,
⚫ Last_Name,
⚫ Gender,
⚫ Salary,
⚫ Date_of_Birth,
⚫ Dept_No

and its OUTPUT.

PROGRAM

mysql> CREATE TABLE TEACHER


→(
→ Teacher_ID INTEGER,
→ First_Name VARCHAR(20),
→ Last_Name VARCHAR(20),
→ Gender CHAR(1),
→ Salary DECIMAL(10,2),
→ Date_of_Birth DATE,
→ Dept_No INTEGER
→);

OUTPUT

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

4. Write down mysql program to show the databases and tables created?

AIM

To write a mysql command to show the databases and tables and its output.

PROGRAM
mysql> show databases;

OUTPUT

PROGRAM
mysql> show tables;

OUTPUT

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

5. Write a mysql program to list out the field name Teacher_ID,


First_Name, Last_Name, Gender, Salary, Date_of_Birth, Dept_No
along with its field type and constraints for the table TEACHER in the
database STUDENT.

AIM
To write a mysql program to list out the field name Teacher_ID, First_Name,
Last_Name, Gender, Salary, Date_of_Birth, Dept_No
along with its field type and constraints for the table TEACHER in the database
STUDENT

PROGRAM
mysql > use student;
Database changed

mysql > desc teacher;

OUTPUT

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

Write down mysql program to set a default value for the field SALARY as
6.
30000 to the table name TEACHER whose field names are listed below
⚫ Teacher_ID,
⚫ First_Name,
⚫ Last_Name,
⚫ Gender,
⚫ Salary,
⚫ Date_of_Birth,
⚫ Dept_No

AIM

To write a mysql command to set a default value for the field SALARY as
30000 in table TEACHER.

PROGRAM

mysql > desc teacher;

mysql > ALTER TABLE TEACHER ALTER SALARY SET DEFAULT 30000;

OUTPUT

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

7.Write a mysql command to INSERT VALUES INTO table TEACHER in its field
Teacher_ID, First_Name, Last_Name, Gender, Salary, Date_of_Birth, Dept_No

AIM

To write a mysql command to INSERT VALUES INTO table TEACHER in its field
Teacher_ID, First_Name, Last_Name, Gender, Salary, Date_of_Birth, Dept_No

PROGRAM

mysql > INSERT INTO Teacher (Teacher_ID, First_Name, Last_Name,


Gender, Salary, Date_of_Birth, Dept_No) VALUES(101,"Shanaya", "Batra",
'F', 50000, '1984-08-11', 1);

OUTPUT

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

8.Write a mysql command to display the details of a Teacher whose


Teacher_ID=101.

The field names in Teacher table is listed below.

⚫ Teacher_ID,
⚫ First_Name,
⚫ Last_Name,
⚫ Gender,
⚫ Salary,
⚫ Date_of_Birth,
⚫ Dept_No

AIM

To write a mysql command to display the details of Teacher_ID=101 in table


TEACHER with its field names listed below.

⚫ Teacher_ID,
⚫ First_Name,
⚫ Last_Name,
⚫ Gender,
⚫ Salary,
⚫ Date_of_Birth,
⚫ Dept_No

PROGRAM

mysql > SELECT * FROM TEACHER WHERE Teacher_ID=101;

OUTPUT

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

9. Write a mysql command to UPDATE the details of Salary as 55000 in Teacher


table whose Teacher_ID=101.

The field names in Teacher table is listed below.

Teacher_ID, First_Name, Last_Name, Gender, Salary, Date_of_Birth, Dept_No

AIM

To write a mysql command to display the UPDATED details of Salary as 55000


for Teacher_ID=101 in table TEACHER with its field names listed below.

Teacher_ID, First_Name, Last_Name, Gender, Salary, Date_of_Birth, Dept_No

PROGRAM

mysql> UPDATE Teacher SET Salary=55000 WHERE Teacher_ID=101;

OUTPUT

10

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

10. Write a mysql command to find the following using AGGREGATE FUNCTIONS
in Table Teacher. The field names in Teacher table is listed below.
Teacher_ID, First_Name, Last_Name, Gender, Salary, Date_of_Birth, Dept_No

(i) Calculate the sum of salary given to the Teachers and name it as Total_Salary.
(ii) Calculate the maximum and minimum salary of the Teacher and name it as
Max_Salary and Min_Salary.
(iii) Calculate the total number of Teachers whose salary is >40000.

AIM

To write mysql command using AGGREGATE FUNCTIONS to


(i) Calculate the sum of salary given to the Teachers and name it as Total_Salary.
(ii) Calculate the maximum and minimum salary of the Teacher and name it as
Max_Salary and Min_Salary.
(iii) Calculate the total number of Teachers whose salary is >40000.
11

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

PROGRAM
mysql > SELECT SUM(Salary) AS Total_Salary FROM Teacher;

OUTPUT

PROGRAM
mysql > SELECT MAX(Salary) AS Max_Salary, MIN(Salary) AS Min_Salary
FROM Teacher;

OUTPUT

PROGRAM
mysql > SELECT COUNT(Salary) FROM Teacher WHERE Salary > 40000;

OUTPUT

12

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

JAVA
PROGRAM

13

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

01. Write a JAVA program to print the string Hello World.

AIM

To write a JAVA program to print the string Hello World.

PROGRAM

// Your First Program

public class Helloworld {


public static void main(String[] args) {
System.out.println("Hello World");
}
}

OUTPUT

Output from Helloworld

14

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

02. Write a Java program to display character A to Z using for loop.

AIM

To write a Java program to display character A to Z using for loop.

PROGRAM

public class CharactersAtoZ {


public static void main(String[] args) {
char c;
for(c = 'A'; c <= 'Z'; c++)
System.out.print(c + " ");
}
}

OUTPUT

15

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

03. Write a Java program to check if a given Number is Positive or Negative or Zero
using if..else statement by getting the input of a number of user choice during
runtime.

AIM

To write a Java program to check if a given Number is Positive or Negative or Zero


using if..else statement by getting the input of a number of user choice during
runtime.

PROGRAM

import java.util.Scanner;
public class PositiveNegativeZero {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("Enter the number: ");
int num = reader.nextInt();
// true if number is less than 0
if (num < 0)
System.out.println(+num + " is a negative number.");
// true if number is greater than 0
else if (num > 0)
System.out.println(+num + " is a positive number.");
// if both test expression is evaluated to false
else
System.out.println(+num + " The given number is zero.");
}
}

OUTPUT

16

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

04. Write a Java program to find the largest among three numbers using if..else
statement by getting the input of three number of user choice during run time.

AIM

To write a Java program to find the largest among three numbers using if..else
statement by getting the input of three number of user choice during run time.

PROGRAM

import java.util.Scanner;
public class LargestOfThree {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("Enter the first number: ");
int n1 = reader.nextInt();
System.out.print("Enter the second number: ");
int n2 = reader.nextInt();
System.out.print("Enter the third number: ");
int n3 = reader.nextInt();
if( n1 >= n2 && n1 >= n3)
System.out.println(n1 + " is the largest number.");
else if (n2 >= n1 && n2 >= n3)
System.out.println(n2 + " is the largest number.");
else
System.out.println(n3 + " is the largest number.");
}
}

OUTPUT

17

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

05. Write a Java program to check whether a number is even or odd using if...else
statement by getting the input of a number of user choice during run time.

AIM

To write a Java program to check whether a number is even or odd using if...else
statement by getting the input of a number of user choice during run time.

PROGRAM

import java.util.Scanner;
public class EvenOdd {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = reader.nextInt();
if(num % 2 == 0)
System.out.println(num + " is even");
else
System.out.println(num + " is odd");
}
}

OUTPUT

18

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

06. Write a Java program to Generate Multiplication Table (number of iteration


(from 1 to 10)) using for loop of a number by getting the input of a number of
user choice during runtime.

AIM

To write a Java program to Generate Multiplication Table (number of iteration


(from 1 to 10) using for loop of a number by getting the input of a number of user
choice during runtime.

PROGRAM

import java.util.Scanner;
public class MultiplicationTable {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("Enter the MultiplicationTable number: ");
int num = reader.nextInt();
for(int i = 1; i <= 10; i++)
{
System.out.printf("%d * %d = %d \n", num, i, num * i);
}
}
}

OUTPUT

19

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

07. Write a Java program to find the Area of Rectangle by getting the input of
length and breadth from the user during run time.

AIM

To write a Java program to find the Area of Rectangle by getting the input of length
and breadth from the user during run time.

PROGRAM

import java.util.Scanner;
public class AreaOfRectangle {
public static void main(String args[])
{
Scanner s= new Scanner(System.in);
System.out.println("Enter the length of the Rectangle:");
double l= s.nextDouble();
System.out.println("Enter the width of the Rectangle:");
double b= s.nextDouble();
double area=l*b;
System.out.println("Area of Rectangle is: " + area);
}
}

OUTPUT

20

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

08. Write a JAVA program to print the sum of first 10 natural numbers 1 to 10.

AIM

To write a JAVA program to print the sum of first 10 natural numbers 1 to 10.

PROGRAM

public class SumNatural {

public static void main(String[] args) {

int i, sum = 0;

for(i = 1; i <= 10; ++i)


{
sum = sum + i;
}

System.out.println("The Sum of first 10 Natural numbers is = " + sum);


}
}

OUTPUT

21

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

09. Write a Java program to print the FIBONACCI SERIES by getting the input of
number of terms in the series during run time.
0 1 1 2 3 5 8 13 21 34

AIM

To write a Java program to print the FIBONACCI SERIES by getting the input of
number of terms in the series during run time.

PROGRAM
import java.util.Scanner;
class Fibonacci
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter number of terms");
int n=s.nextInt();
int num1=-1, num2=1,num3=0;
System.out.println("Fibonacci series is ");
for(int i=0;i<n;i++)
{
num3=num1+num2;
num1=num2;
num2=num3;
System.out.print(num3);
System.out.print("\t");
}
}
}

OUTPUT

22

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

10. Write a Java program to print the FACTORIAL of a given number by getting

23

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

the input of a number of user choice during run time.

AIM

To write a Java program to print the FACTORIAL of a given number by getting the
input of a number of user choice during run time.

PROGRAM

import java.util.Scanner;
public class Factorial {
public static void main(String arg[])
{
int n,fact=1;
Scanner s=new Scanner(System.in);
System.out.println("Enter a number:");
n=s.nextInt();
for(int i=1;i<=n;i++)
{
fact=fact*i;
}
System.out.println("Factorial of the given number "+n +" is " +fact);
}
}

OUTPUT

24

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

OPERATING
WEB BASED
APPLICATION

25

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

CASE STUDY
ONLINE BILL CALCULATOR
BOOK RAIL TICKET
How to book train ticket online; step by step guide
Step 1: Visit the IRCTC e-ticketing website: www.irctc.co.in.
Step 2: Login to the IRCTC website by using user id, password
Step 3: You can either login with OTP facility or by entering the captcha code.
If opting the OTP facility, enter the One Time Password (OTP) sent on the
registered mobile number to log in

Step 4: Fill the railway stations between which you wish to travel, ‘source
station’ and ‘destination station’ on the ‘Book Your Ticket’ on the homepage of
the IRCTC website.

Step 5: Enter the date of journey and class of travel.

26

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

Step 6: The list of trains available on the selected route will be shown.

Step 7: Enter passenger details such as name, age, gender, food choice, seat
preference, mobile number, preferred coach id (if any). Enter the details of the
child, if travelling with senior citizen / children below 5 years of age.

27

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

Step 8: Click on ‘Continue Booking’ again on the review booking page. You may
also book a return ticket.

Step 9: Select the payment method from the options available such as credit
card, debit card, net banking, mobile wallet and pay the required amount on
payment window.

28

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

Step 10: Electronic Reservation Slip E- Ticket is generated. Passengers must


carry a copy of this E-Ticket while boarding the Train.
“Avoid printing the paper and save trees and our environment”.

29

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

My Project
Train Fare Calculator

30

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

Folder Structure

31

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

HelloApplication.java

package com.example.trainfarecalculator;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

public class HelloApplication extends Application {

@Override
public void start(Stage stage) throws IOException {
Parent root =
FXMLLoader.load(getClass().getResource("hello-
view.fxml"));
stage.setScene(new Scene(root, 776, 520));
stage.setTitle("Train Fare Calculator");
stage.setResizable(false);
stage.show();
}

public static void main(String[] args) {


launch(args);
}
}
32

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

HelloController.java
package com.example.trainfarecalculator;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;

import java.net.URL;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

public class HelloController implements Initializable {


@FXML
private ChoiceBox<String> trainNamesChoiceBox;

@FXML
private ChoiceBox<String> fromTrainChoiceBox;

@FXML
private ChoiceBox<String> toTrainChoiceBox;

@FXML

33

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

private DatePicker datePicker;

@FXML
private ChoiceBox<String> quotaChoiceBox;

@FXML
private ChoiceBox<String> classChoiceBox;

@FXML
private ChoiceBox<String> adultCountComboBox;

@FXML
private ChoiceBox<String> childCountComboBox;

@FXML
private ChoiceBox<String>
seniorFemaleCountComboBox;

@FXML
private ChoiceBox<String>
seniorMaleCountComboBox;

@FXML
private TextArea outputTextArea;

@FXML
private TextField baseFareTextField;

@FXML

34

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

private TextField tatkalChargeTextField;

@FXML
private TextField reservationChargeTextField;

@FXML
private TextField superfastChargeTextField;

@FXML
private TextField cateringChargeTextField;

@FXML
private TextField dynamicFareTextField;

@FXML
private TextField pgChargePercentTextField;

@FXML
private TextField pgChargeTicketTextField;

@FXML
private TextField agentChargeTicketTextField;

@FXML
private TextField agentChargePersonTextField;

@FXML
private TextField insuranceTextField;

35

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

private List<String> trainNames = new


ArrayList<String>();

private String[] counts =


{"0","1","2","3","4","5","6"};

private Dictionary<String, List<String>> dict = new


Hashtable<String, List<String>>();

private Dictionary<String, List<String>> dataset = new


Hashtable<String, List<String>>();

private List<String> trainRoutes;

String trainName, intialDestination,


finalDestination, ticketClass;
int adultCount =0, childCount = 0,
seniorMaleCount = 0, seniorFemaleCount =0;
boolean quotaData = false;

public void setOutputText(){


int distance =
(Integer.parseInt(finalDestination.split(";")[3])-
Integer.parseInt(intialDestination.split(";")[3]));
String output= trainName+"\n" + "-".repeat(60)+"\n";
output+="From: "+intialDestination.split(";")
[2]+"\n";
output+="Departure:
"+intialDestination.split(";")[1]+"\n";
36

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

output+="Date: "+datePicker.getValue()+"\n"+
"-".repeat(60)+"\n";
output+="To: "+finalDestination.split(";")[2]+"\
n";
output+="Arrival: "+finalDestination.split(";")
[0]+"\n"+ "-".repeat(60)+"\n";
output+="Distance: "+distance+" km\n";
output+="Travel: "+ LocalTime.MIN.plus(

Duration.ofMinutes(Integer.parseInt(finalDestination.split(";
")[4])-Integer.parseInt(intialDestination.split(";")[4]))
).toString()+" hours\n"+ "-".repeat(60)+"\n";
output+="Adult: "+adultCount+"\n";
output+="Child: "+childCount+"\n";
output+="Senior Male: "+seniorMaleCount+"\n";
output+="Senior Female:
"+seniorFemaleCount+"\n"+ "-".repeat(60)+"\n";

float totalFare = distance*0.5f;

if(ticketClass.equals("First AC"))
totalFare*=4;
else if(ticketClass.equals("Second AC"))
totalFare*=3;
else if(ticketClass.equals("Third AC"))
totalFare*=2;
if (quotaData)
totalFare+=
Float.parseFloat(tatkalChargeTextField.getText())*(adult
37

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

Count+seniorMaleCount+seniorFemaleCount);
totalFare +=
Float.parseFloat(baseFareTextField.getText())+
Float.parseFloat(reservationChargeTextField.getText())+
Float.parseFloat(superfastChargeTextField.getText())+
Float.parseFloat(cateringChargeTextField.getText());
totalFare +=
totalFare*Float.parseFloat(pgChargePercentTextField.getT
ext())/100.f;
totalFare+=
Float.parseFloat(pgChargeTicketTextField.getText()) +
Float.parseFloat(agentChargePersonTextField.getText())
+Float.parseFloat(agentChargeTicketTextField.getText())
+Float.parseFloat(insuranceTextField.getText());
totalFare = (totalFare*adultCount)+
(totalFare*childCount)+(totalFare*seniorMaleCount)+
(totalFare*seniorFemaleCount);
totalFare+=
Float.parseFloat(dynamicFareTextField.getText())*(adultC
ount+seniorMaleCount+seniorFemaleCount);
totalFare +=46;
if
((childCount+seniorMaleCount+seniorFemaleCount+
adultCount) == 0)
totalFare=0;
output+=ticketClass+" Fare: "+totalFare;
outputTextArea.setText(output);
}

38

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

@Override
public void initialize(URL url, ResourceBundle
resourceBundle) {

dataset.put("HWH Duronto Express", new


ArrayList<String> () {{
add("0;12:40PM;New Delhi Station;0;0");
add("05:35PM;05:40PM;Kanpur
Central;440;295");
add("10:02PM;10:12PM;Deen Dayal Upadhyay
Station;787;562");
add("12:55AM;01:05AM;Patna
Junction;999;735");
add("05:02AM;05:04AM;Jasidih
Junction;1220;982");
add("07:35AM;07:40AM;Asamsol
Junction;1330;1135");
add("10:35AM;0;Hawda Junction;1529;1315");
}});
dataset.put("VRL INDB Mahmana", new
ArrayList<String> () {{
add("0;10:20PM;Veraval;0;0");
add("11:26PM;11:28PM;Junagadh
Junction;82;66");
add("02:05AM;02:10AM;Rajkot
Junction;185;225");
add("02:59AM;02:10AM;Wankaner
Junction;227;279");
add("04:08AM;04:10AM;Surendra
39

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

Nagar;301;348");
add("06:30AM;06:45AM;Ahmedabad
Junction;432;490");
add("10:08AM;10:10AM;Godhra
Junction;574;708");
add("12:40PM;12:45PM;Ratlam
Junction;761;860");
add("01:50PM;01:55PM;Ujjain
Junction;858;930");
add("03:31PM;03:33PM;Devas;898;1031");
add("05:05PM;0;Indore;937;1125");
}});

for (Enumeration en = dataset.keys();


en.hasMoreElements();) {
trainNames.add((String) en.nextElement());
}
trainName = trainNames.get(0);
trainRoutes = new
ArrayList<>(dataset.get(trainName));
intialDestination = trainRoutes.get(0);
finalDestination =
trainRoutes.get(trainRoutes.size()-1);

List<String> getSelectedTrainRoutes = new ArrayList<>();


for(int i=0; i< trainRoutes.size()-1; i++)
{
getSelectedTrainRoutes.add(trainRoutes.get(i).split(";")[2]);
40

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

fromTrainChoiceBox.getItems().setAll(getSelectedTrainRoutes
);

fromTrainChoiceBox.setValue(intialDestination.split("
;")[2]);
toTrainChoiceBox.setValue(finalDestination);

List<String> toSelectedTrainRoutes = new ArrayList<>();


for (int i=1; i<trainRoutes.size(); i++)
toSelectedTrainRoutes.add(trainRoutes.get(i).split(";")
[2]);

toTrainChoiceBox.getItems().setAll(toSelectedTrainRoutes);

toTrainChoiceBox.setValue(finalDestination.split(";")
[2]);

trainNamesChoiceBox.getItems().addAll(trainNames);
trainNamesChoiceBox.setValue(trainNames.get(0));
trainNamesChoiceBox.setOnAction(this::getTrain);

datePicker.setDayCellFactory(picker -> new DateCell() {


public void updateItem(LocalDate date, boolean
empty) {
super.updateItem(date, empty);
41

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

LocalDate today = LocalDate.now();

setDisable(empty || date.compareTo(today) < 0 );


}
});

String date = new SimpleDateFormat("dd-MM-


yyyy").format(Calendar.getInstance().getTime());
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("dd-MM-yyyy");
LocalDate localDate = LocalDate.parse(date , formatter);
datePicker.setValue(localDate);
fromTrainChoiceBox.setOnAction(this::getTrainFrom);
toTrainChoiceBox.setOnAction(this::getTrainTo);

classChoiceBox.getItems().addAll("First AC",
"Second AC", "Third AC", "Sleeper");
classChoiceBox.setValue("First AC");
classChoiceBox.setOnAction(this::getTrainClass);

quotaChoiceBox.getItems().addAll("General",
"Tatkal", "Pre. Tatkal");
quotaChoiceBox.setValue("General");

adultCountComboBox.getItems().addAll(counts);
adultCountComboBox.setValue("0");

adultCountComboBox.setOnAction(this::getAdultsCount);

42

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

childCountComboBox.getItems().addAll(counts);
childCountComboBox.setValue("0");

childCountComboBox.setOnAction(this::getChildrenCount);

seniorFemaleCountComboBox.getItems().addAll(counts);
seniorFemaleCountComboBox.setValue("0");

seniorFemaleCountComboBox.setOnAction(this::getSeniorF
emalesCount);

seniorMaleCountComboBox.getItems().addAll(counts);
seniorMaleCountComboBox.setValue("0");

seniorMaleCountComboBox.setOnAction(this::getSeniorMal
esCount);

baseFareTextField.setText("0");
tatkalChargeTextField.setText("0");
reservationChargeTextField.setText("0");
superfastChargeTextField.setText("0");
cateringChargeTextField.setText("0");
dynamicFareTextField.setText("0");
pgChargePercentTextField.setText("0");
pgChargeTicketTextField.setText("0");
agentChargeTicketTextField.setText("0");
agentChargePersonTextField.setText("0");
insuranceTextField.setText("0");
43

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

datePicker.setOnAction(this::getChangedData);

baseFareTextField.setOnAction(this::getChangedData);

tatkalChargeTextField.setOnAction(this::getChangedData
);

reservationChargeTextField.setOnAction(this::getChan
gedData);

superfastChargeTextField.setOnAction(this::getChanged
Data);

cateringChargeTextField.setOnAction(this::getChangedD
ata);

dynamicFareTextField.setOnAction(this::getChangedData);

pgChargePercentTextField.setOnAction(this::getChanged
Data);

pgChargeTicketTextField.setOnAction(this::getChangedD
ata);

agentChargeTicketTextField.setOnAction(this::getChan
gedData);

agentChargePersonTextField.setOnAction(this::getChan
gedData);
44

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

insuranceTextField.setOnAction(this::getChangedData);
quotaChoiceBox.setOnAction(this::getQuotaData);
quotaData = false;
ticketClass = classChoiceBox.getValue();
setOutputText();
}

private void getQuotaData(ActionEvent event) {


if(quotaChoiceBox.getValue().equals("General"))
{
quotaData = false;
}
else {
quotaData = true;
}
setOutputText();
}

private void getChangedData(ActionEvent event) {


setOutputText();
}

private void getAdultsCount(ActionEvent event) {

adultCount=Integer.parseInt(adultCountComboBox.getValue
());
setOutputText();
}
private void getChildrenCount(ActionEvent event) {
45

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

childCount=Integer.parseInt(childCountComboBox.getValue
());
setOutputText();
}
private void getSeniorMalesCount(ActionEvent event) {

seniorMaleCount=Integer.parseInt(seniorMaleCountComb
oBox.getValue());
setOutputText();
}
private void getSeniorFemalesCount(ActionEvent event) {

seniorFemaleCount=Integer.parseInt(seniorFemaleCount
ComboBox.getValue());
setOutputText();
}

private void getTrainClass(ActionEvent event) {


ticketClass = classChoiceBox.getValue();
setOutputText();
}

private void getTrainTo(ActionEvent event) {


String station = toTrainChoiceBox.getValue();
for (int i=0; i<trainRoutes.size(); i++)
if(trainRoutes.get(i).split(";")[2].equals(station))
{
finalDestination = trainRoutes.get(i);
break;
46

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

}
setOutputText();
}

public void getTrain(ActionEvent event)


{
String train = trainNamesChoiceBox.getValue();

trainName = train;

trainRoutes = new
ArrayList<>(dataset.get(trainName));
intialDestination = trainRoutes.get(0);
finalDestination =
trainRoutes.get(trainRoutes.size()-1);

List<String> getSelectedTrainRoutes = new ArrayList<>();


for(int i=0; i< trainRoutes.size()-1; i++)
{
getSelectedTrainRoutes.add(trainRoutes.get(i).split(";")[2]);
}

fromTrainChoiceBox.getItems().setAll(getSelectedTrainRoutes
);

fromTrainChoiceBox.setValue(trainRoutes.get(0).split(";
")[2]);

toTrainChoiceBox.setValue(trainRoutes.get(trainRout
47

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

es.size()-1).split(";")[2]);
setOutputText();
}

public void getTrainFrom(ActionEvent event)


{
String station = fromTrainChoiceBox.getValue();
List<String> toSelectedTrainRoutes = new ArrayList<>();
for (int i=0; i<trainRoutes.size(); i++)
if(trainRoutes.get(i).split(";")[2].equals(station))
{
intialDestination = trainRoutes.get(i);
++i;
for (;i<trainRoutes.size(); i++)

toSelectedTrainRoutes.add(trainRoutes.get(i).split(";")[2]);
}

toTrainChoiceBox.getItems().setAll(toSelectedTrainRoutes);

toTrainChoiceBox.setValue(trainRoutes.get(trainRout
es.size()-1).split(";")[2]);
setOutputText();
}
}

48

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

hello-view.fxml
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>

<AnchorPane prefHeight="512.0"
prefWidth="779.0"
xmlns="http://javafx.com/javafx/16"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.example.trainfarecalculator
.HelloController">
<children>
<Pane maxHeight="-Infinity" maxWidth="-
Infinity" minHeight="-Infinity" minWidth="-
Infinity" prefHeight="521.0" prefWidth="779.0"
style="-fx-background-color: white;">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0"
fill="#f5f5f5" height="32.0" layoutX="3.0"
layoutY="2.0" stroke="BLACK"
strokeType="INSIDE" width="770.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0"
fill="WHITE" height="32.0" layoutX="3.0"
layoutY="33.0" stroke="BLACK"

49

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

strokeType="INSIDE" width="770.0" />


<Rectangle arcHeight="5.0" arcWidth="5.0"
fill="#f5f5f5" height="32.0" layoutX="3.0"
layoutY="64.0" stroke="BLACK"
strokeType="INSIDE" width="770.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0"
fill="WHITE" height="32.0" layoutX="3.0"
layoutY="95.0" stroke="BLACK"
strokeType="INSIDE" width="770.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0"
fill="#f5f5f5" height="32.0" layoutX="3.0"
layoutY="126.0" stroke="BLACK"
strokeType="INSIDE" width="770.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0"
fill="WHITE" height="32.0" layoutX="3.0"
layoutY="157.0" stroke="BLACK"
strokeType="INSIDE" width="770.0" />
<Text layoutX="10.0" layoutY="23.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Train" />
<ChoiceBox fx:id="trainNamesChoiceBox"
layoutX="62.0" layoutY="5.0" prefWidth="150.0"
/>
<Line endX="-65.0" endY="-250.0"
layoutX="115.0" layoutY="253.0" startX="-65.0"
startY="-65.0" />
<Text layoutX="10.0" layoutY="54.0"
strokeType="OUTSIDE" strokeWidth="0.0"

50

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

text="From" />
<Text layoutX="10.0" layoutY="85.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="To" />
<Text layoutX="10.0" layoutY="116.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Class" />
<Text layoutX="10.0" layoutY="147.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Date" />
<Text layoutX="10.0" layoutY="178.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Quota" />
<Line endX="-65.0" endY="-250.0"
layoutX="289.0" layoutY="253.0" startX="-65.0"
startY="-65.0" />
<Text layoutX="232.0" layoutY="23.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Adult" />
<Text layoutX="232.0" layoutY="54.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Child (no seat)" />
<Text layoutX="232.0" layoutY="85.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Sen. Female" />
<Text layoutX="232.0" layoutY="116.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Sen. Male" />

51

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

<Line endX="-65.0" endY="-250.0"


layoutX="380.0" layoutY="253.0" startX="-65.0"
startY="-65.0" />
<Line endX="-65.0" endY="-250.0"
layoutX="450.0" layoutY="253.0" startX="-65.0"
startY="-65.0" />
<ChoiceBox fx:id="adultCountComboBox"
layoutX="324.0" layoutY="5.0"
prefHeight="25.0" prefWidth="51.0" />
<ChoiceBox fx:id="childCountComboBox"
layoutX="324.0" layoutY="36.0"
prefHeight="25.0" prefWidth="51.0" />
<ChoiceBox
fx:id="seniorFemaleCountComboBox"
layoutX="324.0" layoutY="67.0"
prefHeight="25.0" prefWidth="51.0" />
<ChoiceBox
fx:id="seniorMaleCountComboBox"
layoutX="324.0" layoutY="98.0"
prefHeight="25.0" prefWidth="51.0" />
<ChoiceBox fx:id="fromTrainChoiceBox"
layoutX="62.0" layoutY="36.0"
prefWidth="150.0" />
<ChoiceBox fx:id="toTrainChoiceBox"
layoutX="62.0" layoutY="67.0"
prefWidth="150.0" />
<ChoiceBox fx:id="classChoiceBox"
layoutX="62.0" layoutY="98.0"

52

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

prefWidth="150.0" />
<DatePicker fx:id="datePicker"
layoutX="62.0" layoutY="130.0"
prefHeight="25.0" prefWidth="150.0" />
<ChoiceBox fx:id="quotaChoiceBox"
layoutX="62.0" layoutY="160.0"
prefWidth="150.0" />
<Text layoutX="392.0" layoutY="23.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Base Fare" />
<Text layoutX="392.0" layoutY="54.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Tatkal Charge" />
<Text layoutX="392.0" layoutY="85.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Reservation Charge" />
<Text layoutX="392.0" layoutY="115.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Superfast Charge" />
<Text layoutX="392.0" layoutY="147.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Catering Charge" />
<Text layoutX="392.0" layoutY="178.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Dynamic Fare" />
<Line endX="-65.0" endY="-250.0"
layoutX="565.0" layoutY="253.0" startX="-65.0"
startY="-65.0" />

53

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

<TextField fx:id="baseFareTextField"
layoutX="507.0" layoutY="5.0"
prefHeight="25.0" prefWidth="51.0" />
<TextField fx:id="tatkalChargeTextField"
layoutX="507.0" layoutY="36.0"
prefHeight="25.0" prefWidth="51.0" />
<TextField
fx:id="reservationChargeTextField"
layoutX="507.0" layoutY="67.0"
prefHeight="25.0" prefWidth="51.0" />
<TextField
fx:id="superfastChargeTextField"
layoutX="507.0" layoutY="98.0"
prefHeight="25.0" prefWidth="51.0" />
<TextField
fx:id="cateringChargeTextField"
layoutX="508.0" layoutY="129.0"
prefHeight="25.0" prefWidth="51.0" />
<TextField fx:id="dynamicFareTextField"
layoutX="508.0" layoutY="160.0"
prefHeight="25.0" prefWidth="51.0" />
<Line endX="-65.0" endY="-250.0"
layoutX="631.0" layoutY="253.0" startX="-65.0"
startY="-65.0" />
<Text layoutX="574.0" layoutY="23.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="PG Charge %" />
<Text layoutX="574.0" layoutY="54.0"

54

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

strokeType="OUTSIDE" strokeWidth="0.0"
text="PG Charge / Ticket" />
<Text layoutX="574.0" layoutY="85.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Agent Charge / Ticket" />
<Text layoutX="574.0" layoutY="115.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Agent Charge / Person" />
<Text layoutX="574.0" layoutY="147.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Insurance / Person" />
<Line endX="-65.0" endY="-250.0"
layoutX="767.0" layoutY="253.0" startX="-65.0"
startY="-65.0" />
<TextField
fx:id="pgChargePercentTextField"
layoutX="710.0" layoutY="5.0"
prefHeight="25.0" prefWidth="51.0" />
<TextField
fx:id="pgChargeTicketTextField"
layoutX="710.0" layoutY="36.0"
prefHeight="25.0" prefWidth="51.0" />
<TextField
fx:id="agentChargeTicketTextField"
layoutX="711.0" layoutY="67.0"
prefHeight="25.0" prefWidth="51.0" />
<TextField
fx:id="agentChargePersonTextField"

55

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

layoutX="711.0" layoutY="98.0"
prefHeight="25.0" prefWidth="51.0" />
<TextField fx:id="insuranceTextField"
layoutX="711.0" layoutY="129.0"
prefHeight="25.0" prefWidth="51.0" />
<Text layoutX="16.0" layoutY="295.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Made by">
<font>
<Font name="Consolas Bold" size="19.0"
/>
</font></Text>
<Text layoutX="112.0" layoutY="295.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Aditi Panwar">
<font>
<Font name="Arial" size="19.0" />
</font></Text>
<Text layoutX="16.0" layoutY="326.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Class">
<font>
<Font name="Consolas Bold" size="19.0"
/>
</font></Text>
<Text layoutX="112.0" layoutY="326.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="12th A">
<font>
56

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

<Font name="Arial" size="19.0" />


</font></Text>
<Text layoutX="16.0" layoutY="357.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="School">
<font>
<Font name="Consolas Bold" size="19.0"
/>
</font></Text>
<Text layoutX="112.0" layoutY="357.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Kala Niketan Sr. Sec. Bal Vidyalaya">
<font>
<Font name="Arial" size="19.0" />
</font></Text>
<Text layoutX="16.0" layoutY="391.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Roll No">
<font>
<Font name="Consolas Bold" size="19.0"
/>
</font></Text>
<Text layoutX="112.0" layoutY="314.0"
strokeType="OUTSIDE" strokeWidth="0.0" text="
">
<font>
<Font name="Arial" size="19.0" />
</font></Text>
<Text layoutX="16.0" layoutY="424.0"
57

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

strokeType="OUTSIDE" strokeWidth="0.0"
text="Project">
<font>
<Font name="Consolas Bold" size="19.0"
/>
</font></Text>
<Text layoutX="112.0" layoutY="424.0"
strokeType="OUTSIDE" strokeWidth="0.0"
text="Train Fare Caluclator">
<font>
<Font name="Arial" size="19.0" />
</font></Text>
<TextArea fx:id="outputTextArea"
layoutX="443.0" layoutY="194.0"
prefHeight="318.0" prefWidth="325.0" />
</children>
</Pane>
</children>
</AnchorPane>

58

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

59

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)


lOMoARcPSD|6916255

References:
www.programiz.com,
www.w3schools.com,
www.javatpoint.com,
www.beginnersbook.com,
Katson Publication ‘Preeti Saxena’

60

Downloaded by Ramesh Prasad Bhatta (rpb.mcs@gmail.com)

You might also like