0% found this document useful (0 votes)
2 views4 pages

Kotlin Array and Hotel Reservation App

The document contains a Kotlin program that allows users to manage an array of integers and make hotel reservations. Users can add, delete, edit, and display elements in the array, as well as make reservations for different room types and view all reservations. The program utilizes a console interface for user interaction and employs functions for each operation.

Uploaded by

tadori474
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Kotlin Array and Hotel Reservation App

The document contains a Kotlin program that allows users to manage an array of integers and make hotel reservations. Users can add, delete, edit, and display elements in the array, as well as make reservations for different room types and view all reservations. The program utilizes a console interface for user interaction and employs functions for each operation.

Uploaded by

tadori474
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import [Link].

*
import [Link]

fun main(args: Array<String>) {

val scan = Scanner(System.`in`)


val arr = ArrayList<Int>()

while(true){

println("\nPlease choose option:")


println("1. Add an array")
println("2. Delete an array")
println("3. edit an array")
println("4. Display all Elements")

print("Please choose to 1-4: ")


val choose = [Link]()

when(choose){
1 -> addArray(arr,scan)
2 -> deleteArray(arr,scan)
3 -> editArray(arr,scan)
4 -> allArray(arr)
else-> println("Invalid")
}
}
}
fun addArray(arr: ArrayList<Int>, scan: Scanner){
println("Adding an array")
print("Enter a size: ")
val arrSize = [Link]()

var num =1;

for(i in 0 until arrSize){


print("Element $num: ");
var elem = [Link]()
[Link](elem)
num++
}
print("Original Array: $arr")

print("Enter number to add: ")


val number = [Link]()
print("Enter index to add at: ")
val index = [Link]()

if (index in 0..[Link]){
[Link](index,number)
println("Number $number add at index $index.")
print("Updated Array: $arr")
}else{
println("Invalid.")
}
}
fun deleteArray(arr: ArrayList<Int>, scan: Scanner){

println("Adding an array")
print("Enter a size: ")
val arrSize = [Link]()

var num =1;

for(i in 0 until arrSize){


print("Element $num: ");
var elem = [Link]()
[Link](elem)
num++
}
print("Original Array: $arr")

print("Enter the index of the element to be removed: ")


val remove = [Link]()

[Link](arr[remove])
print("After removing the elemnt at index: $remove: $arr")

}
fun editArray(arr:ArrayList<Int> ,scan: Scanner){
if ([Link]()) {
println("List is empty. Cannot edit.")
return
}

print("Enter index to edit (0-${[Link] - 1}): ")


val index = [Link]()

if (index in 0 until [Link]) {


print("Enter new number: ")
val newNumber = [Link]()
arr[index] = newNumber
println("Edited list: $arr")
} else {
println("Invalid index. Cannot edit.")
}

}
fun allArray(arr: List<Int>){
println("Current list: $arr")
}
Hotel:

import [Link].*

class Reserve(
val GuestName: String="",
val RoomType: String,
val NumberofRooms: Int,
val Cost: Int=0

)
fun main(args: Array<String>) {
val reservation = mutableListOf<Reserve>()

val scan = Scanner(System.`in`)

while (true){
println("Welcome to Hotel Reservation")
println("Please choose an option")
println("1. Make a Reservation")
println("2. View All Reservation")
println("3 Quit")

print("Enter your choice: ")


val choice = [Link]()

when(choice){
1 ->makeReservation(reservation,scan)
2 ->viewAll(reservation)
else-> print("Invalid")
}
}
}
fun makeReservation(reservation: MutableList<Reserve>,scan:Scanner){

println("please choose a room type:")


println("1. Standard Room - $100 per night")
println("2. Deluxe Room - $150 per night")
println("2. Suit - $200 per night")

print("Room Type: ")


val choice = [Link]()

val roomtype = when(choice){


1 -> "Standard Room"
2 -> "Deluxe Room"
3 -> "Suit"
else -> {
print("Invalid")
return
}
}

print("Guest Name: ")


val guestName = [Link]()
print("number of rooms: ")
val numberof = [Link]()

val cost = when (roomtype){


"Standard Room" -> numberof * 100
"Deluxe Room" -> numberof * 150
"Suit" -> numberof * 200
else -> {
print("Invalid")
return
}
}

val listReserve = Reserve(guestName,roomtype,numberof,cost)


[Link](listReserve)

println("=======================================")

println("Guestname: $guestName")
println("RoomType: $roomtype")
println("Number of Rooms: $numberof")
println("Cost: $ $cost")

println("=======================================")

}
fun viewAll(reservation: List<Reserve>){
[Link] { index, reserve ->
println("${index + 1}, -${[Link]}, - ${[Link]}-
$ ${[Link]
}")
}
}

You might also like