Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

newbie question

 
ryan cheeseman
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic