如何为moveelevator创建方法

编程入门 行业动态 更新时间:2024-10-27 14:18:29
本文介绍了如何为moveelevator创建方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我为Elevator类设计了一个代码,我必须创建一个移动Elevator方法,我的教授希望我通过参考他为我们提供的流程图来创建。我希望我可以上传流程图让我的问题更容易回答,但我无法道歉。该方法必须向上,向下移动电梯,并在其移动时宣告每个楼层的通过。此外,他希望我尝试制造一个错误,并将电梯移到太高的地板上,如果有意义的话。 如果有人可以请求帮助,那就是很棒,我一直在努力,不仅仅是这个课程,而是一般的这门课程,我正处于失败的边缘,不是咆哮或任何事情,但我只是有点不知所措,可以使用额外的帮助。 我尝试了什么: 这就是我所拥有的远;我还为loadElevator和unloadElevator添加了我的方法,以便对我想要做的事情有所了解:

I've designed a code for an Elevator class and I have to create a move Elevator method and my professor wants me to create by referring to a flowchart he's provided for us. I wish I could upload the flowchart to make my question a little easier to answer, but I'm unable to and I apologize. The method must move the elevator up, down, and announce each floor its passing as it moves. Also, he wants me to try to create an error and move the elevator on a floor that's too high if that makes sense. If someone could please help, that would be great, I've struggled so much with not just this program but with this course in general and I'm on the verge of failing, not to rant or anything, but I'm just a little overwhelmed and could use the extra help. What I have tried: Here's what I have so far; and I also added my methods for loadElevator and unloadElevator to give some insight on exactly what Im trying to do:

public void loadElevator (int passengersToLoad) { System.out.println("loading elevator " + passengersToLoad); int numToLoad; int spaceAvailable; spaceAvailable = maxCapacity - numOnBoard; if (spaceAvailable < passengersToLoad) numToLoad = spaceAvailable; else { numToLoad = passengersToLoad; } numOnBoard = numOnBoard + numToLoad; } public void unloadElevator (int passengerstoUnload) { System.out.println("unloading elevator" + passengerstoUnload); int numToUnload = 0; numToUnload = numOnBoard; { numToUnload = passengerstoUnload; } numOnBoard -= numToUnload; } public void moveElevator (int requestedFloor) { System.out.println("moving elevator" + requestedFloor); int destFloor; if (destFloor > currentFloor)

推荐答案

以非编程术语来思考您的问题。电梯做什么,它是如何做的? 启动电梯需要按钮来确定要停在哪个楼层。这些是简单的开/关按钮(开启停止,关闭旁路)。它需要在移动之前关闭门,因此您需要一个标志指示门的状态。它需要一个标志来指示行进方向(响应按下的按钮)。它需要在楼层之间移动(向上或向下)并停在按钮点亮的楼层。 Think about your problem in non-programming terms. What does an elevator do, and how does it do it? To start the elevator needs buttons to identify which floor(s) to stop on. These are simple on/off buttons (on for stop, off for bypass). It needs to close the doors before moving, so you need a flag that indicates the state of the doors. It needs a flag to indicate the direction of travel (in response to whichever buttons are pressed). It needs to move between floors (up or down) and stop at the ones whose buttons are lit.

更多推荐

如何为moveelevator创建方法

本文发布于:2023-11-04 00:34:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556474.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:何为   方法   moveelevator

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!