0

I need to divide the total sales by 500 to get the discount threshold for an assignment I'm working on, and I can't figure out what is wrong. Apologies if this is a dumb question, but I'm in my first few weeks learning java.

String nameDFF;
    String inputStringDFF;
    int quantityDFF, discountThresholdDFF;
    double salesPriceDFF, totalSalesAmountDFF;



    //Create a new Scanner object to read user's input
    Scanner keyboard = new Scanner(System.in);

    //Get the user's name 
    System.out.print("What is your name? ");
    nameDFF = keyboard.nextLine();

    //Get the the user's quantity they want to buy
    System.out.print("\nWhat is the quantity you want to buy?\n Enter a whole number greater than or equal to 1.");
    quantityDFF = keyboard.nextInt();

    //Get the sales price of the item
    System.out.print("\nWhat is the sales price of the item?\n Enter the value greater than 0.");
    salesPriceDFF = keyboard.nextDouble();

    //Calculate total sales amount
    totalSalesAmountDFF = quantityDFF * salesPriceDFF;

    //Calculate the discount threshold
    discountThresholdDFF = totalSalesAmountDFF / 500;
}
DFF55
  • 11
  • 1
  • 2
    Have a read https://stackoverflow.com/questions/3144610/integer-division-how-do-you-produce-a-double Also look into https://stackoverflow.com/questions/13252903/i-need-to-convert-an-int-variable-to-double – Balwinder Singh Feb 28 '18 at 23:25

1 Answers1

0

You’re dividing a double precision floating point by 500 and storing the result in an integer.

What do you actually want it to do with the remaining decimals? Should it Math.floor so you only get the non decimal part, Math.round to the nearest integer, or did you actually want the result variable to also be double precision?

Java needs guidance from you because you’re asking it to do an operation without enough information, hence the error.

SplinterReality
  • 3,400
  • 1
  • 23
  • 45