Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 26

Thread: Fixing this grade finder program?

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Fixing this grade finder program?

    Okay im creating a program for my beginning programming class, and its one we get to make for personal use as well, so mine is a grade program!

    In the loops i cant figure out how i can make it keep adding the stuff for example i run the program say there are 2 assignments first is worth 20 points second is worth 50 i cant figure out how to have it add them together and set my totalPoints as 70?

    Next after it runs all of this i want it to tell me what i need on the assignments not done yet for each grade letter for example 4 assignments worth 25 a piece i want lets say if i got 20 20 20 on the first 3 i want it to tell me i need 0 points on assignment 4 for a D 10 for a C 20 for a B and that its impossible to get an A

    Im just a little confused on what code i would need to do that and how i would have it do it for say multiple assignments, if i had 5 and had done 3 i want it to tell me the minimums on 4 and 5 without going over their maximum points, for example if 4 was worth 30 and 5 was worth 20 and i needed a total of 30 points i dont want it to say i need 30 on 4 and 0 on 5 i want it to say i need 15 each, and so on and so forth, im hoping this area doesnt get more complicated than i think it is in my head haha



    import java.util.Scanner;
     
     
    public class Prog5 {
     
    	public static void main(String args[])
    	{
    		int numberOfGrades;
    		int grades = 0;
    		int gradesDone = 0;
    		int completed;
    		int totalPoints = 0;
    		int points;
    		int pointsEarned;
     
     
     
     
     
    		Scanner input = new Scanner( System.in );
     
    		System.out.println("How many total grades will there be? ");
    		numberOfGrades = input.nextInt();
     
    		do            
    		{
    		 grades++;
     
    		System.out.println("Points possible for assignment " + grades + ":");
    		points = input.nextInt();
     
     
     
    		}while (grades < numberOfGrades);
     
    		totalPoints = points;
     
    		System.out.println("How many assignments completed?");
    		completed = input.nextInt();
     
     
     
     
     
    		do            
    		{
    		 gradesDone++;
     
    		System.out.println("Points recieved on assignment " + gradesDone + ":");
    		pointsEarned = input.nextInt();
     
     
     
    		}while (gradesDone < completed);
     
    		System.out.println(totalPoints);
    		System.out.println(pointsEarned);
     
     
    	}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Fixing this grade finder program?

    Look at using an array to hold the grades that are read in. After reading all the grades, you will be able to use a loop to scan through the array and add them.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fixing this grade finder program?

    Quote Originally Posted by Norm View Post
    Look at using an array to hold the grades that are read in. After reading all the grades, you will be able to use a loop scan through the array and add them.
    I had thought about arrays, but we never went to in depth in them besides literally just making one, and not sure what a loop scan is? sorry for my noobness! ill check the book see if i can figure out how to incorporate an array here

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Fixing this grade finder program?

    what a loop scan is
    I left out the word "to": use a loop to scan through the array.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fixing this grade finder program?

    Quote Originally Posted by Norm View Post
    I left out the word "to": use a loop to scan through the array.
    So i know i would have to declare the array, then for length i would have to set it = the first integer input which is how many grades are there, How would i set the array then to be the numbers put in through that loop?

    int [] grades = new int [numberOfGrades]; Correct for declaring?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Fixing this grade finder program?

    Correct for declaring?
    Have you passed that to the compiler? It will tell you if there are problems. I could miss something that the compiler wouldn't.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Nov 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fixing this grade finder program?

    Quote Originally Posted by Norm View Post
    Have you passed that to the compiler? It will tell you if there are problems. I could miss something that the compiler wouldn't.
    Well true, yes it doesnt have any errors, (using eclipse) but im not sure what i need to change up in that first loop to have it set the array to each of the numbers that i put in?

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Fixing this grade finder program?

    You assign the value read in to a slot in the array at an index:
    anArray[theIdx] = theValue;
    then you increment the index so the next time the value will go into the next slot.
    In a for loop, the for statement variable can be the index.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Nov 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fixing this grade finder program?

    Quote Originally Posted by Norm View Post
    You assign the value read in to a slot in the array at an index:
    anArray[theIdx] = theValue;
    then you increment the index so the next time the value will go into the next slot.
    In a for loop, the for statement variable can be the index.
    haha okay so as im understanding this which isnt very well this is the bit of code i have come up with

    for (grade < grades.length; grade++ )
    				totalPoints += grades [grade ];

    But putting it in the while loop it wants me to create a class called grade (i have grade declared to = 0 )

    what am i missing? this is turning into way more than i thought haha i didnt feel the array would be this complicated (to me at least)

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Fixing this grade finder program?

    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Nov 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fixing this grade finder program?

    Quote Originally Posted by Norm View Post
    that was my bad on the loop i know for loops lol i just was taking something out of the book and left some stuff out, okay here is my first bit of code as of yet, when i run it and say i do 5 assignments and i put in 10 points for each assignment it says that = 60... can you tell what ive put in wrong for it to be adding it again??


    import java.util.Scanner;
     
     
    public class Prog5 {
     
    	public static void main(String args[])
    	{
    		int numberOfGrades;
    		int grade = 0; 
    		int gradesDone = 0;
    		int completed;
    		int totalPoints = 0;
    		int points;
    		int pointsEarned;
     
     
     
     
     
    		Scanner input = new Scanner( System.in );
     
    		System.out.println("How many total grades will there be? ");
    		numberOfGrades = input.nextInt();
     
    		int [] grades = new int [numberOfGrades+1];
     
    		do            
    		{
     
    		grade++;
    		System.out.println("Points possible for assignment " + grade + ":");
    		grades[grade] = input.nextInt();
     
     
     
    		}while (grade < numberOfGrades);
     
    		for (int counter = 0; counter < grades.length; counter++ )
    			totalPoints += grades [grade]; 
     
    		System.out.println(totalPoints);
     
    }
    }

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Fixing this grade finder program?

    Print out the contents of the array so you can see what you are adding up. Use the Arrays class's toString method to format the array for printing:
    System.out.println("an ID "+ java.util.Arrays.toString(theArrayName));
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Nov 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fixing this grade finder program?

    Quote Originally Posted by Norm View Post
    Print out the contents of the array so you can see what you are adding up. Use the Arrays class's toString method to format the array for printing:
    System.out.println("an ID "+ java.util.Arrays.toString(theArrayName));
    its doing everything like i want its setting the first array number to 0 then from there on out is right, its just adding them up very very weirdly?

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Fixing this grade finder program?

    Did you add the numbers that were printed out? Was the sum different from what the code computed?
    Double check the loop and the index used for the array.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Nov 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fixing this grade finder program?

    Okay idk why it would do it but by changing counter =0 to =1 its doing it right now. So now on to the next task, im assuming my best bet is to set a second array the same way for the second loop for how many points i got on each assignment, so what is it that i will need to do after that to make my program figure out the points i need for each of the letter grades? im really not even sure where to start like i dont know what way i need to go about making A = 89.5-100 % of the points where i take the total points/ points ive gotten but printing out the points i need on the last assignments?


    thats probably confusing lol its got me confused as well just looking for some tips, thank you, youve helped quite a bit already!

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Fixing this grade finder program?

    I'm done for tonight. Back tomorrow.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Nov 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fixing this grade finder program?

    Quote Originally Posted by Norm View Post
    I'm done for tonight. Back tomorrow.
    alright thanks man! just messed up again tried different numbers and its still adding them up all weird.

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Fixing this grade finder program?

    For testing reduce the size of the array to 3 and enter 3 different numbers like 1 22 55
    then look at what the program prints out and see if there is something that stands out.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Junior Member
    Join Date
    Nov 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fixing this grade finder program?

    Quote Originally Posted by Norm View Post
    For testing reduce the size of the array to 3 and enter 3 different numbers like 1 22 55
    then look at what the program prints out and see if there is something that stands out.
    I actually got it working last night, i wasnt putting the counter in the places it needed to be! so here is my code working perfect up till this point, now just to figure out how to approach the next step, any tips?

    import java.util.Scanner;
     
     
    public class Prog5 {
     
    	public static void main(String args[])
    	{
    		int numberOfGrades;
    		int grade = 0; 
    		int gradesDone = 0;
    		int completed;
    		int totalPoints = 0;
    		int points;
    		int pointsEarned = 0;
     
     
     
     
     
    		Scanner input = new Scanner( System.in );
     
    		System.out.println("How many total grades will there be? ");
    		numberOfGrades = input.nextInt();
     
    		int [] grades = new int [numberOfGrades+1];
     
    		do            
    		{
     
    		grade++;
    		System.out.println("Points possible for assignment " + grade + ":");
    		grades[grade] = input.nextInt();
     
     
     
    		}while (grade < numberOfGrades);
     
     
    		for ( int counter=1; counter < grades.length; counter++ )
    			totalPoints += grades[counter]; 
     
     
     
    		System.out.println("an ID "+ java.util.Arrays.toString(grades));
     
    		System.out.println(totalPoints);
     
    		System.out.println("How many assignments completed?");
    		completed = input.nextInt();
     
     
    		int [] completedArray = new int [completed+1];
     
     
     
    		do            
    		{
    		 gradesDone++;
     
    		System.out.println("Points recieved on assignment " + gradesDone + ":");
    		completedArray[gradesDone] = input.nextInt();
     
     
     
    		}while (gradesDone < completed);
     
    		for ( int counter=1; counter < completedArray.length; counter++ )
    			pointsEarned += completedArray[counter]; 
     
    		System.out.println(totalPoints);
    		System.out.println(pointsEarned);
     
     
    	}
    }

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Fixing this grade finder program?

    how to approach the next step
    Sorry, I don't know what the next step is. Can you explain?
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Junior Member
    Join Date
    Nov 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fixing this grade finder program?

    Quote Originally Posted by Norm View Post
    Sorry, I don't know what the next step is. Can you explain?
    Sure, ill try and make it a little clearer basically after the input of the grades, i want it to then output saying what i need on the final grade and or grades at a minimum for each letter grade! For example lets say i had 4 total grades, each worth 25 points a piece and i got perfect on the first 2 and have 2 left! I want it to output saying for an A i need 20 on Assignment 3 and 20 on Assignment 4 For a B i need 15 on each then for a C 10 on each and D 5 on each, however i need to have stuff in there that spreads the points out like such and doesn't say 25 on one and 15 on one i want it spread as evenly as it can be, also if i had one assignment worth 5 and another worth 20 i dont want it to be like i need 10 and 10 when 5 is the max!

    If that makes sense which i hope it does!

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Fixing this grade finder program?

    Looks like you need to work on some logic for this part.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Junior Member
    Join Date
    Nov 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fixing this grade finder program?

    Well yeah, thats where im a little stumped i mean i have a formula to find how many grades are left, and how many points are left, but thats where im at i know the next thing i need to do is somehow make it where it adds points to each of the remaining grades without going over their maximum (id even be okay with if it added till the max on each one until it got to the point) until when you divide points earned + points added / total possible points is greater than or equal to .895 for an A that would at least get me started im just not sure what code i would put in to do that?

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Fixing this grade finder program?

    im just not sure what code
    Work on the steps to solve the problem first. When you have worked out the logic, THEN work on coding it.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #25
    Junior Member
    Join Date
    Nov 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Fixing this grade finder program?

    Quote Originally Posted by Norm View Post
    Work on the steps to solve the problem first. When you have worked out the logic, THEN work on coding it.
    Well i have the formulas for like i said the remaining grades, and remaining points!

    lets say there are 4 assignments, done two 25 each and got 25 on each the last 2 are worth 25 each as well, My next bit needs to add onto the 3rd assignment and everytime it adds a point check the points earned/total points to verify it hasnt reached 89.5% yet and once it hits the max of that grade it then needs to move to assignment 4 and do the same thing until it reaches 89.5 when it does it will need to print

    If thats what you mean by the logic im still fairly new at all this and some of it is just coming hard to me, like i understand what i need to do im just needing to figure out the direction in which i need to go for it

Page 1 of 2 12 LastLast

Similar Threads

  1. Problem with my prime number finder program
    By Truck35 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 6th, 2012, 11:25 PM
  2. Help fixing my first program
    By javadude in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 9th, 2012, 06:52 PM
  3. Need simple JAVA program fixing ASAP
    By theviper in forum Paid Java Projects
    Replies: 1
    Last Post: April 14th, 2010, 10:59 AM
  4. help with the logic on this letter grade program.
    By etidd in forum Loops & Control Statements
    Replies: 2
    Last Post: January 28th, 2010, 09:14 PM
  5. Grade averaging program with array and multiple methods.
    By jeremykatz in forum What's Wrong With My Code?
    Replies: 8
    Last Post: November 9th, 2009, 09:44 PM