Read with Formatting | Join TechSpot! (it's free) | Bookmark / Share this



Help with java homework....

Rick Alvernaz
11-13-2007, 11:02 PM
Can someone please look at this, I'm sure I'm just missing something really easy. Something is wrong with my Method. I'm brand new to java, so don't laugh.

I realize you can't see everything...put maybe someone can spot the problem real quick.


public class SpacelySprockets
{

public static void main(String[] args) //Main Program
{ //Start Main


int partNumber=0;
int quantity=0;
int part1Total=0;
int part2Total=0;
int part3Total=0;
int part4Total=0;
int part5Total=0;

Keyboard kbd;
kbd = new Keyboard ();

InputFile sprockets;
sprockets = new InputFile ("E:\\MaxSync\\School\\SLCC\\CIS 1030\\Spacely Sprockets\\sprockets.txt");

while (!sprockets.eof())
{ //Start Loop

partNumber=sprockets.readInt ();
quantity=sprockets.readInt ();


switch (partNumber)
{
case 1: part1Total = part1Total + quantity;
break;
case 2: part2Total = part2Total + quantity;
break;
case 3: part3Total = part3Total + quantity;
break;
case 4: part4Total = part4Total + quantity;
break;
case 5: part5Total = part5Total + quantity;
break;
default: System.out.println ("The file has unknown part numbers ltstd");
}


} //End Loop

detailLine (part1Total, 1);
detailLine (part2Total, 2);
detailLine (part3Total, 3);
detailLine (part4Total, 4);
detailLine (part5Total, 5);


} //End Main

public static void detailLine (int partTotal, int partNumber);
{
OutputFile summaryReport;
summaryReport = new OutputFile ("E:\\MaxSync\\School\\SLCC\\CIS 1030\\Spacely Sprockets\\summaryReport.txt");

summaryReport.writeWord (partTotal, partNumber);
summaryReport.writeEOL();
summaryReport.close();

}


} //End Class

Nodsu
11-14-2007, 04:43 AM
What exactly is wrong?

It is very hard to read code written by someone else. Tell us what it is supposed to do and what really happens.

Ad
11-14-2007, 04:43 AM

Rick Alvernaz
11-14-2007, 05:21 PM
Sorry, I should have given more information.

The program is supposed to read a text file that contains information like below....

1 99
2 88
3 77
4 66
5 55
1 10
2 35
5 50
3 60

It supposed to add up the numbers on the right, corresponding with the numbers on the left and right that information to a file. For example there are 105 "5"s and 123 "2"s.

So the new file should look like this

1 109
2 123
3 137
4 66
5 105

However,

When I compile my program...I get this error.


E:\MaxSync\School\SLCC\CIS 1030\Spacely Sprockets\SpacelySprockets.java:56: missing method body, or declare abstract
public static void detailLine (int partTotal, int partNumber);
^
E:\MaxSync\School\SLCC\CIS 1030\Spacely Sprockets\SpacelySprockets.java:61: cannot find symbol
symbol : variable partTotal
location: class SpacelySprockets
summaryReport.writeWord (partTotal, partNumber);
^
E:\MaxSync\School\SLCC\CIS 1030\Spacely Sprockets\SpacelySprockets.java:61: cannot find symbol
symbol : variable partNumber
location: class SpacelySprockets
summaryReport.writeWord (partTotal, partNumber);
^
3 errors

Tool completed with exit code 1

I've also tried using writeWord, writeInt, and writeString.

Nodsu
11-15-2007, 04:58 AM
Remove the semicolon from the end of line 56 (public static void detailLine...).

You seem to be using some course-specific classes (Keyboard, InputFile, OutputFile), so I can't verify the correctness of the program..

Rick Alvernaz
11-15-2007, 12:49 PM
wow, I feel stupid. I can't believe I spent so much time over one semicolon. I knew it would be something simple.

I got the programing running now. Thanks for your help.

 Top Technology News

 Software Downloads

Copyright © 1998-2008 TechSpot.com. TechSpot is a registered trademark. All Rights Reserved.