Java Primitives

import java.util.Scanner;

public class primitives {
    public static void main(String[] args) {
        // int is for integers
        int x = 7;
        System.out.println(x);
        // double is for numbers with decimals
        double pi = 3.14159265358979;
        System.out.println(pi);
        // boolean has two return values, which are usually true and false
        boolean y = true;
        System.out.println(y);
        // String is for text values
        String z = "Hello, World!";
        System.out.println(z);
        
        for (int a = 0; a < 5; a++) {
            Scanner userInput1 = new Scanner(System.in);
            System.out.println("Type your first integer:");
            int first = userInput1.nextInt();
            System.out.println("Type your second integer:");
            int second = userInput1.nextInt();

            Scanner userInput2 = new Scanner(System.in);
            System.out.println("Type the desired mathematical operator:");
            String operator = userInput2.nextLine();
            String operatorNew = operator.toLowerCase();

            if (operatorNew.equals("addition")) {
                int sum = first + second;
                System.out.println(first + " plus " + second + " equals " + sum);
            } else if (operatorNew.equals("subtraction")) {
                int difference = first - second;
                System.out.println(first + " subtracted by " + second + " equals " + difference);
            } else if (operatorNew.equals("multiplication")) {
                int product = first * second;
                System.out.println(first + " multiplied by " + second + " equals " + product);
            } else if (operatorNew.equals("division")) {
                double quotient = (double) first / (double) second;
                System.out.println(first + " divided by " + second + " equals " + quotient);
            } else if (operatorNew.equals("modulation")) {
                int modResult = first % second;
                System.out.println(first + " modulus " + second + " equals " + modResult);
            }
        }
    }
}
primitives.main(null);
7
3.14159265358979
true
Hello, World!
Type your first integer:
Type your second integer:
Type the desired mathematical operator:
7 plus 8 equals 15
Type your first integer:
Type your second integer:
Type the desired mathematical operator:
11 subtracted by 1 equals 10
Type your first integer:
Type your second integer:
Type the desired mathematical operator:
7 multiplied by 7 equals 49
Type your first integer:
Type your second integer:
Type the desired mathematical operator:
121 divided by 11 equals 11.0
Type your first integer:
Type your second integer:
Type the desired mathematical operator:
11 modulus 5 equals 1

Java Compound Operators

public class javaCompound {
    public static void main(String[] args) {
        // Initial Values
        int x = 7;
        int y = 8;
        double a = 3.14;
        double b = 6.28;
        
        // The compound operators modify values
        x += 7;
        y += 8;
        a *= 2;
        b /= 2;

        System.out.println(x);
        System.out.println(y);
        System.out.println(a);
        System.out.println(b);
    }
}
javaCompound.main(null);
14
16
6.28
3.14

GPA Calculator

import java.util.Scanner;

public class GPACalculator {
    public static void main(String[] args) {
        System.out.println("Trimester GPA Calculator");
        Scanner userInput = new Scanner(System.in);
        int sum = 0;
        System.out.println("Enter the number of classes this trimester or the most recent trimester with final grades:");
        int classes = userInput.nextInt();
        System.out.println(classes + " classes");
        System.out.println("Enter Class Grades:");
        for (int i = 0; i <= classes; i++) {
            int gpa = 0;
            String grade = userInput.nextLine();
            System.out.println(grade);
            if (grade.equals("A")) {
                gpa = 4;
            } else if (grade.equals("B")) {
                gpa = 3;
            } else if (grade.equals("C")) {
                gpa = 2;
            } else if (grade.equals("D")) {
                gpa = 1;
            } else if (grade.equals("F")) {
                gpa = 0;
            }
            sum = sum + gpa;
        }

        float gpaWhole = (float) sum/(float) classes;

        System.out.println("Your Overall GPA: " + gpaWhole);
    }
}

GPACalculator.main(null);
Trimester GPA Calculator
Enter the number of classes this trimester or the most recent trimester with final grades:
8 classes
Enter Class Grades:

A
A
B
A
A
B
A
A
Your Overall GPA: 3.75