# 3.3 Fare Calculator Part 2

Video Activity

Join over 3 million cybersecurity professionals advancing their career

Sign up with

Required fields are marked with an *

or

Already have an account? Sign In »

Video Transcription

00:00

hi and welcome back to the course. Now, if you noticed in the last video lecture or lab, I should say we went over creating the first part of our fair calculator where we defined a certain set of variables, one of them being the age and another one being tax and in standard price, total price and total tax.

00:19

Then we sent we set the total price to zero and the tax rate

00:24

to 13% or 0.13 in decimal numbers. We also made use of the scanner class and which allowed us to accept user input from the user, which in this case is an age. So an inter juror number

00:42

and know what we're gonna do is actually implement our

00:47

concept that we learned in the last video lecture the video Lecter before that which was related to and based on if statements.

00:56

So let's say I have a user whose age is less than or equal to 10 and I want to set a standard price that I will charge them to $5.

01:07

And then I'd also like to add tax on top of that and then include that in my total price. How would I be doing that?

01:15

So, first off,

01:15

you would

01:17

make use of that if word. So you were typing. If and then since we have an age of arable, which is what we're storing from the user input,

01:26

I would put it if age is less than or equal to. And this year is the lesson or equal to

01:33

sign your operator

01:36

less than a miracle to 10. Then I would like to set the standard price too.

01:42

Uh, $5.

01:45

Perfect.

01:47

And now, I would like to calculate the total tax

01:52

in order for me to calculate the total attacks.

01:55

Think about what it is that you need to do.

02:00

So if you're thinking along the lines of multiplying the tax with the standard price, that is exactly correct. And that is what you need to do. So I would do tax times

02:10

Standard price.

02:15

Perfect. No.

02:15

What

02:16

is it that that I would have to do or go through in order to calculate my total price?

02:23

Now, this may seem pretty trivial, but what we need to go through is we tow ad,

02:29

um, the standard price and the total tax, which will essentially give us our total price,

02:35

so we would be doing standard. Apply a price on and plus total tax.

02:40

Perfect.

02:43

Now, this is just one condition for someone whose age is less than or equal to 10. But let's say we wanted to have another condition where we are checking if the user's age is greater than 10 or it is less than or equal to 18.

03:00

And if that happens to be the case, then I would like to set the standard price to $10

03:07

and then essentially, have these two lines repeat, since they complete the job of calculating the total tax in the total price.

03:16

So let's go ahead and add that into our program so I would be doing else if

03:23

age is creator than 10

03:25

or

03:28

age

03:29

is less than or equal to 18.

03:31

It's a simple as that you

03:35

take your age and you check if it's greater than 10 or if it's a lesson or equal to

03:40

of 18.

03:42

And this over here is a symbol of or if you are not familiar with it. And we discussed that this is a center for symbol for less than or equal to.

03:52

Now what is it that I would like to do if this happens to be the case. So, as I mentioned previously, I would like to set the standard price to $10.

04:03

And then these two lines over here would repeat.

04:06

So I'm saying Go ahead and copy them control, see?

04:10

And then control Beat to face them.

04:13

Now, after doing all these calculations, there is no use of them unless we actually print something to the consul.

04:19

So I'd like to tell the user that this is their total price to the fair. So in order to do that,

04:28

I would say something like the total

04:31

cost of,

04:33

of course,

04:34

for entry to the

04:39

festival

04:41

is

04:42

and then total costs or a total price.

04:46

Perfect. Now what that would do is print out the result of our calculations. No, it's actually go ahead and run our program.

04:58

And what this will do once we click run is it'll compiler program. Build it and then

05:03

we will be asked for an age. So let's go ahead and start with 10.

05:09

Right? So no, it's telling us the total cost for entry to the festival is $5.65 to confirm that we can do it manually.

05:16

So let's just go ahead and follow the formula or the calculations we set up here. So the ticket is $5. For a standard price,

05:26

multiply that by 0.13

05:29

which gives you 0.65

05:31

and then add $5 on to that

05:36

perfect. That gives you $5.65. And that is exactly what we got as an output here.

05:43

Now let's say the age of the user is 18.

05:46

Then let's type in 18.

05:49

So now it is saying the total cost for the entry to the festival is $11.30

05:57

so I would go back to my calculator and then

06:01

I'm set. First, start with the standard price, which is $10 for someone whose age is greater than 10 or less than or equal to 18

06:09

and then essentially multiply so not add. But multiply that by 0.13

06:16

and then add 10 to that, which gives me 11.3, which is exactly the number that we calculated over here.

06:25

Perfect. So that's essentially the fair calculator that we wanted to build too sweet and simple program for you to grasp the concept of

06:32

if and else if statements now going back to our,

06:40

uh, slides.

06:43

We covered in this video a summary implementing if statements by creating a fair calculator program and in the next video that's coming up next, we will be going over four loops.

06:57

Now, as always, if you have any questions at all, feel free to reach out to me of your Lincoln, and I would be more than happy to end answer any of your questions, and I look forward to seeing you in the next of the electorate. Thank you very much for watching.

Up Next

Similar Content