473,224 Members | 1,451 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

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 2368
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

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

Similar topics

16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
4
by: frank | last post by:
I posted a question before (to too many groups) and this time I am sending to this group only. I have a quick script as seen below, the file_list table has a unique field called file_name. The...
5
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
0
by: Mobile Boy 36 | last post by:
I'm trying to make a very simple Textbox with a FocusColor property...When the focus changes to the control, the backcolor must change automaticly to the color set by the focusColor property....
3
by: Basil Fawlty | last post by:
Hi everyone, I could use some help in converting a simple Liberty BASIC program toa VB.NET 2003 SE program. I have built the simple form with a label, text box and button, Under the button I...
8
by: SK | last post by:
Hi I am trying to write a simple C program with devc++ as the complier using the concept of arrays. I cannot get the program to compile without mutiple errors. If anyone has the time to help me...
2
by: dave | last post by:
Hi, I have searched for the answer for this error message without success. I have seen the question many times though:) I create an ASP.NET project (VS 2005, C#), and use a very simple .mdf...
1
by: foolproofplan | last post by:
I have a situation where I need to convert an xml file into two types of tables in html. I have never done anything like this before, so I have been reading up on it online. However, I am not 100...
8
by: ftjonsson | last post by:
hello, I was wondering if anyone could tips me on what I am doing wrong when writing the following code: #include <iostream> using namespace std; int main () {
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.