# calculation isn't working

No replies to this topic

### #1 jayne1069

jayne1069
• New Members
• Newbie
• 1 posts

Posted 03 August 2013 - 11:28 AM

This code needs to calculate a profit, I'm really new to this and when I calculate it it shows \$0 which is not correct. Could someone please help me and show me where the error is.

/**
* A program to work out Alfredo's profit from his mobile game
*
* @author (Jayne Hill)
* @version (2013 Semester 2)
*/

public class profit
{
public static void CalculateProfit(); }
{
// set up cost and usage parameters)
final int USERS = 10000;
final double PRICE = 0.99;
final double SERVER_PER_MONTH = 100.0;
final double COST_PER_REQUEST = 0.01/1000;
final int REQUEST_PER_GAMES = 4;

final int GAMES_1 = 100;
final int GAMES_2 = 20;
final int GAMES_3 = 20;
final int GAMES_4 = 20;
final int GAMES_5 = 20;
final int GAMES_6 = 20;
final int GAMES_7 = 5;
final int GAMES_8 = 5;
final int GAMES_9 = 5;
final int GAMES_10 = 5;
final int GAMES_11 = 5;
final int GAMES_12 = 5;

double totalCost = 0; // we will accumulate the costs here
int numberOfRequests; // how many requests in a given month

// month 1
totalCost = totalCost + SERVER_PER_MONTH;
numberOfRequests = GAMES_1*REQUEST_PER_GAMES*USERS;
totalCost = totalCost + numberOfRequests*COST_PER_REQUEST;

// month 2
totalCost = totalCost + SERVER_PER_MONTH;
numberOfRequests = GAMES_2*REQUEST_PER_GAMES*USERS;
totalCost = totalCost + numberOfRequests*COST_PER_REQUEST;

// month 3
totalCost = totalCost + SERVER_PER_MONTH;
numberOfRequests = GAMES_3*REQUEST_PER_GAMES*USERS;
totalCost = totalCost + numberOfRequests*COST_PER_REQUEST;

// month 4
totalCost = totalCost + SERVER_PER_MONTH;
numberOfRequests = GAMES_4*REQUEST_PER_GAMES*USERS;
totalCost = totalCost + numberOfRequests*COST_PER_REQUEST;

// month 5
totalCost = totalCost + SERVER_PER_MONTH;
numberOfRequests = GAMES_5*REQUEST_PER_GAMES*USERS;
totalCost = totalCost + numberOfRequests*COST_PER_REQUEST;

// month 6
totalCost = totalCost + SERVER_PER_MONTH;
numberOfRequests = GAMES_6*REQUEST_PER_GAMES*USERS;
totalCost = totalCost + numberOfRequests*COST_PER_REQUEST;

// month 7
totalCost = totalCost + SERVER_PER_MONTH;
numberOfRequests = GAMES_7*REQUEST_PER_GAMES*USERS;
totalCost = totalCost + numberOfRequests*COST_PER_REQUEST;

// month 8
totalCost = totalCost + SERVER_PER_MONTH;
numberOfRequests = GAMES_8*REQUEST_PER_GAMES*USERS;
totalCost = totalCost + numberOfRequests*COST_PER_REQUEST;

// month 9
totalCost = totalCost + SERVER_PER_MONTH;
numberOfRequests = GAMES_9*REQUEST_PER_GAMES*USERS;
totalCost = totalCost + numberOfRequests*COST_PER_REQUEST;

// month 10
totalCost = totalCost + SERVER_PER_MONTH;
numberOfRequests = GAMES_10*REQUEST_PER_GAMES*USERS;
totalCost = totalCost + numberOfRequests*COST_PER_REQUEST;

// month 11
totalCost = totalCost + SERVER_PER_MONTH;
numberOfRequests = GAMES_11*REQUEST_PER_GAMES*USERS;
totalCost = totalCost + numberOfRequests*COST_PER_REQUEST;

// month 12
totalCost = totalCost + SERVER_PER_MONTH;
numberOfRequests = GAMES_12*REQUEST_PER_GAMES*USERS;
totalCost = totalCost + numberOfRequests*COST_PER_REQUEST;

//calculate profit
double profit = USERS*PRICE-totalCost;
System.out.println("Alfredo's game should make a total profit of \$");

}
}

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users