如何为moveelevator创建方法 [英] How do I create a method for moveelevator

查看:107
本文介绍了如何为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创建方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆