Results 1 to 3 of 3
  1. #1
    javanewbie82 is offline Member
    Join Date
    Oct 2016
    Posts
    13
    Rep Power
    0

    Default Function issues with my code?

    I have a student record class which should output a student's final grade as a integer and as a letter. My code outputs nothing for the letter and 0.0 for the integer. What is wrong with my setter methods? I feel like I am making either a simple mistake or doing the entire assignment incorrectly...
    methods which determine final grade and letter grade:


    // code continues for each letter until F
    Java Code:
    public void setGradeLetter(char grades)
    	{
    		if (finalGrade >= 100)
    		{
    			this.grades = grades;
    			if (finalGrade >= 90)
    			{
    				grades = 'A';
    			}
    // and this is the calculate final grade code
    Java Code:
    public void calculateFinalGrade(double finalGrade)
    	{
    		
    	
    	finalGrade = ((quizScore * .25) + (midtermScore * .35) + (finalScore *.4));
    	  
    	}





    this is my class and after that is my driver class
    Java Code:
    public class Student_Record 
    {
    	private int quizScore, finalScore, midtermScore;
    	private char grades;
    	private double finalGrade;
    	public Student_Record()
    	{
    		quizScore = 0;
    		finalScore = 0;
    		midtermScore = 0;
    		grades = 0;
    		finalGrade = 0;
    	}
    	public Student_Record(int quizScore, int finalScore, int midtermScore, char grades, double finalGrade, boolean scoreLimits)
    	{
    	if (scoreLimits == true)
    	{
    		this.quizScore = quizScore;
    		this.midtermScore = midtermScore;
    		this.finalScore = finalScore;
    		this.grades = grades;
    		this.finalGrade = finalGrade;
    	}
    		setGradeLetter(grades);
    		calculateFinalGrade(finalGrade);
    	}
    	public boolean equals(Student_Record other)
    	{
    		return finalGrade == other.finalGrade;
    	}
    	public boolean scoreLimits()
    	{
    		return quizScore <= 30 && midtermScore <= 100 && finalScore <= 100;
    	}
    	
    		public int setquizScore()
    		{
    			if (quizScore <= 30)
    			{
    				this.quizScore = quizScore;
    			}
    			quizScore = 23;
    			return quizScore;
    		}
    		public int setFinalScore()
    		{
    			if (finalScore <= 100)
    			{
    				this.finalScore = finalScore;	
    			}
    			
    			return finalScore = 68;
    		}
    		public int setMidtermScore()
    		{
    			if (midtermScore <= 100)
    			{
    				this.midtermScore = midtermScore;
    								
    			}
    		 return midtermScore = 86;
    				
    		}
    	
    
    	public void calculateFinalGrade(double finalGrade)
    	{
    		
    	
    	finalGrade = ((quizScore * .25) + (midtermScore * .35) + (finalScore *.4));
    	  
    	}
    	public void setGradeLetter(char grades)
    	{
    		if (finalGrade >= 100)
    		{
    			this.grades = grades;
    			if (finalGrade >= 90)
    			{
    				grades = 'A';
    			}
    			else if (finalGrade < 90 && finalGrade >= 80)
    			{
    				grades = 'B';
    			}
    			else if (finalGrade < 80 && finalGrade >= 70)
    			{
    				grades = 'C';
    			}
    			else if (finalGrade < 70 && finalGrade >= 60)
    			{
    				grades = 'D';
    			}
    			else if (finalGrade < 60)
    			{
    				grades = 'F';
    			}
    			
    		}
    	
    	}
    	public int getQuiz()
    	{
    		return quizScore;
    	}
    	public int getMidterm()
    	{
    		return midtermScore;
    	}
    	public int getFinalScore()
    	{
    		return finalScore;
    	}
    	public double getFinalGrade()
    	{
    		return finalGrade;
    	}
    	public char getLetterGrade()
    	{
    		return grades;
    	}
    	
    }
    public class StudentRecordTest
     {
    	
    	public static void main (String[] args) 
    	{
    		Student_Record StudentRecord1;
    		StudentRecord1 = new Student_Record();
    		StudentRecord1.setMidtermScore();
    		StudentRecord1.setquizScore();
    		StudentRecord1.setFinalScore();
    		System.out.println("Quiz score: " + StudentRecord1.getQuiz() + "Midterm Score: " + StudentRecord1.getMidterm() + "Final score: " + StudentRecord1.getFinalScore());
    		System.out.println("Letter Grade: " + StudentRecord1.getLetterGrade()); 
    		System.out.println("Final Grade: " + StudentRecord1.getFinalGrade());
    		
    	}
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Function issues with my code?

    You haven't given the Student you create any values.
    You have used the no-argument constructor (the one with no parameters) so everything is set to 0, and at no point do you change them.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Function issues with my code?

    There is a problem with the if statement on line 75. It tests for finalGrade >= 100, and IN that if block, you test for finalGrade < 90. That won't happen at that point. It looks like that is suppoed to be an else-if.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Code continues on for a long time - Recursion Issues
    By Captain Forge in forum New To Java
    Replies: 1
    Last Post: 03-30-2013, 04:50 PM
  2. I am having issues to run this code ?
    By dantzig in forum New To Java
    Replies: 5
    Last Post: 06-24-2012, 01:53 AM
  3. Modular Inverse Function issues.
    By christopherx in forum Advanced Java
    Replies: 0
    Last Post: 10-28-2011, 08:36 PM
  4. having issues with this java code...please help out
    By oenhouse in forum New To Java
    Replies: 4
    Last Post: 12-20-2010, 01:21 PM
  5. Major issues with code - Please help
    By aldorfski_17 in forum New To Java
    Replies: 3
    Last Post: 03-29-2010, 04:46 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •