I need to edit this code to add these classes the code is a GPA calculater that
ID: 3666756 • Letter: I
Question
I need to edit this code to add these classes
the code is a GPA calculater that get the credit,cource id and point from the user then calculate the the total points and total credit then calculate the GPA
import java.util.Scanner;
public class StudentGPA {
public static void main (String args[]){
String point = "";
double C1;
double C2;
double C3;
int ID1;
int ID2;
int ID3;
double pointValue=0;
double P1=0;
double P2=0;
double P3=0;
double totPts=0;
double totalCredits= 0;
double gpa;
Scanner console = new Scanner (System.in);
System.out.println("Please enter the course ID number for course 1");
ID1= console.nextInt();
System.out.println("Please enter the number of credits of course 1");
C1 = console.nextDouble();
System.out.println("Please enter your grades for course 1(Capital letters such as A,B+, C)");
point = console.next();
if (point.equals ("A+"))
pointValue= 4.00;
else if (point.equals("A"))
pointValue = 3.75;
else if (point.equals("B+"))
pointValue = 3.50;
else if (point.equals("B"))
pointValue = 3.00;
else if (point.equals("C+"))
pointValue = 2.50;
else if (point.equals("C"))
pointValue = 2.00;
else if (point.equals ("D+"))
pointValue = 1.50;
else if (point.equals ("D"))
pointValue = 1.00;
else if (point.equals ("F"))
pointValue = 0;
else
System.out.println ("Invalid Grade");
P1 = pointValue * C1;
System.out.println("Please enter the course ID number for course 2");
ID2= console.nextInt();
System.out.println("Please enter the number of credits of course 2");
C2 = console.nextDouble();
System.out.println("Please enter your grades for course 2 (Capital letters such as A,B+, C)");
point = console.next();
if (point.equals ("A+"))
pointValue= 4.00;
else if (point.equals("A"))
pointValue= 3.75;
else if (point.equals("B+"))
pointValue = 3.50;
else if (point.equals("B"))
pointValue = 3.00;
else if (point.equals("C+"))
pointValue = 2.50;
else if (point.equals("C"))
pointValue = 2.00;
else if (point.equals ("D+"))
pointValue = 1.50;
else if (point.equals ("D"))
pointValue = 1.00;
else if (point.equals ("F"))
pointValue = 0;
else
System.out.println ("Invalid Grade");
P2 = pointValue * C2;
System.out.println("Please enter the course ID number for course 3");
ID3= console.nextInt();
System.out.println("Please enter the number of credits of course 3");
C3 = console.nextDouble();
System.out.println("Please enter your grades for course 3 (Capital letters such as A,B+, C)");
point = console.next();
if (point.equals ("A+"))
pointValue = 4.00;
else if (point.equals("A"))
pointValue = 3.75;
else if (point.equals("B+"))
pointValue = 3.50;
else if (point.equals("B"))
pointValue = 3.00;
else if (point.equals("C+"))
pointValue = 2.50;
else if (point.equals("C"))
pointValue = 2.00;
else if (point.equals ("D+"))
pointValue = 1.50;
else if (point.equals ("D"))
pointValue = 1.00;
else if (point.equals ("F"))
pointValue = 0;
else
System.out.println ("Invalid Grade");
P3 = pointValue * C3;
totPts= P1+P2+P3;
totalCredits = C1+C2+C3;
gpa= totPts / totalCredits;
System.out.printf("Your GPA is: %.2f ", + gpa);
}
}
Cource GPA Calculator -credit : double -ID: int -point: double +getcredito : double +getpointO : double +totalcredit0 nts GPAO:double) +getiDO: int .getlExplanation / Answer
Answer -
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
class GPACalculator extends Course
{
double totalpoints(double TP)
{
double tpt=0;
tpt=tpt+TP;
return tpt;
}
double totalcredit(double TC)
{
double tct=0;
tct = tct+TC;
return tct;
}
double GPA(double totP, double totC)
{
double gpa= totP / totC;
return gpa;
}
public static void main (String args[])
{
GPACalculator g=new GPACalculator();
double[] C2=new double[4];
double[] P2=new double[4];
int[] ID2 = new int[4];
double pointValue=0,totPts=0,totalCredits=0;
for(int i=1;i<4;i++)
{
ID2[i]=g.getID(i);
C2[i]=g.getCredit(i);
pointValue=g.getPoint(i);
P2[i] = pointValue * C2[i];
}
for(int i=1;i<4;i++)
{
totPts=totPts+g.totalpoints(P2[i]);
totalCredits=totalCredits+g.totalcredit(C2[i]);
}
System.out.printf("Your GPA is: %.2f ", +g.GPA(totPts,totalCredits));
}
}
class Course
{
double C;
double P=0;
int id;
String point;
double getCredit(int i)
{
Scanner console = new Scanner (System.in);
System.out.println("enter the number of credits of course "+i+" :");
C= console.nextDouble();
return C;
}
double getPoint(int i)
{
Scanner console = new Scanner (System.in);
System.out.println("enter your grades for course "+i+" (Capital letters such as A+/A/B+/B/C+/C/D+/D/F) :");
point = console.next();
if (point.equals ("A+"))
P= 4.00;
else if (point.equals("A"))
P = 3.75;
else if (point.equals("B+"))
P = 3.50;
else if (point.equals("B"))
P = 3.00;
else if (point.equals("C+"))
P = 2.50;
else if (point.equals("C"))
P = 2.00;
else if (point.equals ("D+"))
P = 1.50;
else if (point.equals ("D"))
P = 1.00;
else if (point.equals ("F"))
P = 0;
else
System.out.println ("Invalid Grade");
return P;
}
int getID(int i)
{
Scanner console = new Scanner (System.in);
System.out.println("enter the course ID number for course "+i+" :");
id= console.nextInt();
return id;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.