00:01
Okay, let's write a function that will allow us to get the number of hotel rooms that are occupied and over all the floors that exist based on a user input and return a couple of things like the number of occupied rooms the number of vacant rooms the total rooms and the occupancy rate so this is going to depend on user input we first want to import java util scanner.
00:25
I'll be using the scanner tool to grab input from the user for every number that i we want.
00:33
So let's go ahead and write our main function, so public, static, void, main, strain, args.
00:44
And the first thing we're going to do is initialize some variables.
00:47
So things we need to know.
00:49
In this case, we need to know a total number of rooms.
00:52
So number of rooms, we need to know the number of occupied rooms.
00:58
We need a number of vacant rooms and number of, or in this case, occupancy rate.
01:06
Also the number of floors.
01:10
So in this case, the vacant rooms, we can calculate this easily from just subtracting the occupied rooms minus, or the, subtracting the occupied room number from the total room number.
01:25
Okay, let's go ahead and initialize these variables, so we know that the number of floors is going to be an integer, also the number of occupied rooms is going to be an integer, the number of total rooms is going to be an integer, and and in this case, also the number of vacant rooms is going to be an integer.
01:45
And then finally, we're going to have the occupancy rate.
01:48
Since we want to use division to get a fraction, we're going to want this to be a double.
01:52
So occupancy rate is a double, unlike the other four.
01:57
Okay, so the first thing we want to do is create this scanner object that we want to be able to use to take input from the user.
02:05
So let's do that by doing scanner, scanner, equal to a new scanner.
02:10
And since we want this to be input, we're going to put it as the argument system.
02:14
Not in.
02:16
This is going to read the inputs from the user.
02:19
And we can go ahead and manipulate this to use different methods to grab types, typing from the user.
02:26
And so the first thing i want to do is prompt for the number of floors.
02:30
So in this case, you can print out, enter the number of floors, and now we can just get number of floors as equal to scanner.
02:45
Next int.
02:48
This is an integer.
02:49
And now we have the number of floors in this hotel.
02:53
And so now when we're given the number of floors, we can just do some loops.
02:56
So let's do a four loop...