473,387 Members | 1,834 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,387 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 2382
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.