File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

newbie question

ryan cheeseman
Greenhorn

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

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

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

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.
Scott.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: newbie question
 
Similar Threads
Need help creating classes
TestScores
Test score
TestScores
[HOMEWORK] Please need help with java project