Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2004

Tip: Looking for answers? Try searching our database.

Help on finding the error in my homework assignment

Thread view: 
Andy B. - 12 Sep 2004 21:06 GMT
My program is not compiling properly, and I was hoping that someone
would know how to fix the program (listed below).  The first part of
the program compiles well (the conversion of the temperature) but the
second part keeps giving me errors.  I've only been working with Java
for a few weeks, so I'd appreciate any extra information anyone can
give me about general errors in my code as well as what is
specifically keeping the program from running.  Thank you in advance!

/* Homework #1
* This program is in two parts -
* 1. The program converts degrees Fahrenheit to degrees Centigrade.
* 2. The program takes an amount of money and finds the smallest
* number of cents that it can be divided into.
*/

import java.io.*;
public class HwOneApp
{
// class data
   static private PrintWriter screen      = new
PrintWriter(System.out,

true);
   static private BufferedReader keyboard = new BufferedReader(
                                            new

InputStreamReader(System.in));
   static private PrintWriter ps;
   static private int cents, quarters, dimes, nickels, pennies,
totCoins;

// class methods
public static void main(String [] argv) throws IOException
// Part One
{
  double degF, degC;

  ps = new PrintWriter (new FileWriter ("HwOneOut.doc"));
  for (int i = 1; i <= 5; i++)
  {
    screen.print("\nEnter a temperature in degrees F > ");
    screen.flush();
    degF = Double.parseDouble(keyboard.readLine());

    ps.println ("\nEnter a temperature in degrees F > " + degF);
    degC = (5.0 / 9) * (degF - 32);

    screen.println( + degF + " degrees F = " + degC + " degrees C");
    ps.println ( + degF + " degrees F = " + degC + " degrees C");
   }
   {
// Part Two
     
 for (int i = 1; i <= 5; i++);

 { cents = quarters = dimes = pennies = nickels = totCoins = 0;
   cents = getCents();
   calCoins();
   displayResults(screen);
   displayResults(ps);

 } ps.close();

// method #2
//This method prompts user for input amount.

 private static int getCents() throws IOException

 { int money = 0;
   screen.print("\nEnter an amount of money >");
   screen.flush();
   mone = Integer.parseInt (keyboard.readline());
   ps.prinntln ("\nEnter an amount of money >" + money);
   return money;
 }

 
// method #3
//This method calculates the minimum output amount.
   
   private void calCoins

     { int temp = 0;
       quarters = cents / 25;
       temp     = cents % 25
       dimes    = temp / 10
       temp     = temp % 10
       nickles  = temp / 5
       temp     = temp % 5
       pennies  = temp / 1;
       totCoins = quarters + dimes + nickles + pennies;
     }
// method #4
// This method displays the minimum number of coins by denomination.

   private static void displayResults (PrintWriter fps);

   {
     fps.println ("\n Part Two Results" +
                  "\n Total Coins = " + totCoins +
                  "\n Quarters    = " + quarters +
                  "\n Dimes       = " + dimes +
                  "\n Nickels     = " + nickels +
                  "\n Pennies     = " + pennies);
   }}}}
Chris Smith - 12 Sep 2004 21:12 GMT
> My program is not compiling properly, and I was hoping that someone
> would know how to fix the program (listed below).  The first part of
> the program compiles well (the conversion of the temperature) but the
> second part keeps giving me errors.

At the risk of being obvious, it would help to know what errors you are
getting.  Please don't assume that an error message that you don't
understand is equally useless to others.  You have neglected to provide
the most important piece of information that could be used to answer
your question.

That said, it appears that you haven't finished your main method before
you write other methods.  Your methods should appear one after the
other, such as:

class SomeClass
{
   public static void main(String[] args)
   {
       ...
   }

   private static someMethod()
   {
       ...
   }

   private static someOtherMethod()
   {
       ...
   }
}

Signature

www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Luca Paganelli - 13 Sep 2004 07:43 GMT
> // method #2
> //This method prompts user for input amount.
[quoted text clipped - 6 lines]
>    mone = Integer.parseInt (keyboard.readline());
>    ps.prinntln ("\nEnter an amount of money >" + money);

*****^^^^^^*****
ps.println ("\nEnter an amount of money >" + money);
- only one "n"!

>    return money;
>  }


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.