#elevator

1 messages · Page 1 of 1 (latest)

celest kite
#

Hey! I am really new to coding and my professor isn’t really teaching this class (Object Orienting Programing Java Script) for people with no experience even though he said he was going to do so it’s a big frustrating. During the lectures, he’d always reference stuff he taught in past semesters in C and C++ and doesn’t go over anything too well. So now half the stuff I’m doing I don’t really understand it’s all like jibberish to me so bare with me. We are supposed to create an object in one class use some private stuff so that people don’t mess with it (?) then use another folder class thing to use the object in and make the elevator go up. I have attempted this but I have no idea what I just wrote or if I’m even on the right track any help would be greatly appreciated. Here are some pictures:

tepid templeBOT
#

This post has been reserved for your question.

Hey @celest kite! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

high pumice
#

can you explain what you're trying to do here pleas

#

theres a few syntax errors here and there but walk me through the logic rq

celest kite
#

Ah well I thought cuz I did the goUp in the other one it’ll mean that it’ll go up to the net level but if the input was wrong then it’ll display the error message then show level cuz there’s only three floors

#

So like in the second one I did goUp = + floor I thought that will make it go up

high pumice
#

ok i understand

#

but here

#

so in an if statement, java checks to see if the thing in the parentheses is true

#

but you put the boolean truth which you set to true in the parentheses, so it's always gonna run the code inside the if statement

#

also another note, the else in an if statement doesnt have a parentheses because it's going to run if the condition of the if statement is false

#

so to accomplish what you're trying to do you would need something that says if input.nextInt() is between 1 and 3, then goUp() and print "Going up!"

#

otherwise, displaycurrentFloor() and print "Can't proceed"

sinful ocean
#

OOJS is different

high pumice
#

so..

if(0<Floor<4){
 goUp();
 System.out.println("Going up!");
}
else{
 displaycurrentFloor();
 System.out.println("Can't proceed");
sinful ocean
celest kite
sinful ocean
#

But that's also a thing

#

And it's completely different

celest kite
#

Alright I’ll try and find some help somewhere else then thank you!

sinful ocean
#

This is the place lol

#

But you just got the name wrong

celest kite
#

Oh can you help me out then?

high pumice
#

yes

high pumice
#

yes it works but its less readable

#

but yea thats good

sinful ocean
high pumice
#

you cann also just declare floor in line 26 rather than line 16

sinful ocean
#

define*

#

And yeah that looks cleaner in my opinion

celest kite
sinful ocean
#

all three should be methods

#

Because go is a verb yes?

celest kite
#

I donnu what a method is 😅

sinful ocean
#

We're telling the computer to do stuff

sinful ocean
celest kite
#

But how do I do that

sinful ocean
#

How do you define the methods?

#

Very similar to main

#

Just change the name and String[] args to whatever data you pass in

#

And the void to whatever is returned. (For you example no change)

high pumice
#

you're using methods when you say goUp()

celest kite
#

What do you mean by data you pass in

high pumice
#

a method is basically a block of code with a purpose

high pumice
celest kite
#

What’s that

high pumice
#

so your setFloor method has a parameter

#

which is an int

#

and so sometimes methods take parameters as an input

#

sometimes they dont need one

celest kite
#

But what happens when they do have a parameter

high pumice
#

so basically what methods does your professor say you need to have

celest kite
#

goUp goDown displayCurrentFloor

#

I think

high pumice
#

as seen here the method addNumbers has 2 int parameters

#

and its purpose is to add numbers

#

so the 2 ints that it receives as input, it adds them, and then outputs their sum

#

makes sense?

celest kite
#

Ok that kinda makes sense

high pumice
#

if i did this i would have it take an int parameter

#

representing the floor they would like to go to

#

and then set your class variable currentFloor to the parameter

#

it doesnt really need to be goUp and goDown it can just be changeFloor

#

unless he specifically said you need one method for going up and one for going down

celest kite
#

oh well I think he wants the elevator to go one up at a time so like it can’t skip from 1 to 3 and when you try to go up on third it’s supposed to display an error message

celest kite
#

Alright this is what I got now

#

Donnu if this is closer or farther away from what I need 😅

high pumice
# celest kite

replace this with
System.out.println("Currently on floor " + Floor);

#

dont you wanna change the value of currentFloor as well

high pumice
#

i gtg i'll be back in 25 mins

celest kite
#

Alright!

#

Also made a couple changes

sinful ocean
#

You need ro step back and learn the cores of java

#

Only following school/college curriculum is not a good way to learn fast

celest kite
# sinful ocean Only following school/college curriculum is not a good way to learn fast

Dawg that’s the point of going to school wym 😭
I’m not tryna learn fast or anything this was supposed to be intro level stuff but the course material definitely doesn’t cover the very basics and the professor doesn’t help as much as he should and it’s an online class so it’s hard to make friends
Besides this is due tomorrow I’m not stepping back 😂

sinful ocean
#

I never made friends

celest kite
#

If you wanna help me I’ll very much appreciate it cuz I’ve been so lost for the past 2 weeks if not cuz you think I’m an idiot trust me I know aha

sinful ocean
#

No I also have to do things you know?

celest kite
#

Then go do them

#

Have fun!

sinful ocean
#

👍

high pumice
#

theres an order in which to learn things

#

jumping around will lead to a lot of confusion

celest kite
#

I know he’s right but I can’t really go back rn cuz that’s the structure of the course wish it was better but 🤷‍♀️. I’m just trying my best