Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 22nd, 2017, 12:17 AM
Registered User
 
Join Date: May 2017
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trying to calculate GPA

Hi guy!
I want clone follow website https://gpahub.net/semester-grade-calculator
Here's what I need to be able to output:

Eligible
Ineligible, taking less than 4 classes
Ineligible, gpa below 2.0
Ineligible, gpa above 2.0 but has F grade (note: gpa >= 2.0)
Ineligible, gpa below 2.0 and has F grade
It keeps asking for input. How do I stop this? I tried converting grade into a char but that ended horribly for me. I think it might be a compiler error or something. Any help would be appreciated. Though helpful help would keep my blood pressure down.
here's my code so far:
import java.util.Scanner;

public class gpa {

public static void main(String[] args) {
double gpa=0;
double input = 0;
String grade= "";
int classes =0;
double fail =0;
do
{
System.out.print("Enter Grade (n to quit): ");
Scanner sc = new Scanner(System.in);
grade = sc.nextLine();
grade = grade.toLowerCase();
if (grade.equals("a"))
{
input = 4.0;
}
if (grade.equals("b"))
{
input = 3.0;
}
if (grade.equals("c"))
{
input = 2.0;
}
if (grade.equals("d"))
{
input = 1.0;
}
if (grade.equals("f"))
{
fail = 1;
}

gpa+=input;
classes++;
} while(grade!="n");
System.out.print("GPA: " + gpa + " ");

gpa/=classes;
if (gpa>=2 && classes >=4 && fail !=1)
{
System.out.print("Eligible");
}
else if(classes <4)
{
System.out.print("Ineligible. less than 4 classes");
}
else if (gpa < 2.0)
{
System.out.print("Ineligible. GPA is less than 2.0");
}
else if (gpa >=2.0 && fail == 1)
{
System.out.print("Ineligible. GPA is above 2.0, but has an F");
}
else if (gpa <2.0 && fail ==1)
{
System.out.print("Ineligible. GPA is below 2.0 and has F");
}
}

}
 
Old June 30th, 2017, 09:21 AM
Authorized User
 
Join Date: Mar 2012
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default Please forward your reply

Quote:
Originally Posted by avavida View Post
Hi guy!
I want clone follow website https://gpahub.net/semester-grade-calculator
Here's what I need to be able to output:

Eligible
Ineligible, taking less than 4 classes
Ineligible, gpa below 2.0
Ineligible, gpa above 2.0 but has F grade (note: gpa >= 2.0)
Ineligible, gpa below 2.0 and has F grade
It keeps asking for input. How do I stop this? I tried converting grade into a char but that ended horribly for me. I think it might be a compiler error or something. Any help would be appreciated. Though helpful help would keep my blood pressure down.
here's my code so far:
import java.util.Scanner;

public class gpa {

public static void main(String[] args) {
double gpa=0;
double input = 0;
String grade= "";
int classes =0;
double fail =0;
do
{
System.out.print("Enter Grade (n to quit): ");
Scanner sc = new Scanner(System.in);
grade = sc.nextLine();
grade = grade.toLowerCase();
if (grade.equals("a"))
{
input = 4.0;
}
if (grade.equals("b"))
{
input = 3.0;
}
if (grade.equals("c"))
{
input = 2.0;
}
if (grade.equals("d"))
{
input = 1.0;
}
if (grade.equals("f"))
{
fail = 1;
}

gpa+=input;
classes++;
} while(grade!="n");
System.out.print("GPA: " + gpa + " ");

gpa/=classes;
if (gpa>=2 && classes >=4 && fail !=1)
{
System.out.print("Eligible");
}
else if(classes <4)
{
System.out.print("Ineligible. less than 4 classes");
}
else if (gpa < 2.0)
{
System.out.print("Ineligible. GPA is less than 2.0");
}
else if (gpa >=2.0 && fail == 1)
{
System.out.print("Ineligible. GPA is above 2.0, but has an F");
}
else if (gpa <2.0 && fail ==1)
{
System.out.print("Ineligible. GPA is below 2.0 and has F");
}
}

}
Hi

Subsequent to modification and initialising in this way
please try this
if ok
Thanks
Code:
import java.util.Scanner;

public class gpa {

public static void main(String[] args) {
double gpa=0.0;
double input = 0.0;
String grade= "d";
int classes =4;
double fail =0.0;
do
{
System.out.print("Enter Grade (n to quit): ");
Scanner sc = new Scanner(System.in);
grade = sc.nextLine();
grade = grade.toLowerCase();
if (grade.equals("a"))
{
input = 4.0;
}
if (grade.equals("b"))
{
input = 3.0;
}
if (grade.equals("c"))
{
input = 2.0;
}
if (grade.equals("d"))
{
input = 1.0;
}
if (grade.equals("f"))
{
fail = 1;
}

gpa += input;

classes++;
} 
while(grade =="d");
System.out.print("GPA: " + gpa + " ");
gpa /= classes;
if (gpa>=2 && classes >=4 && fail !=1)
{
System.out.print("Eligible");
}
else if(classes <4)
{
System.out.print("Ineligible. less than 4 classes");
}
else if (gpa < 2.0)
{
System.out.print("Ineligible. GPA is less than 2.0");
}
else if (gpa >=2.0 && fail == 1)
{
System.out.print("Ineligible. GPA is above 2.0, but has an F");
}
else if (gpa <2.0 && fail ==1)
{
System.out.print("Ineligible. GPA is below 2.0 and has F");
}
}

}
As
muthukutta1





Similar Threads
Thread Thread Starter Forum Replies Last Post
GPA Calculator Final Method IsoftTech C# 2012/5.0 General Discussion 4 June 14th, 2018 05:40 AM
calculating gpa with only grades? avavida C# 2012/5.0 General Discussion 0 May 21st, 2017 11:39 AM
GPA Calculator xenoalien C# 1 November 30th, 2007 03:25 AM
Calculate ivangr Visual Basic 2005 Basics 0 April 9th, 2006 04:39 AM
Help me How to calculate minhtri VB How-To 4 June 8th, 2004 04:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.