Jump to content

calculation isn't working


Recommended Posts

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 $");
      
    }
}
 

Link to comment
https://forums.phpfreaks.com/topic/280793-calculation-isnt-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.