File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes newbie question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "newbie question" Watch "newbie question" New topic

newbie question

ryan cheeseman

Joined: Feb 03, 2004
Posts: 1
heres what i have
import cs1.Keyboard;
public class Final
public static void main(String[]args)
int num1 = 3;
int num2 = 5;
int min = 0;
System.out.println("You will now enter 3 test grades,\nthen 5 quiz grades\nthen the students average will be outputed:");
int test = 0;
while (num1!=min)
System.out.println("Please enter a test grades:");
test = Keyboard.readInt();
if ((test<0) || (test>100))
System.out.println("Please input a valid grade (greater than 0)");
if ((test>0) && (test<100))

int quiz = 0;
while (num2!=min)
System.out.println("Please enter a quiz grades:");
quiz = Keyboard.readInt();
if ((quiz<0) || (quiz>100))
System.out.println("Please input a valid grade (greater than 0)");
if ((quiz>0) && (quiz<100))

float tg = (test + test + test)/3;/*here i want to get the 3 test scores collected and divide them by 3 to get the i need to read them into a array, and if so how would i do this*/
thanks for any help
Scott Stoddard

Joined: Jan 30, 2004
Posts: 5
Ryan...good to see yet another person learning Java.
It would seem that there is a simpler solution than arrays. This is because in your test and quiz mark entry sections you already have an 'if' structure to determine if the mark entered is a valid mark.

How about - in the section where you are decrementing num2 - you have something like
...assuming of course that you define quiztotal above this. Then, at the end, you would just need to divide quiztotal by 5. Of course the same could easily be done for 'test'.
By the way, the way that your code is currently written, a person could not have either a mark of 0 or a mark of 100 on a test or a quiz.
I agree. Here's the link:
subject: newbie question
It's not a secret anymore!