468,733 Members | 1,491 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,733 developers. It's quick & easy.

Simple table program errors

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...
Expand|Select|Wrap|Line Numbers
  1. import static java.lang.System.out;
  2. import java.util.Scanner;
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. class PostalServicetable
  7.   {
  8.        public static void main(String args[])
  9.                              throws IOException
  10.        {
  11.        Scanner PostScanner = new Scanner(new File("Measures.txt"));
  12.  
  13.  
  14.        double Postage;
  15.        double Surface;
  16.        double Length;
  17.        double Width;
  18.        double Height;
  19.      double Volume;
  20.      out.println("Length         Width            Height            S.A               Vol                Postage              ");
  21.  
  22.     Postage = 0;
  23.     Surface = 0;
  24.     Length = 0;
  25.     Width = 0;
  26.     Height = 0;
  27.        Volume = 0;
  28.      for (int count = 1; count <= 10; count++)
  29.      {
  30.          Length = PostScanner.nextDouble();
  31.           Width = PostScanner.nextDouble();
  32.           Height = PostScanner.nextDouble();
  33.      }
  34.        if (Volume < 8000)
  35.        {
  36.              Postage = 3.50;
  37.         }
  38.         if (Volume >= 8000 & Volume <= 64000)
  39.         {
  40.               Postage = 10.50;
  41.         }
  42.            if (Volume > 64000)
  43.        {
  44.           Postage = 10.50 + ((Volume - 64000)/10000);
  45.   }
  46.  
  47.            out.printf(Length + "\t\t\t");
  48.            out.printf(Width + "\t\t\t");
  49.            out.printf(Height + "\t\t\t");
  50.            out.printf(Surface + "\t\t\t");
  51.            out.printf(Volume + "\t\t\t");
  52.            out.print("          ");
  53.            out.printf(Postage + "$%.2f\n");
  54.        }      
  55.  
  56. }
  57.  
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...

Expand|Select|Wrap|Line Numbers
  1. Length         Width            Height            S.A               Vol                Postage              
  2. 23.0            24.0            25.0            0.0         0.0$Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier '.2f'
  3.     at java.util.Formatter.format(Formatter.java:2431)
  4.     at java.io.PrintStream.format(PrintStream.java:920)
  5.     at java.io.PrintStream.printf(PrintStream.java:821)
  6.     at PostalServicetable.main(postagetable.java:51)
  7.  
  8. Process completed.
  9.  
Thanks for any help in advance!!!
Feb 20 '08 #1
1 2164
r035198x
13,262 8TB
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...
Expand|Select|Wrap|Line Numbers
  1. import static java.lang.System.out;
  2. import java.util.Scanner;
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. class PostalServicetable
  7.   {
  8.        public static void main(String args[])
  9.                              throws IOException
  10.        {
  11.        Scanner PostScanner = new Scanner(new File("Measures.txt"));
  12.  
  13.  
  14.        double Postage;
  15.        double Surface;
  16.        double Length;
  17.        double Width;
  18.        double Height;
  19.      double Volume;
  20.      out.println("Length         Width            Height            S.A               Vol                Postage              ");
  21.  
  22.     Postage = 0;
  23.     Surface = 0;
  24.     Length = 0;
  25.     Width = 0;
  26.     Height = 0;
  27.        Volume = 0;
  28.      for (int count = 1; count <= 10; count++)
  29.      {
  30.          Length = PostScanner.nextDouble();
  31.           Width = PostScanner.nextDouble();
  32.           Height = PostScanner.nextDouble();
  33.      }
  34.        if (Volume < 8000)
  35.        {
  36.              Postage = 3.50;
  37.         }
  38.         if (Volume >= 8000 & Volume <= 64000)
  39.         {
  40.               Postage = 10.50;
  41.         }
  42.            if (Volume > 64000)
  43.        {
  44.           Postage = 10.50 + ((Volume - 64000)/10000);
  45.   }
  46.  
  47.            out.printf(Length + "\t\t\t");
  48.            out.printf(Width + "\t\t\t");
  49.            out.printf(Height + "\t\t\t");
  50.            out.printf(Surface + "\t\t\t");
  51.            out.printf(Volume + "\t\t\t");
  52.            out.print("          ");
  53.            out.printf(Postage + "$%.2f\n");
  54.        }      
  55.  
  56. }
  57.  
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...

Expand|Select|Wrap|Line Numbers
  1. Length         Width            Height            S.A               Vol                Postage              
  2. 23.0            24.0            25.0            0.0         0.0$Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier '.2f'
  3.     at java.util.Formatter.format(Formatter.java:2431)
  4.     at java.io.PrintStream.format(PrintStream.java:920)
  5.     at java.io.PrintStream.printf(PrintStream.java:821)
  6.     at PostalServicetable.main(postagetable.java:51)
  7.  
  8. Process completed.
  9.  
Thanks for any help in advance!!!

There you go.
Feb 20 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

16 posts views Thread by Terry | last post: by
5 posts views Thread by Rob Somers | last post: by
3 posts views Thread by Basil Fawlty | last post: by
8 posts views Thread by SK | last post: by
1 post views Thread by foolproofplan | last post: by
8 posts views Thread by ftjonsson | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.