如果一家電影院的門票售價爲5美元,平均每場節目售出100張門票,則每人的費用爲2美元。對於0.25美元的每次減價,售出的門票數量增加30,而每人的成本增加0.10美元。打印一張表格,顯示價格(從$ 5到$ 3),售出的門票數量,人均成本,總收入,總成本,淨利潤。指示最大利潤。最大利潤計算器Java
我在接近這個問題時遇到了問題,我正在尋找正確的方向指導幫助。我不擅長編碼,我正在做這個練習。我嘗試使用我的知識使用數組,但無濟於事。感謝幫助。
/* If a cinema sells tickets for $5 and averages 100 tickets sold per show,
the cost per person is $2.
For each reduction in price of $0.25,
the number of tickets sold increases by 30 and the cost per person increases by $0.10.
Print a table showing the price (ranging from $5 to $3,) the number of tickets sold,
cost per person, gross revenue, total cost, net profit. Indicate the maximum profit.
*/
import java.util.*;
import java.io.*;
public class MaxProfitCalc {
public static void main(String[] args) {
for (double ticketCost = 5.0; ticketCost >= 3.0; ticketCost-=0.25) {
System.out.printf("Ticket cost is: " + "%.2f\n", ticketCost);
}
for (double costPerPerson = 2.0; costPerPerson <= 2.80; costPerPerson+=0.10) {
System.out.printf("Cost per person is: " + "%.2f\n", costPerPerson);
}
for (int ticketSold = 100; ticketSold <= 340; ticketSold+=30) {
System.out.println("Amount of tickets sold: " + ticketSold);
}
}
}
編輯我想通了如何打印數字,現在是計算數字的問題。有沒有辦法訪問最高的數字,以便找出最大利潤,總收入和總成本?我需要創建一個數組還是可以有辦法從for循環中獲取數字?
做些什麼,然後回來尋找方向。我的女兒學會了走路試着走路。 – Bathsheba
我相信如果你尋求關於如何分析這個問題的建議,[programmer.se]會更好。 @Bathsheba,最好的建議,但我希望你會在她學習騎自行車時幫助她;) – AxelH
創建一個數組和一個while循環是合乎邏輯的嗎? – jermac