hey im new to this forum and new to programming and i got an assignment for a sales ticket generator and i clicked compile and it said
variable burger might not have been initialized
please help....

import TerminalIO.KeyboardReader;

public class Resturant {
public static void main (String [] args) {
KeyboardReader reader = new KeyboardReader();

// Constants
final double BURGERS = 1.49;
final double FRIES = 0.89;
final double SODA = 0.99;

// Variables
double total;
double tax;
double totalT;
double burger ;
double frie;
double sodas;

// Input
System.out.print(" Burgers : " + burger );
burger = reader.readDouble();
System.out.print(" Fries : " );
frie = reader.readDouble();

}

First, welcome to the forum.

Second. Please learn to use the [ code ] tags.

Finally....

Lets look at the code.

Going through your code from top to bottom...

You make a new instance of a KeyBoardReader object. Which is used later in the program.

Then you declair some prices for your different products.

Then you declair some other attributes that have no value. So they are not being initialized and the compiler gets a little nervous when things aren't initialized.

You can fix your code by doing the following:

// Variables
double total = 0;
double tax = 0;
double totalT = 0;
double burger = 0;
double fries = 0;
double sodas = 0;

and don't forget to add a 's' to the end of fries.

Regards,

Nate

thanks alot i appreciate it

now i get this
Burgers : 0.03
Fries : 0.02
Sodas : 0.05
The total before tax is : 11.2
The tax is : 0.6719999999999999
The grand total is : $ 11.872
Press any key to continue...


how do i get rid of those zeros that are there because on my instructers program he didnt have that 0.0

now i get this
Burgers : 0.03
Fries : 0.02
Sodas : 0.05
The total before tax is : 11.2
The tax is : 0.6719999999999999
The grand total is : $ 11.872
Press any key to continue...


how do i get rid of those zeros that are there because on my instructers program he didnt have that 0.0

Where are you getting this? Is this output from your code? My guess is that it is output.

So, it looks as though you need to format your numbers. Try looking for java.text.NumberFormat and then looking at one of its sub classes, java.text.DecimalFormat.

You should be able to figure out how to use those classes to format your data.

Regards,

Nate

my instructor used {format.justify} to format the decimal places adn how many numbers are displayed

sorry bout so many questions but im 15 and have little experience with this

hmm... are you using BreezyGUI package or any package?

ie. charData = stdin.readDouble();

then format something it using BreezySwing.Format class ... then you can do something like

Format.justify('x', y, z, p);

where x is l, c, or r for left, center or right respectively
where y is data to be justified
where z is field width
and p is decimal places (double only)

example:

Format.justify('l', 34, 4)                "34  "
Format.justify('r', 34, 4)               "  34"
Format.justify('c', 34, 4)               " 34 "
Format.justify('r', 34.346, 7, 2)      "  34.35"

for java package,

http://java.sun.com/developer/TechTips/2000/tt0411.html


read the example given there, you should be getting the idea. :mrgreen:

thanks i got it now

welcome... :cheesy:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.