-1

I keep getting these error codes:

SoftwareSales.java:20: cannot find symbol

symbol : variable Sales

location: class SoftwareSales

  Sales = 99;
  ^

SoftwareSales.java:30: cannot find symbol

symbol : variable Sales

location: class SoftwareSales

  Total = Quantity * Sales;
                     ^

SoftwareSales.java:32: cannot find symbol

symbol : variable Disount

location: class SoftwareSales

  Total = Total - Disount;
                  ^

SoftwareSales.java:37: possible loss of precision

found : float

required: int

     Rate = .20f;
            ^

SoftwareSales.java:39: possible loss of precision

found : float

required: int

     Rate = .30f;
            ^

SoftwareSales.java:41: possible loss of precision

found : float

required: int

     Rate = .40f;
            ^

SoftwareSales.java:43: possible loss of precision

found : float

required: int

     Rate = .50f;
            ^

7 errors

This is my code so far:

import java.util.Scanner;

public class SoftwareSales
{
   public static void main(String[] args)
   {

      Scanner keyboard = new Scanner(System.in);

      Sales = 99;

      int Quantity;
      int Total;
      int Rate;
      double Discount;

      System.out.print ("Enter amount of packages purchased: ");
            Quantity = keyboard.nextInt();

      Total = Quantity * Sales;
      Discount = Total * Rate;
      Total = Total - Disount;

      if(!(Total < 10))
         System.out.println("No discount." + "Your total is: " + Total);
      else if(Total >= 19)
         Rate = .20f;
      else if(Total >= 49)
         Rate = .30f;
      else if(Total >= 99)
         Rate = .40f;
      else
         Rate = .50f;

      System.out.println("Your discount is " + Discount + 
                         ". Your total is: " + Total);
   }
}

Any help will be very much appreciated. Thanks for your time.

user2771077
  • 71
  • 2
  • 2
  • 7

4 Answers4

3

You need to declare the variable Sales. For example:

int Sales = 99;

The loss-of-precision errors are because you are assigning float values to int variables. While this is sometimes treated as a warning, it usually indicates an error and requires either declaring the proper variable types or using an explicit cast. Possibly you should declare the variables to be float. Alternatively, do all the calculations in integer cent values and avoid potential round-off errors.

Not that you asked about this, but Java naming conventions are for variables to be camel case and start with a lower-case letter: sales instead of Sales (and totalSales instead of TotalSales, if you had such a variable name).

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
2

You may want to make your variables lowercase to avoid confusion with class names. In java class names are always capitalized which may introduce confusion in your code.

You're missing int sales = 99; it cannot resolve the symbol because you never declared it.

Rate should be a double and you're casting values to float, you can leave off the .f

Jesus Ramos
  • 22,940
  • 10
  • 58
  • 88
  • `Discount` is just a typo. `Rate` is the variable with the float issue and it is because it is declared as an int. – Jon Sep 13 '13 at 17:23
  • One of his/her errors was `Discount` typo'd as `Discout`. The other error is that `Rate` is declared as an int not a double or float. – Jon Sep 13 '13 at 17:25
2
  • You haven't defined Sales
  • You have a typo in Disount
  • Rate should be of type float
Detheroc
  • 1,833
  • 15
  • 19
0

You need to learn variable types my friend. Sales is most likely an int so

int Sales

Rate is a double so

double Rate

Whole code should be

import java.util.Scanner;

public class SoftwareSales
{
   public static void main(String[] args)
   {

      Scanner keyboard = new Scanner(System.in);

      int sales = 99;

      int quantity;
      double total;
      double rate = 0; // set rate to what you need.
      double discount;

      System.out.print ("Enter amount of packages purchased: ");
            quantity = keyboard.nextInt();

      total = quantity * sales;
      discount = total * rate;
      total = total - discount;

      if(!(total < 10))
         System.out.println("No discount." + "Your total is: " + total);
      else if(total >= 19)
         rate = .20f;
      else if(total >= 49)
         rate = .30f;
      else if(total >= 99)
         rate = .40f;
      else
         rate = .50f;

      System.out.println("Your discount is " + discount + 
                         ". Your total is: " + total);
   }
}
Quillion
  • 6,346
  • 11
  • 60
  • 97
  • Thanks for your time and the visual aid. I still keep forgetting about the naming conventions and i'll try too keep this in mind. – user2771077 Sep 13 '13 at 17:34
  • Im still getting an error of "possible loss of precision" for **`total = total - discount;`** @Quillion – user2771077 Sep 13 '13 at 17:38
  • Your total is an int, your discount is a double. Therefore the precision lost will be the decimal digits when you are doing the arithmetic. If you want, change the type of total to a double and you are good, no decimal digits will be lost. – Quillion Sep 13 '13 at 17:44
  • Thank you for your time! It's very much apreciated. @Quillion – user2771077 Sep 13 '13 at 17:45
  • Im very sorry again but another error appeared right after we just fixed this one it says, _"Variable rate might not have been initialized"_ for **`discount = total * rate;`** @Quillion – user2771077 Sep 13 '13 at 17:48
  • no problem :) glad I can help, you need to have some kind of a value assigned to rate. When you try to calculate discount, it tries to see what rate is, but it has no value assigned. I edit the code for you. – Quillion Sep 13 '13 at 17:59
  • Ohhhh ok thanks a lot! no error came up but i did see that when i run the code and I entered 1 for the amount of pkgs it would display **"No discount. Your total is 99."** and also **"Your discount is 0.0 your total is 99.0"** I don't want it to show both msgs when its less than 10 and or the decimal point if its a whole number. @Quillion – user2771077 Sep 13 '13 at 18:08
  • 1
    Taht's another question and another thing. For showing proper messages I will let you try that yourself. For showing proper numbers look into http://stackoverflow.com/questions/50532/how-do-i-format-a-number-in-java or http://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html – Quillion Sep 13 '13 at 18:25