如果一家电影院的门票售价为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