Unstoppable Domains

Very quick java help

Spaceship Spaceship
Watch

Hayes

Expert DeveloperEstablished Member
Impact
16
Can someone please tell me why this will not work? It compiles but always determines the GPA to be 0.0. Thank you kindly. Rep to whoever can hlep :)

PHP:
// Program:		GPACalculator.java
// Author:		Rob Hayes
// Date:		Oct. 4, 2007
// Description:	Calculate your Grade Point Average for the first semester.

import java.util.Scanner;		//Scanner class

class GPACalculator
{
	public static void main (String[] args)
	{		
		// Display a  title
		System.out.println();	// print a blank line
		System.out.println("Calculates the Grade Point Average of a Student");
		System.out.println("-----------------------------------------------");
		System.out.println();	// print a blank line
		
		// Create a Scanner object for user input
		Scanner input = new Scanner(System.in);
		
		// Read-in the user's grade points
		System.out.print("Enter the grade point for INFO 1136: ");
		double gp1 = input.nextDouble();
		
		System.out.print("Enter the grade point for INFO 1135: ");
		double gp2 = input.nextDouble();
		
		System.out.print("Enter the grade point for INFO 1119: ");
		double gp3 = input.nextDouble();
		
		System.out.print("Enter the grade point for INFO 1120: ");
		double gp4 = input.nextDouble();
		
		System.out.print("Enter the grade point for BUSI 1005: ");
		double gp5 = input.nextDouble();
		
		System.out.print("Enter the grade point for BUSI 1060: ");
		double gp6 = input.nextDouble();
		
		// Determine the weighted grade point taking into consideration the amount of credits per course
		double wGP1 = gp1 * (5 / 20);
		double wGP2 = gp2 * (5 / 20);
		double wGP3 = gp3 * (3 / 20);
		double wGP4 = gp4 * (3 / 20);
		double wGP5 = gp5 * (3 / 20);
		double wGP6 = gp6 * (1 / 20);
		
		//  Determine the GPA by adding up the weighted grade points
		double GPA = (wGP1 + wGP2 + wGP3 + wGP4 + wGP5 + wGP6);
		
		System.out.print("Your GPA = " + GPA + " for 20 credit units");
	}
}
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
That should work.
Code:
// Program:		GPACalculator.java
// Author:		Rob Hayes
// Date:		Oct. 4, 2007
// Description:	Calculate your Grade Point Average for the first semester.

import java.util.Scanner;		//Scanner class

class GPACalculator
{
	public static void main (String[] args)
	{		
		// Display a  title
		System.out.println();	// print a blank line
		System.out.println("Calculates the Grade Point Average of a Student");
		System.out.println("-----------------------------------------------");
		System.out.println();	// print a blank line
		
		// Create a Scanner object for user input
		Scanner input = new Scanner(System.in);
		
		// Read-in the user's grade points
		System.out.print("Enter the grade point for INFO 1136: ");
		double gp1 = input.nextDouble();
		
		System.out.print("Enter the grade point for INFO 1135: ");
		double gp2 = input.nextDouble();
		
		System.out.print("Enter the grade point for INFO 1119: ");
		double gp3 = input.nextDouble();
		
		System.out.print("Enter the grade point for INFO 1120: ");
		double gp4 = input.nextDouble();
		
		System.out.print("Enter the grade point for BUSI 1005: ");
		double gp5 = input.nextDouble();
		
		System.out.print("Enter the grade point for BUSI 1060: ");
		double gp6 = input.nextDouble();
		
		// Determine the weighted grade point taking into consideration the amount of credits per course
		double wGP1 = gp1 * 5 / 20;
		double wGP2 = gp2 * 5 / 20;
		double wGP3 = gp3 * 3 / 20;
		double wGP4 = gp4 * 3 / 20;
		double wGP5 = gp5 * 3 / 20;
		double wGP6 = gp6 * 1 / 20;
		
		//  Determine the GPA by adding up the weighted grade points
		double GPA = (wGP1 + wGP2 + wGP3 + wGP4 + wGP5 + wGP6);
		
		System.out.print("Your GPA = " + GPA + " for 20 credit units");
	}
}
 
Last edited:
0
•••
Have you put debbugging statements in to confirm that the values you've read in from user input are not somehow being interpreted as 0?
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back