473,657 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple table program errors

1 New Member
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 2409
r035198x
13,262 MVP
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
2878
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 loaded into cache, the slideshow doesn't look very nice. I am not sure how/when to call the slideshow() function to make sure it starts after the preload has been completed.
4
2104
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 problem I am having is that if no unique items exist, this will insert into the table fine. But if a unique item does exist it will not insert as it should. My problem is that I can not get access to return any kind of error. This is very...
5
7234
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, two aspects which I want to incorporate into my program eventually. That aside, my most pressing problem right now is how to get rid of the newline in the input when I use fgets(). Now I have looked around on the net, not so much in this group...
0
1422
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. Very simple, the control works fine when creating it dynamicly from code. My aim is to add design functionality, so I can use it from the Visual Studio .Net toolbox. When I compile my code, no errors are reproted and Visual studio leaves a
3
3747
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 have inserted the old LIberty BASIC code. Now my problem is how to go about making the mod to the code to fit VB's needs, but not loose the logic as it's sound. What should I start doing at this point? Many thanks, Basil Private Sub...
8
2122
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 I would really apprecaite it. Thanks SK //Specs to be added later //C Libraries #include <stdio.h>
2
4199
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 file (which I can provide if necessary). I use 'Add new Item' and pick 'DataSet'. I believe this creates a TypedDataSet, CORRECT? I take all the defaults as far as Insert, and I pick the advanced tab and ask for Update Statements and Delete...
1
3027
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 percent sure where to begin. Here is an example of an xml file I have: <SquishReport version="1.2" > <summary fatals="0" testcases="13" expected_fails="0" unexpected_passes="0" warnings="0" tests="180" errors="0" fails="0"
8
3171
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
8395
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7330
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6166
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.