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:
#elevator
1 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @celest kite! Please use
/closeor theClose Postbutton 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.
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
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
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"
Java, not JS
OOJS is different
so..
if(0<Floor<4){
goUp();
System.out.println("Going up!");
}
else{
displaycurrentFloor();
System.out.println("Can't proceed");
( Chained comparisons don't work in java like in python )
Oh I thought that’s what it was cuz that’s the course title 😭😭😭😭
Alright I’ll try and find some help somewhere else then thank you!
Oh can you help me out then?
yes
Does this work?
Are there requirements for the elevator class? It looks overengineered
you cann also just declare floor in line 26 rather than line 16
We’re supposed to tell it to go up up up up until it reaches the very top then do down. I donnu tho he basically ran through another example with the same structure and he wanted us to set this same way I think? He said we had to use goUp and goDown and displayCurrentFloor() which honestly I donnu if I’m really doing
I donnu what a method is 😅
We're telling the computer to do stuff
Function inside a class is called method
But how do I do that
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)
you're using methods when you say goUp()
What do you mean by data you pass in
a method is basically a block of code with a purpose
parameters that go in the parentheses of the metohd
What’s that
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
But what happens when they do have a parameter
so basically what methods does your professor say you need to have
you use the parameter as needed to make the method do what it needs to do
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?
Ok that kinda makes sense
ok so with your goUp method
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
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
Alright this is what I got now
Donnu if this is closer or farther away from what I need 😅
replace this with
System.out.println("Currently on floor " + Floor);
dont you wanna change the value of currentFloor as well
i gtg i'll be back in 25 mins
What does that mean
Alright!
Also made a couple changes
You need ro step back and learn the cores of java
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 😂
I never made friends
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
No I also have to do things you know?
👍
hes right
theres an order in which to learn things
jumping around will lead to a lot of confusion
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