Hey guys Im pretty new to Java and while I am finding it enjoyable i am getting several errors!!! Do you think you could help me on this particular question of an Assignment im doing.
I have to make a simple program that takes 10 sets of numbers from a text file which it reads the Length, Width and Height from. Then the program works out the Surface Area, Volume and the Postage. The Surface Area, Volume and Postage sections work fine but the actual printing into a table keeps giving me errors.
Here is my coding...
And this is my Error as you can see it starts printing the Table but the first line is printing my last set of numbers...
Thanks for any help in advance!!!
I have to make a simple program that takes 10 sets of numbers from a text file which it reads the Length, Width and Height from. Then the program works out the Surface Area, Volume and the Postage. The Surface Area, Volume and Postage sections work fine but the actual printing into a table keeps giving me errors.
Here is my coding...
Code:
import static java.lang.System.out;
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
class PostalServicetable
{
public static void main(String args[])
throws IOException
{
Scanner PostScanner = new Scanner(new File("Measures.txt"));
double Postage;
double Surface;
double Length;
double Width;
double Height;
double Volume;
out.println("Length Width Height S.A Vol Postage ");
Postage = 0;
Surface = 0;
Length = 0;
Width = 0;
Height = 0;
Volume = 0;
for (int count = 1; count <= 10; count++)
{
Length = PostScanner.nextDouble();
Width = PostScanner.nextDouble();
Height = PostScanner.nextDouble();
}
if (Volume < 8000)
{
Postage = 3.50;
}
if (Volume >= 8000 & Volume <= 64000)
{
Postage = 10.50;
}
if (Volume > 64000)
{
Postage = 10.50 + ((Volume - 64000)/10000);
}
out.printf(Length + "\t\t\t");
out.printf(Width + "\t\t\t");
out.printf(Height + "\t\t\t");
out.printf(Surface + "\t\t\t");
out.printf(Volume + "\t\t\t");
out.print(" ");
out.printf(Postage + "$%.2f\n");
}
}
Code:
Length Width Height S.A Vol Postage
23.0 24.0 25.0 0.0 0.0$Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier '.2f'
at java.util.Formatter.format(Formatter.java:2431)
at java.io.PrintStream.format(PrintStream.java:920)
at java.io.PrintStream.printf(PrintStream.java:821)
at PostalServicetable.main(postagetable.java:51)
Process completed.
Comment