Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 57 additions & 20 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/datastructures/traficlight/RedLight.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package datastructures.traficlight;

public final class RedLight implements TrafficLight {
@Override
public void showLight() {
System.out.println("RedLight is going on!");
}
}
65 changes: 65 additions & 0 deletions src/datastructures/zoho/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package datastructures.zoho;

public class Main {
public static void main(String[] args) {
/*
* Try to print a patten printing using words.
* Patten : (x)
* */
char[] chars = "PROGRAM".toCharArray();
int length = chars.length;
for (int i = 0; i < length; i++) {
for (int j = 0; j < length; j++) {
if (i == j) System.out.print(chars[j] + " ");
else if (i + j == length - 1) System.out.print(chars[length - 1 - i] + " ");
else System.out.print(" ");
}
System.out.println();
}

/*
String Question
Convert the string into Two dimensional matrix.
Try To Identify the target in the matrix either in rows or column.
* */
String input = "WELCOMETOZOHOCORPORATION";
String target = "oc".toUpperCase();

int rows = 5;
int cols = 5;

char[][] grid = new char[rows][cols];
int index = 0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if (index < input.length()) {
grid[i][j] = input.charAt(index);
index++;
}
}
}

for (int i = 0; i < cols; i++) {
StringBuilder sb = new StringBuilder();
for (int j = 0; j < rows; j++) {
sb.append(grid[j][i]);
}
if (sb.toString().contains(target)) {
System.out.println("Target Found!!, In Vertical Search");
}
}


for (char[] row : grid) {
String r = new String(row);
if (r.contains(target)) System.out.println("Target Found!!, In Horizontal Search");
}

for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
System.out.print(grid[i][j] + " ");
}
System.out.println();
}
}
}
131 changes: 131 additions & 0 deletions src/datastructures/zoho/railway/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package datastructures.zoho.railway;

import java.util.ArrayList;
import java.util.Scanner;

/*
*
*
* */


public class Main {
static final int TOTAL_BERTHS_TICKET = 63;
static final int TOTAL_RAC_TICKET = 18;
static final int TOTAL_WAITING_LIST_TICKET = 10;

static ArrayList<People> confirmedTicket = new ArrayList<>();
static ArrayList<People> racTicket = new ArrayList<>();
static ArrayList<People> waitingListTicket = new ArrayList<>();

public static void main(String[] args) {
System.out.println("RAILWAY RESERVATION SYSTEM");
Scanner scanner = new Scanner(System.in);

while (true) {
System.out.println("""
1. Booking
2. Cancel
3. Print Booked Tickets
4. Print Available Ticket
5. Exit""");

System.out.print("Enter Your Choice : ");
int ch = scanner.nextInt();
scanner.nextLine();

switch (ch) {
case 1 -> bookTicket(scanner);
case 2 -> cancelTicket(scanner);
case 3 -> printBookedTicket(confirmedTicket);
case 4 -> printAvailableTicket();
case 5 -> {
System.out.println("Program Exited");
scanner.close();
System.exit(0);
}
default -> System.out.println("INVALID INPUT");
}
}
}

private static void printBookedTicket(ArrayList<People> passenger) {
Service.printTickets(passenger, "BOOKED TICKETS");
}

private static void printAvailableTicket() {
System.out.print("Available Tickets");
System.out.printf("Confirmed Ticket : %d%nRAC Ticket : %d%nWaiting List Ticket : %d%n",
TOTAL_BERTHS_TICKET - confirmedTicket.size(),
TOTAL_RAC_TICKET - racTicket.size(),
TOTAL_WAITING_LIST_TICKET - waitingListTicket.size());
}

private static void bookTicket(Scanner scanner) {
if (waitingListTicket.size() > TOTAL_WAITING_LIST_TICKET) {
System.out.print("NO TICKETS AVAILABLE");
return;
}

System.out.print("Enter passenger name: ");
String name = scanner.nextLine();

System.out.print("Enter passenger age: ");
int age = scanner.nextInt();
scanner.nextLine();

System.out.print("Enter passenger gender (M/F): ");
char gender = scanner.nextLine().charAt(0);

System.out.print("Enter berth preference (U/L/S): ");
char berthPreference = scanner.nextLine().charAt(0);

People person = new People(name, age, gender, berthPreference);

if (person.getAge() < 5) {
System.out.println("There Is No Ticket for Child");
waitingListTicket.add(person);
} else if (person.getAge() >= 60 || person.getGender() == 'F' && person.getAge() > 5) {
allocateBerth(confirmedTicket, person);
} else {
allocateBerth(racTicket, person);
}
}

private static void allocateBerth(ArrayList<People> ticket, People passenger) {
if (ticket.size() < TOTAL_BERTHS_TICKET) {
confirmedTicket.add(passenger);
System.out.println("Ticket Booked Successful");
} else {
if (racTicket.size() < TOTAL_RAC_TICKET) {
racTicket.add(passenger);
System.out.println("The ticket was booked under RAC");
} else if (waitingListTicket.size() < TOTAL_WAITING_LIST_TICKET) {
waitingListTicket.add(passenger);
System.out.println("The ticket was booked under Waiting List");
} else {
System.out.println("No Ticket Available");
}
}
}

private static void cancelTicket(Scanner scanner) {
System.out.print("Enter your passengerName to cancel the ticket : ");
String passengerName = scanner.nextLine();

boolean removed = false;

for (int i = 0; i < confirmedTicket.size(); i++) {
if (confirmedTicket.get(i).getName().equalsIgnoreCase(passengerName)) {
confirmedTicket.remove(i);
removed = true;
System.out.printf("The Ticket for %s has been canceled%n", passengerName);
break;
}
}

if (!removed) {
System.out.printf("The Ticket for %s was not found in booked ticket%n", passengerName);
}
}
}
31 changes: 31 additions & 0 deletions src/datastructures/zoho/railway/People.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package datastructures.zoho.railway;

public class People {
private String name;
private int age;
private char gender;
private char berthPreference;

public People(String name, int age, char gender, char berthPreference) {
this.name = name;
this.age = age;
this.gender = gender;
this.berthPreference = berthPreference;
}

public int getAge() {
return age;
}

public String getName() {
return name;
}

public char getGender() {
return gender;
}

public char getBerthPreference() {
return berthPreference;
}
}
Loading