Help on finding the error in my homework assignment

Help on finding the error in my homework assignment

Post by byasam » Tue, 14 Sep 2004 05:06:22


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);
}}}}
 
 
 

Help on finding the error in my homework assignment

Post by Chris Smit » Tue, 14 Sep 2004 05:12:47


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()
{
...
}
}

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

 
 
 

Help on finding the error in my homework assignment

Post by Luca Pagan » Tue, 14 Sep 2004 15:43:35


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