Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-03-2009, 08:06 PM
Member
 
Join Date: Feb 2009
Posts: 19
Rep Power: 0
maxpower1000sa is on a distinguished road
Default Errors with simple program... PLEASE HELP ME!!!
I am supposed to be writing this program and this is what I have so far...

import java.io.*;
import java.util.*;

public class assignment
{
public static void main(String[] args) throws FileNotFoundException
{
double quiz1, quiz2, quiz3, quiz4;
double average;
String firstName;
String lastName;

Scanner inFile =
new Scanner(system.n);

PrintWriter outFile = new
PrintWriter("testavg.out");

firstName = inFile.next();
lastName = inFile.next();

outFile.println("Student Name: "
+ firstName + " " + lastName);

quiz1 = inFile.nextDouble();
quiz2 = inFile.nextDouble();
quiz3 = inFile.nextDouble();
quiz4 = inFile.nextDouble();

average = (quiz1 + quiz2 + quiz3 + quiz4) / 4.0;
outFile.printf("Average quiz score: %5.2f %n",
average);

if (average>=90)System.out.println("A");
else if (average>=80)System.out.print("B");
else if (average>=70)System.out.print("C");
else if (average>=60)System.out.print("D");
else if (average<=50)System.out.print("F");
inFile.close();
outFile.close();
}
}

WHAT I NEED TO DO IS WRITE IT SO THAT THE USER INPUTS A NUMBER OF QUIZES AND IT FINDS THE AVERAGE. AND I CAN NOT FIX THE ERRORS. IE. THE SCANNER ERROR

PLEASE HELP ME!!!!
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 05-03-2009, 09:06 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,466
Rep Power: 8
Fubarable is on a distinguished road
Default
Hello. You will likely find that the more relevant information you tell us, the more we'll be able to help you. For instance, if you have a compile error(s), should post the error message(s) here with your question to better let us know just exactly what is going wrong.

Also, you have to be extremely careful with spelling and capitalization when coding in Java.

for instance, here:
Code:
Scanner inFile =
new Scanner(system.n);
System.in is not the same as system.n

Best of luck.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-03-2009, 09:09 PM
Member
 
Join Date: Feb 2009
Posts: 19
Rep Power: 0
maxpower1000sa is on a distinguished road
Default help... again
I am wondering if you know how to input an amount of quizzes instead of it having a default amount of quizzes set?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-03-2009, 09:25 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,466
Rep Power: 8
Fubarable is on a distinguished road
Default
You can always get the number of quizzes from the user via your Scanner object, and then use that int to initiate your int array, when you call
int[] intArray = new int[the number goes here]
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-03-2009, 09:26 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,466
Rep Power: 8
Fubarable is on a distinguished road
Default
edit: this is not an Applet question. I'm going to move this to the New to Java section
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-04-2009, 12:42 AM
Member
 
Join Date: Feb 2009
Posts: 19
Rep Power: 0
maxpower1000sa is on a distinguished road
Default Alright so I tried this... but
Alright so I tried what you said and no way I can think of does it work... if you would not mind helping me...

.....
int Scnanner (System.in) intArray = new int[];

//Step 6 - retrieve the five test scores
quiz1 = inFile.nextDouble();
quiz2 = inFile.nextDouble();
quiz3 = inFile.nextDouble();
quiz4 = inFile.nextDouble();

outFile.printf("Quiz scores: %5.2f %5.2f %5.2f "
+ "%5.2f %n", quiz1, quiz2,
quiz3, quiz4);

average = (quiz1 + quiz2 + quiz3 + quiz4) / new int[]; //Step 8
outFile.printf("Average quiz score: %5.2f %n",
average);
if (average>=90)System.out.println("A");
.....

Here are the errors:

/export/home/students/jgiannin/exampleStudentGrade.java:30: ';' expected
int Scnanner System.in intArray = new int[];
^
/export/home/students/jgiannin/exampleStudentGrade.java:42: array dimension missing
average = (quiz1 + quiz2 + quiz3 + quiz4) / new int[];
^
2 errors

----jGRASP wedge: exit code for process is 1.
----jGRASP: operation complete.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-04-2009, 12:55 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,466
Rep Power: 8
Fubarable is on a distinguished road
Default
This is wrong:
Code:
int Scnanner (System.in) intArray = new int[];
Don't try to combine your Scanner object and your int array as they are two completely different animals. Create your scanner with a correctly spelled System.in object as I mentioned above,
Code:
Scanner scanner = new Scanner(System.in);
then use that Scanner object to get a number from the user, just as you're currently using it to get your quiz scores. Then you use that int obtained to initialize the array, just as you'd initialize any array. Correction though, if your quiz scores are doubles (are you sure that they're doubles? int would make more sense), then you'll want an array of double.

Last edited by Fubarable; 05-04-2009 at 02:45 AM.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] hello, java program with 2 errors, help einstein1234 New To Java 24 04-10-2009 09:50 AM
Errors in Program (Right Triangle) SupaStudy New To Java 3 03-26-2009 11:42 AM
Debuggin help - simple program non-static method errors RR_QQ New To Java 5 02-04-2009 02:20 AM
Help with Errors in Inventory Program ljk8950 AWT / Swing 3 08-09-2008 12:49 AM
3 errors and then terminate program hezfast2 New To Java 2 05-20-2008 02:57 AM


All times are GMT +2. The time now is 06:35 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org