現在、私はJavaで私の最初のコーディングプロジェクトを行っています。お客様に次のことを可能にする注文システムです。まず、顧客はアプリケーションをナビゲートし、コペンハーゲンでお気に入りのレストランを選択し、個々のメニューリストから食事を選ぶことができます。第2に、各注文は、注文数量および配送場所に関連してカスタマイズ可能でなければならない。最後に、システムは、最も近い利用可能なバイカーを割り当てて、レストランから注文を受け取り、規定された時間に指定された目的地に食事を届けなければならない。Javaの食事オーダーシステムのコレクションエラー
@テレサの助けを借りて、私はプログラムをもう一度テストしましたが、最後のマイルを走らせることはできません。システムが最も近い利用可能なバイカーを割り当てて、レストランから注文を受け取るべき部分は機能しません。私はまだできていないと感じています。なぜなら私はできる限りのことを試みたからです。
他のコメント、ヒント、または助けがあれば幸いです。ありがとうございます。
これは、更新されたコードである:[https://www.dropbox.com/s/awvohw7vholsdrd/Cleaner_DeliveryBike.zip?dl=0][1]
private static void setDelivery() throws Exception {
double totalTime = 0;
String delivery = "Now that you have chosen what you want to order, we would like to introduce to you our MadCyklers."
+ "All day we have 5 biker that are touring arround the city to deliver your order right to you. We only need"
+ "to know one thing from you: where in Copenhagen are you right now?";
try {
printString(navigationFrameTop);
printString(delivery);
printString(navigationFrameBottom);
printString(categoryFrame);
System.out.println(" *COPENHAGEN* ");
System.out.println("");
System.out.println(" LONG> 12.52 12.54 12.56 12.58 12.60 12.62");
System.out.println(" . . . . . . ");
System.out.println(" 55.70 + . . . + . . . + . . . + . . . + . . . + ");
System.out.println(" . . . . . . ");
System.out.println(" 55.69 + . . . + . . . + . . . + . . . + . . . + ");
System.out.println(" . . . . . . ");
System.out.println(" 55.68 + . . . + . . . + . . . + . . . + . . . + ");
System.out.println(" . . . . . . ");
System.out.println(" 55.67 + . . . + . . . + . . . + . . . + . . . + ");
System.out.println(" . . . . . . ");
System.out.println(" 55.66 + . . . + . . . + . . . + . . . + . . . + ");
System.out.println(" ^ . . . . . . ");
System.out.println(" LAT");
printString(categoryFrame);
printString(inputFrame);
customer.setLongitude(0);
printString(inputFrame);
customer.setLatitude(0);
printString(inputFrame);
double min = 9999999;
double distance;
// checking if Indications are correct.
for(Biker biker : BIKERS) {
biker.setLatitude(0);
biker.setLongitude(0);
distance = biker.distanceTo(customer) + (restaurants.get(restaurantPick)).distanceTo(customer);
if(distance < min) {
min = min + distance;
activeBiker = biker.iD;
}
}
totalTime = (min/KILOMETRES_PER_HOUR) * 3600000
+ restaurants.get(restaurantPick).getPreparationTime() * 60000;
deliveryTime = (long) (currentTime + totalTime);
String deliveryConfirmation = " Your order will be delivered to your location at: " + deliveryTime
+ " from our MadCykler " + BIKERS.get(activeBiker).getTipFactor() + ".";
printString(deliveryConfirmation);
payment();
} catch (Exception e) {
printString(errorFrame);
System.out.println("Error! Reloading Main Menu...");
printString(errorFrame);
main(null);
}
}
private static void payment() throws Exception {
BigDecimal tip = BigDecimal.ZERO;
BigDecimal tipPrice = BigDecimal.ZERO;
int payingOption = 0;
String payment = "There is only one more thing left to do for you. Just initialize the payment and we will send"
+ "you the order confirmation. Then you just have to wait for" + BIKERS.get(activeBiker).getTipFactor()
+ "to arrive with your order.";
String totalCost = "The total costs are " + getTotal() + "DKK. What % tip would you like to give to the Cykler? ";
try {
printString(navigationFrameTop);
printString(payment);
printString(navigationFrameBottom);
printString(categoryFrame);
printString(totalCost);
printString(categoryFrame);
printString(inputFrame);
tip = BIKERS.get(activeBiker).getTipFactor();
printString(inputFrame);
tipPrice = tip.divide(tip, 100).multiply(getTotal());
deliveryCost = deliveryCost.add(getTotal()).add(tipPrice);
String totalDelivery = "The overall delivery cost are " + deliveryCost + "DKK. Press [1] if you would like to pay,"
+ "[2] to pick a new restaurant, or [3] to return to the Main Menu.";
String totalDeliveryError = "Error! Press [1] if you would like to pay,[2] to pick a new restaurant, or [3] to "
+ "return to the Main Menu.";
printString(categoryFrame);
printString(totalDelivery);
printString(categoryFrame);
do {
Scanner input = new Scanner(System.in);
printString(inputFrame);
payingOption = input.nextInt();
printString(inputFrame);
switch (payingOption) {
case 1:
wrapOrder();
break;
case 2:
choiceMeal = null;
quantityMeal = null;
pickingRestaurant();
break;
case 3:
choiceMeal = null;
quantityMeal = null;
main(null);
break;
default:
printString(errorFrame);
printString(totalDeliveryError);
printString(errorFrame);
break;
}
} while (payingOption != 1 && payingOption != 2 && payingOption != 3);
} catch (Exception e) {
printString(errorFrame);
System.out.println("Error! Reloading Main Menu...");
printString(errorFrame);
main(null);
}
}
private static void wrapOrder() {
String s = "";
UUID customerId;
BigDecimal currentBalance = BigDecimal.ZERO;
String customerDetails = customer.toString();
long arrival = deliveryTime;
BigDecimal bill = deliveryCost;
currentBalance = creditAccounts.get(customerAccountLoggedIn).getBalance();
if (currentBalance.compareTo(deliveryCost) > 0) {
printString(categoryFrame);
System.out.println(" Your payment was successful.");
printString(categoryFrame);
creditAccounts.get(customerAccountLoggedIn).withdraw(deliveryCost);
for (int i = confirmations.size(); i < confirmations.size() + 1; i++) {
customerId = confirmations.get(i).getOrderId();
Confirmation confirmation = new Confirmation(customerId, customerDetails, arrival, bill);
confirmations.add(confirmation);
printString(navigationFrameTop);
confirmation.toString();
printString(navigationFrameBottom);
}
}
else {
printString(errorFrame);
creditAccounts.get(customerAccountLoggedIn).withdraw(deliveryCost);
printString(errorFrame);
reCharging();
}
// ending the program and clearing all content during the order
}
それが何をしたい終えることができたとき、それは滑らかな印象 私は完成したコードを上に置く作ることができる場所である小さな提案
ですあなたは言っていますが、私たちはデータベースを全く使っていません。したがって、私はハードコードのしか方法を知っていると思います:/システム自体がより効果的で調整可能でなければなりませんが、私たちが学んだことは私にそれを何でもすることを許しません。私のハードコードにどうやって対処できるか他の提案がありますか? @TheresaForster – maximal16
それから、私はあなたにハードコードを1ヶ所で提案し、その周りに残りを構築することをお勧めします。あなたは大学のプロジェクトとしてこれをやっていると思います。 –
はい。正直言って、私はそれがコーディングになると幼いです。私はITビジネスの背景を持っていて、実際に高級言語を学ぶためにプログラミングマイナーを選んだ。このプロジェクトを成功させるために過去3週間に90時間を費やしました。本当にありがとう!私はこれを今実装し、私はそれを構築することができますかどうかを見てみましょう。私はそれが問題を止めることを望む。 – maximal16