Now you've written a lot of code and mercifully the application is nearly done.
I'll give you the final piece. Here in the CarShareApp class, you make a
simulation object, we ask it to read it's input. Then we load the passengers,
and drive the cars. Also, so that you see what's going on, I've added a couple
of print statements to the car class. Here in the tryToAdd method, we print out
whenever the driver has picked up a passenger. And in the drive method, we
print out, whenever the driver has dropped off a passenger. Now I would like
you to, run the car share app, with these inputs here. So Jane has a car, that
can hold four people including herself, wants to go to destination four. Fred
has a two seater wants to go to destination two. And these are all passengers,
they want to go to these destinations. The minus one signifies the end of
input. Go ahead and run the app, and tell me in which order do passengers get
dropped off.
Has escrito un montón de código y la aplicación casi está hecha.
Te voy a dar la última pieza. Aquí, en la clase CarShareApp (CocheCompartirApp) haces
un objeto de simulación, le pedimos que lea su entrada. Después cargamos los pasajeros
y conducimos los coches. También, para que veas lo que está pasando, he añadido un par
de declaraciones de impresión para la clase Coche. Aquí, en el método tryToAdd, imprimimos
cada vez que el conductor ha recogido un pasajero. Y en el método drive
imprimimos cada vez que el conductor ha dejado un pasajero. Ahora me gustaría
que ejecutaras la aplicación de compartir coche con estas entradas aquí. Así que Jane tiene un coche, que
puede albergar a cuatro personas incluyendo a sí misma, quiere ir al destino cuatro. Fred
tiene un coche de dos asientos y quiere ir al destino dos. Y todos estos son pasajeros,
quieren ir a estos destinos. El menos uno significa el final de
la entrada. Continua y ejecuta la aplicación y dime en qué orden llegaron
los pasajeros a su destino.
Vous avez écrit beaucoup de code
et, par chance, l'application
est presque terminée.
Je vous donnerai la dernière pièce.
Ici, dans la classe CarShareApp,
vous créez un objet de simulation,
nous lui demandons de lire son entrée.
Ensuite, nous chargeons les passagers
et conduisons les voitures.
Aussi, pour que vous voyiez
ce qui se passe,
j'ai ajouté quelques instructions
d'impression à la classe car.
Ici, dans la méthode tryToAdd,
nous imprimons chaque fois
que le conducteur prends un passager
et dans la méthode drive, nous imprimons,
chaque fois que le conducteur
dépose un passager.
Je voudrais que vous exécutiez
l'application de covoiturage,
avec ces entrées ici.
Jane a une voiture pouvant
contenir quatre personnes
y compris elle-même,
et veut aller à destination 4.
Fred a un deux places
veut aller à destination 2.
Et ce sont tous des passagers
qui veulent aller à ces destinations.
Le -1 signifie la fin de l'entrée.
Allez-y et lancez l'application
et dites-moi dans quel ordre
les passagers sont déposés.
たくさんコードを書いてきました
アプリケーションの完成は間近です
これが最後のCarShareAppクラスです
シミュレーションオブジェクトを作成し
入力を読み込んで乗客を乗せます
そして車を運転します
何が起きているか確かめるために
Carクラスにprint文をいくつか足しました
このtryToAddメソッドでは
運転手が乗客を乗せる度に出力します
driveメソッドでは
運転手が乗客を降ろす度に出力します
ではこのCarShareAppを
これらを入力して実行してください
ジェーンの車は彼女を含め4人乗ることができ
目的地4へ向かいます
フレッドは2人乗りの車で目的地2へ向かいます
そして各乗客がそれぞれの目的地に向かいます
-1は入力の最後です
アプリケーションを実行し
乗客が降りる順番を教えてください