Professional Documents
Culture Documents
import java.util.*;
//class Address
class Address{
String city,state,country;
int zip;
//default constructor
public Address(){
//parameterized Contstructor
this.city=city;
this.state=state;
this.zip=zip;
this.country=country;
this.city=city;
return city;
this.state=state;
return state;
}
public void setZip(int zip){
this.zip=zip;
return zip;
this.country=country;
return country;
//override toString()
", state="+state+
", zip="+zip+
", country="+country+
"]";
//class Customer
class Customer{
int userId;
String emailId,password,firstName,lastName,city,gender;
long phoneNumber;
Address address;
//default constructor
public Customer(){
}
//parametrized constructor
this.userId=userId;
this.emailId=emailId;
this.password=password;
this.firstName=firstName;
this.lastName=lastName;
this.city=city;
this.gender=gender;
this.phoneNumber=phoneNumber;
this.address=address;
this.userId=userId;
return userId;
this.emailId=emailId;
return emailId;
this.password=password;
}
public String getPassword(){
return password;
this.firstName=firstName;
return firstName;
this.lastName=lastName;
return lastName;
this.city=city;
return city;
this.gender=gender;
return gender;
this.phoneNumber=phoneNumber;
}
public long getPhoneNumber(){
return phoneNumber;
this.address=address;
return address;
//override toString()
String add=address.toString();
", emailId="+emailId+
", password="+password+
", firstName="+firstName+
", lastName="+lastName+
", city="+city+
", gender="+gender+
", phoneNumber="+phoneNumber+
", address="+add+
"]";
//class Source
class Source{
int userId=sc.nextInt();
String emailId=sc.next();
String password=sc.next();
String firstName=sc.next();
String lastName=sc.next();
String city=sc.next();
String gender=sc.next();
long phoneNumber=sc.nextLong();
String state=sc.next();
int zip=sc.nextInt();
String country=sc.next();
//create object
Customer customer=new
Customer(userId,emailId,password,firstName,lastName,city,gender,phoneNumber,address);
System.out.println(customer);
}
//JBS-S4-L1-2 Admin and ServiceDetails Classes
import java.util.*;
import java.time.LocalDateTime;
//class Admin
class Admin{
int adminId;
String email;
String firstName;
String password;
//default constructor
public Admin(){
//parametrized constructor
this.adminId=adminId;
this.email=email;
this.firstName=firstName;
this.password=password;
this.adminId=adminId;
return adminId;
this.email=email;
}
return email;
this.firstName=firstName;
return firstName;
this.password=password;
return password;
//override toString()
", emailId="+email+
", firstName="+firstName+
", password="+password+
"]";
//class ServiceDetails
class ServiceDetails{
int serviceId;
int busId;
LocalDateTime deptDateTime;
LocalDateTime arrDateTime;
String arrivalCity;
String deptCity;
double cost;
int seatsLeft;
int totalSeats ;
//default constructor
public ServiceDetails(){
//parametrized constructor
this.serviceId=serviceId;
this.busId=busId;
this.deptDateTime=deptDateTime;
this.arrDateTime=arrDateTime;
this.arrivalCity=arrivalCity;
this.deptCity=deptCity;
this.cost=cost;
this.seatsLeft=seatsLeft;
this.totalSeats=totalSeats;
this.serviceId=serviceId;
this.busId=busId;
return busId;
this.deptDateTime=deptDateTime;
return deptDateTime;
this.arrDateTime=arrDateTime;
return arrDateTime;
this.arrivalCity=arrivalCity;
return arrivalCity;
this.deptCity=deptCity;
this.cost=cost;
return cost;
this.seatsLeft=seatsLeft;
return seatsLeft;
this.totalSeats=totalSeats;
return totalSeats;
//override toString()
", busId="+busId+
", depDateTime="+deptDateTime+
", arrDateTime="+arrDateTime+
", arrCity="+arrivalCity+
", deptCity="+deptCity+
", cost="+cost+
", seatsLeft="+seatsLeft+
", totalSeats="+totalSeats+
"]";
//class Sourse
class Source{
//admin variables
int adminId=sc.nextInt();
String email=sc.next();
String firstName=sc.next();
String password=sc.next();
//sericeDetails variables
int serviceId=sc.nextInt();
int busId=sc.nextInt();
int dyear=sc.nextInt();
int dmonth=sc.nextInt();
int dday=sc.nextInt();
int dh=sc.nextInt();
int dm=sc.nextInt();
LocalDateTime deptDateTime=LocalDateTime.of(dyear,dmonth,dday,dh,dm);
int ayear=sc.nextInt();
int amonth=sc.nextInt();
int aday=sc.nextInt();
int ah=sc.nextInt();
int am=sc.nextInt();
LocalDateTime arrDateTime=LocalDateTime.of(ayear,amonth,aday,ah,am);
String arrivalCity=sc.next();
String deptCity=sc.next();
double cost=sc.nextDouble();
int seatsLeft=sc.nextInt();
int totalSeats=sc.nextInt();
//object
arrivalCity,deptCity,cost,seatsLeft,totalSeats);
//print servicedetails
System.out.println(SD);
}
JBS-S4-L2-1-Customer Name Validator
import java.util.*;
import javax.naming.InvalidNameException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
//class Customer
class Customer{
String firstName;
String lastName;
Customer(){
if(firstName.length()<6 || lastName.length()<6){
else{
this.firstName=firstName;
this.lastName=lastName;
Pattern pattern=Pattern.compile("[^a-zA-Z]");
Matcher matcher1=pattern.matcher(firstName);
Matcher matcher2=pattern.matcher(lastName);
boolean isStringContainsSpecialCharacter1=matcher1.find();
boolean isStringContainsSpecialCharacter2=matcher2.find();
if(isStringContainsSpecialCharacter2 || isStringContainsSpecialCharacter2)
else{
this.firstName=firstName;
this.lastName=lastName;
if(firstName.length()<6){
else{
this.firstName=firstName;
Pattern pattern=Pattern.compile("[^a-zA-Z]");
Matcher matcher=pattern.matcher(firstName);
boolean isStringContainsSpecialCharacter=matcher.find();
if(isStringContainsSpecialCharacter)
else{
this.firstName=firstName;
return firstName;
if(lastName.length()<6){
else{
this.lastName=lastName;
Pattern pattern=Pattern.compile("[^a-zA-Z]");
Matcher matcher=pattern.matcher(lastName);
boolean isStringContainsSpecialCharacter=matcher.find();
if(isStringContainsSpecialCharacter)
else{
this.lastName=lastName;
return lastName;
//class Source
class Source{
String firstName=sc.next();
String lastName=sc.next();
System.out.println(C.getFirstName());
System.out.println(C.getLastName());
}
JBS-S4-L2-2-Customer Mobile Number
-Exception
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
InvalidPhoneNumberExcception(){
super();
class Customer{
long phoneNumber;
Customer(){
Pattern pattern=Pattern.compile("^[6-9][0-9]{9}$");
Matcher matcher=pattern.matcher(Long.toString(phoneNumber));
if(matcher.matches()){
this.phoneNumber=phoneNumber;
else{
try{
catch(InvalidPhoneNumberExcception e){
}
}
Pattern pattern=Pattern.compile("^[6-9][0-9]{9}$");
Matcher matcher=pattern.matcher(Long.toString(phoneNumber));
if(matcher.matches()){
this.phoneNumber=phoneNumber;
else{
try{
catch(InvalidPhoneNumberExcception e){
return phoneNumber;
class Source{
long phoneNumber=sc.nextLong();
System.out.println(C.getPhoneNumber());
}
public CustomerNotFoundException() {
class Address {
String city;
String State;
int zip;
String Country;
super();
this.city = city;
State = state;
this.zip = zip;
Country = country;
return city;
this.city = city;
this.State = state;
return zip;
this.zip = zip;
return Country;
this.Country = country;
@Override
return "Address [city=" + city + ", state=" + State + ", zip=" + zip + ", country=" + Country + "]";
class Customer {
int userId;
String emailId;
String password;
String firstName;
String lastName;
String city;
String gender;
long phoneNumber;
Address address;
public Customer(){
public Customer(int userId, String emailId, String password, String firstName, String lastName, String city,
this.userId = userId;
this.emailId = emailId;
this.password = password;
this.firstName = firstName;
this.lastName = lastName;
this.city = city;
this.gender = gender;
this.phoneNumber = phoneNumber;
this.address = address;
@Override
return "Customer [userId=" + userId + ", emailId=" + emailId + ", password=" + password + ", firstName="
+ firstName + ", lastName=" + lastName + ", city=" + city + ", gender=" + gender + ", phoneNumber="
return userId;
this.userId = userId;
}
public String getEmailId() {
return emailId;
this.emailId = emailId;
return password;
this.password = password;
return firstName;
this.firstName = firstName;
return lastName;
this.lastName = lastName;
return city;
this.city = city;
}
public String getGender() {
return gender;
this.gender = gender;
return phoneNumber;
this.phoneNumber = phoneNumber;
return address;
this.address = address;
interface CustomerService{
Customer[] getCustomers();
customerArray[count]=customer;
count++;
@Override
for(int i=0;i<5;i++)
if(customer.getUserId()==customerArray[i].userId)
customerArray[i]=customer;
return customerArray[i];
@Override
for(int i=0;i<5;i++)
if(customerArray[i].getUserId()==id) {
customerArray[i]=null;
break;
@Override
for(int i=0;i<5;i++)
if(customerArray[i].getUserId()==id) {
return customerArray[i];
@Override
return customerArray;
}
3-2 ADMIN SERVICE INTERFACE
import java.time.LocalDateTime;
import java.util.ArrayList;
class ServiceDetails{
public ServiceDetails(){
public ServiceDetails(int serviceId, int busId, LocalDateTime deptDateTime, LocalDateTime arrDateTime, String
arrivalCity, String deptCity, double cost, int seatsLeft, int totalSeats) {
this.serviceId = serviceId;
this.busId = busId;
this.deptDateTime = deptDateTime;
this.arrDateTime = arrDateTime;
this.arrivalCity = arrivalCity;
this.deptCity = deptCity;
this.cost = cost;
this.seatsLeft = seatsLeft;
this.totalSeats = totalSeats;
}
return serviceId;
this.serviceId = serviceId;
return busId;
this.busId = busId;
return deptDateTime;
this.deptDateTime = deptDateTime;
return arrDateTime;
}
public void setArrDateTime(LocalDateTime arrDateTime) {
this.arrDateTime = arrDateTime;
return arrivalCity;
this.arrivalCity = arrivalCity;
return deptCity;
this.deptCity = deptCity;
return cost;
this.cost = cost;
return seatsLeft;
}
this.seatsLeft = seatsLeft;
return totalSeats;
this.totalSeats = totalSeats;
@Override
return deptCity.equals(that.deptCity);
}
interface AdminService{
Object[] getServiceDetails();
static {
@Override
serviceDetailsArrayList.add(serviceDetails);
@Override
if(serviceDetail.equals(serviceDetails)){
serviceDetailsArrayList.set(serviceDetailsArrayList.indexOf(serviceDetail),serviceDetails);
serviceDetails1 = serviceDetail;
return serviceDetails1;
@Override
if(serviceDetails.getServiceId() == id){
serviceDetail = serviceDetails;
serviceDetailsArrayList.remove(serviceDetails);
break;
@Override
if(serviceDetails.getServiceId() == id){
serviceDetail = serviceDetails;
return serviceDetail;
@Override
ServiceDetailsNotFoundException(){
}
3-3 BOOKING DETAILS SERVICE
class BookingDetails{
BookingDetails(){
this.bookingId = bookingId;
this.customerId = customerId;
this.userId = userId;
this.status = status;
return bookingId;
this.bookingId = bookingId;
return customerId;
}
public void setCustomerId(int customerId){
this.customerId = customerId;
return userId;
this.userId = userId;
return status;
this.status = status;
interface BookingDetailsService{
BookingDetails[] getBookingDetails();
}
class BookingDetailsServiceImpl implements BookingDetailsService{
bookingDetailsArray[i] =bookingDetails;
break;
int i = 0 ;
int j = bookingDetailsArray.length;
if( bookingDetailsArray[i].getBookingId() ==
bookingDetails.getBookingId() ){
bookingDetailsArray[i] = bookingDetails;
return bookingDetails;
return null;
int i = 0 ;
int j = bookingDetailsArray.length;
bookingDetailsArray[i] = null;
break;
return bookingDetailsArray;
int i = 0 ;
int j = bookingDetailsArray.length;
int k = 0;
customerBookingDetails[k++] = bookingDetailsArray[i];
if( k == 2 ){
return customerBookingDetails;
}
return customerBookingDetails;
int i = 0 ;
int j = bookingDetailsArray.length;
int k = 0;
customerBookingDetails[k++] = bookingDetailsArray[i];
if( k == 2 ){
return customerBookingDetails;
return customerBookingDetails;
int i = 0 ;
int j = bookingDetailsArray.length;
int k = 0;
if( k == 2 ){
return customerBookingDetails;
return customerBookingDetails;
interface UserService{
new BookingDetailsServiceImpl().addBookingDetails(bookingDetails);