9 Replies - 523 Views - Last Post: 10 October 2012 - 11:53 AM Rate Topic: -----

#1 DeadTheory23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 16-September 12

Grading program not computing final value?

Posted 07 October 2012 - 05:48 PM

Hi this program I'm working on asks the user to input their value out of 10 for 2 quiz grades, value out of 100 for a midterm, and value out of 100 for a final test, and then displays their percentages for those 4 categories. It is then supposed to calculate their overall course grade by weighing the quizzes (together) as 25%, the midterm as 25%, and the final as 50%. My program does all of that, except computing the final overall grade (It gives an output of 0.0%). What can I do to fix this? Any suggestions would be greatly appreciated!
note: the first code here is the one I run for the program, and it access the second to run and get values.
public class PA42
{
	public static void main(String[] args)
	{
		PA4 demo = new PA4();
		demo.readInput();
		demo.writeOutput();
	}
}


import java.util.*;

public class PA4
{
   
    private double quiz1, quiz2, midterm, cFinal, overallScore;
    private char letterGrade;
    	
    
    public void readInput()
    {
    	Scanner keys = new Scanner(System.in);
    	do
    	{
    		System.out.println("Enter Quiz 1 score from 1 to 10: ");
    		quiz1 = keys.nextInt();
    		if(quiz1 < 0 || quiz1 > 10)
    			System.out.println("Error. Invalid entry.");
    	}while(quiz1 < 0 || quiz1 > 10);
    	do
    	{
    		System.out.println("Enter Quiz 2 score from 1 to 10: ");
    		quiz2 = keys.nextInt();
    		if(quiz2 < 0 || quiz2 > 10)
    			System.out.println("Error. Invalid entry.");
    	}while(quiz2 < 0 || quiz2 > 10);
    	do
    	{
    		System.out.println("Enter Midterm score from 1 to 100: ");
    		midterm = keys.nextInt();
    		if(midterm < 0 || midterm > 100)
    			System.out.println("Error. Invalid entry.");
    	}while(midterm < 0 || midterm > 100);
    	do
    	{
    		System.out.println("Enter Final score from 1 to 100: ");
    		cFinal = keys.nextInt();
    		if(cFinal < 0 || cFinal > 100)
    			System.out.println("Error. Invalid entry.");
    	}while(cFinal < 0 || cFinal > 100);
    }
    public void setGrades(double newQuiz1, double newQuiz2, double newMidterm, double newCFinal)
    {
    	if (newQuiz1 >= 0)
    		quiz1 = newQuiz1;
    	else
    	{
    		System.out.println("Error. Invalid score.");
    		System.exit(0);
    	}
    	if (newQuiz2 >= 0)
    		quiz2 = newQuiz2;
    	else
    	{
    		System.out.println("Error. Invalid score.");
    		System.exit(0);
    	}
    	if (newMidterm >= 0)
    		midterm = newMidterm;
    	else
    	{
    		System.out.println("Error. Invalid score.");
    		System.exit(0);
    	}
    	if (newCFinal >= 0)
    		cFinal = newCFinal;
    	else
    	{
    		System.out.println("Error. Invalid score.");
    		System.exit(0);
    	}
    }
    public double getQuiz1()
    {
    	return quiz1;
    }
    public double getQuiz2()
    {
    	return quiz2;
    }
    public double getMidterm()
    {
    	return midterm;
    }
    public double getCFinal()
    {
    	return cFinal;
    }
   
    public void computeOverallScore()
    {
    	overallScore = 0.25*midterm + 0.5*cFinal + (quiz1 + quiz2)*1.25;
    }
    public void writeOutput()
    {
    	System.out.println("Quiz 1 score: " + quiz1*10.0 + " %.");
    	System.out.println("Quiz 2 score: " + quiz2*10.0 + " %.");
    	System.out.println("Midterm score: " + midterm + " %.");
    	System.out.println("Final score: " + cFinal + " %.");
    	System.out.println("Overall course score: " + overallScore + " %.");
    }
    
}


This post has been edited by jon.kiparsky: 07 October 2012 - 07:16 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Grading program not computing final value?

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2205
  • View blog
  • Posts: 5,239
  • Joined: 10-September 10

Re: Grading program not computing final value?

Posted 07 October 2012 - 06:00 PM

Where do you actually call the method to compute the overall score?
Was This Post Helpful? 1
  • +
  • -

#3 rfs02  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 26
  • View blog
  • Posts: 70
  • Joined: 30-September 12

Re: Grading program not computing final value?

Posted 07 October 2012 - 06:01 PM

Are you calling computeOverallScore anywhere in your code?
Was This Post Helpful? 1
  • +
  • -

#4 jdavi134  Icon User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 225
  • Joined: 26-October 11

Re: Grading program not computing final value?

Posted 07 October 2012 - 06:02 PM

Hint: Use the methods you have written.
Was This Post Helpful? 1
  • +
  • -

#5 DeadTheory23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 16-September 12

Re: Grading program not computing final value?

Posted 08 October 2012 - 09:10 PM

View Postrfs02, on 07 October 2012 - 06:01 PM, said:

Are you calling computeOverallScore anywhere in your code?

where and how do I call it?
Was This Post Helpful? 0
  • +
  • -

#6 Kinaces  Icon User is offline

  • D.I.C Head

Reputation: 78
  • View blog
  • Posts: 230
  • Joined: 04-October 12

Re: Grading program not computing final value?

Posted 08 October 2012 - 09:43 PM

View PostDeadTheory23, on 08 October 2012 - 09:10 PM, said:

View Postrfs02, on 07 October 2012 - 06:01 PM, said:

Are you calling computeOverallScore anywhere in your code?

where and how do I call it?


Did you write this code yourself or copy something else?
Was This Post Helpful? 0
  • +
  • -

#7 DeadTheory23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 16-September 12

Re: Grading program not computing final value?

Posted 08 October 2012 - 09:46 PM

View PostKinaces, on 08 October 2012 - 09:43 PM, said:

View PostDeadTheory23, on 08 October 2012 - 09:10 PM, said:

View Postrfs02, on 07 October 2012 - 06:01 PM, said:

Are you calling computeOverallScore anywhere in your code?

where and how do I call it?


Did you write this code yourself or copy something else?

I did do it myself. I have had my textbook open the whole time because I am still new to java. I'm just not totally 100% sure of everything I do yet.
Was This Post Helpful? 0
  • +
  • -

#8 Kinaces  Icon User is offline

  • D.I.C Head

Reputation: 78
  • View blog
  • Posts: 230
  • Joined: 04-October 12

Re: Grading program not computing final value?

Posted 08 October 2012 - 09:55 PM

What textbook are you using? Also you are making your own methods, and calling them throughout the program. I'm confused on why you ask how you call a method. Make sure you fully understand concepts in your book BEFORE moving on. If you need help explaining the concepts of methods and how to call them feel free to ask. I just rather not make a whole lesson on methods if your textbook already explains it.
Was This Post Helpful? 0
  • +
  • -

#9 asianhulk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-October 12

Re: Grading program not computing final value?

Posted 09 October 2012 - 10:59 PM

View PostKinaces, on 08 October 2012 - 09:55 PM, said:

What textbook are you using?

The book is probably Java: an introduction to problem solving and programming. Hope this helps him
Was This Post Helpful? 0
  • +
  • -

#10 DeadTheory23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 16-September 12

Re: Grading program not computing final value?

Posted 10 October 2012 - 11:53 AM

To everybody who commented on here - Thank you. This is all just a bit confusing for me as a newcomer. I appreciate your willingness to help and I will do my best to exhaust all other resources before putting my newbie questions up.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1