Results 1 to 13 of 13
  1. #1
    andnlou2678 is offline Member
    Join Date
    Sep 2011
    Posts
    69
    Rep Power
    0

    Default java program help please

    if it costs 3 to produce an item which is then priced at 5, there is 2 profit per item. If the overall expenses are 20, the company would need to sell 10 items to break even.

    i need to Write a program to output the break even point using the above values.

    please can somebody point me in the right direction please

    many thanks Andy

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: java program help please

    So you'll want to break the problem down into the steps involved, and so your first thinking should be what exactly are the steps needed? Also, please have a look at the excellent article titled "So, You Need to Write a Program but Don't Know How to Start"

    Also on a side note, will the user be inputting the data or will it be hard-coded into the program?

  3. #3
    Solarsonic is offline Senior Member
    Join Date
    Mar 2011
    Posts
    261
    Rep Power
    4

    Default Re: java program help please

    Just simple math operators.

    Create a couple double variables, one for each of your values. Then find the number of items you break even by dividing expenses by profit.
    Last edited by Solarsonic; 10-02-2011 at 01:44 AM.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: java program help please

    @Solarsonic: let's let the newbie learn to do the coding. Please don't do their work for them.

  5. #5
    andnlou2678 is offline Member
    Join Date
    Sep 2011
    Posts
    69
    Rep Power
    0

    Default Re: java program help please

    all i know i will be writing this in notepad and then running in cmd

    many thanks Andy.

  6. #6
    andnlou2678 is offline Member
    Join Date
    Sep 2011
    Posts
    69
    Rep Power
    0

    Default Re: java program help please

    i dont want people to do for me i just wanted some help to how i start this..

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: java program help please

    Quote Originally Posted by andnlou2678 View Post
    all i know i will be writing this in notepad and then running in cmd

    many thanks Andy.
    Please check out the link that I have provided and Solarsonic's suggestion. Then if you get stuck with your code, please show us your code and any questions that you may have and we'll be glad to help.

    Quote Originally Posted by andnlou2678 View Post
    i dont want people to do for me i just wanted some help to how i start this..
    Well, can you tell us as specifically as possible, where are you stuck?

  8. #8
    andnlou2678 is offline Member
    Join Date
    Sep 2011
    Posts
    69
    Rep Power
    0

    Default Re: java program help please

    hi thankyou for the replys and help i am getting one error with my try code please could you help me with this

    my code

    Java Code:
    /* Declare variables [Data type e.g int or double] [Variable name (REMEMBER CASE SENSITIVE)] = [Value] */
    
    public class Variables
    {
    
           public static void main (String[] args)
    
           {
    
    
    
    double ItemAmount = 3.00;
    
    
    
    double ItemPrice = 5.00;
    
    
    
    double ExpensesPrice = 20.00;
    
    
    
    double Profit = 0.00;
    
    
    
    int SellAmount = 0;
    
    
    
    
    
    
    
    Profit = ItemPrice - ItemAmount;
    
    
    
    SellAmount = Profit/ExpensesPrice;
    
    
    
    
    
    System.out.println("The number of items needed to be sold is: " + SellAmount + " With the item amount at: " + ItemAmount + " and the retail price at: " + ItemPrice);
    
    
    
    
    
    
    
           }
    
    }
    my error

    Java Code:
    H:\FPT>javac Variables.java
    Variables.java:40: error: possible loss of precision
    SellAmount = Profit/ExpensesPrice;
                       ^
      required: int
      found:    double
    1 error
    many thanks Andy
    Last edited by pbrockway2; 10-02-2011 at 03:21 AM. Reason: code tags added

  9. #9
    andnlou2678 is offline Member
    Join Date
    Sep 2011
    Posts
    69
    Rep Power
    0

    Default Re: java program help please

    i think i solved it but could somebody please check if my answer is right for me

    many thanks Andy



    H:\FPT>java Variables
    The number of items needed to be sold is: 0.1 With the item amount at: 3.0 and
    the retail price at: 5.0

  10. #10
    Solarsonic is offline Senior Member
    Join Date
    Mar 2011
    Posts
    261
    Rep Power
    4

    Default Re: java program help please

    Quote Originally Posted by andnlou2678 View Post
    hi thankyou for the replys and help i am getting one error with my try code please could you help me with this

    my code
    Change sellAmount to a double.

    Also, you mixed up your variables; they all have the wrong values...

  11. #11
    andnlou2678 is offline Member
    Join Date
    Sep 2011
    Posts
    69
    Rep Power
    0

    Default Re: java program help please

    yes i realized that thanks but what have i done wrong with my variables....

  12. #12
    Solarsonic is offline Senior Member
    Join Date
    Mar 2011
    Posts
    261
    Rep Power
    4

    Default Re: java program help please

    Your variables are confusing. Think like you're doing the math on paper. Your variables would be:

    Java Code:
    double costToMake = 3.00;
    double sellPrice = 5.00;
    double profit = sellPrice - costToMake;
    double expenses = 20.00;
    double itemsToBreakEven = expenses/profit;
    Last edited by Solarsonic; 10-02-2011 at 03:49 AM.

  13. #13
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,568
    Rep Power
    12

    Default Re: java program help please

    When you post code, please use the "code" tags: put [code] at the start of the code and [/code] at the end. This allows the code to be readable when it appears on a web page. (Similar conventions exist across the internet).

    You will also improve readability by following Java coding conventions (google the phrase for details): variables always start with a lowerCase letter, and consistent indentation is vital.

    -----

    Before writing the code read through the question and try to express the information in a general, somewhat algebraic, way. Identify the "things" in the problem: cost-per-item, price and all the rest. These will (later!) correspond to variables and expressions in your code.

    Divide the "things" in the problem into those that are "given" and those that are "to be calculated".

    For example the first sentence of your original post includes three things: cost-per-item, price and profit-per-item. The first two are given values while the last is calculated from the first two. You need to identify how it is calculated and express that as a formula. Basically you should begin with a close reading of the problem to identify all of its elements and whether they should be considered given or to be calculated. Where things are calculated (rather than given) your code will probably include an expression corresponding their formula.

    -----

    "Possible loss of precision" is the compiler's way of saying that the expression on the right hand side involves integer quantities and integer division, while the variable on the left hand side is a floating point one. Integer things and operations involve whole numbers (no fractions) which are expressed exactly. Floating point variables, on the other hand, have values that are somewhat imprecise - there are an infinite number of floating point values so the computer has no way of expressing them all with complete precision - so that when you assign an integral thing to a floating point variable you lose precision.

    You can always cast an integral value to a floating point one, which is a way of telling the compiler that you know what you are doing and that it should keep quiet about the loss of precision:

    Java Code:
    int foo = 42;
    int bar = 666;
    double result = (double)foo / bar;
    Personally I think you are a little way from actually writing the code at this point, however. My comments above are intended to elaborate on points (1) and (4) of the page Fubarable linked to.
    Last edited by pbrockway2; 10-02-2011 at 03:50 AM.

Similar Threads

  1. Call one Java Program from another Java Program
    By rajpalparyani in forum New To Java
    Replies: 3
    Last Post: 02-14-2011, 05:13 AM
  2. Replies: 4
    Last Post: 07-30-2010, 01:25 PM
  3. execute java program within java program
    By popey in forum New To Java
    Replies: 2
    Last Post: 10-22-2009, 06:32 PM
  4. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 10:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •