Primitives Data Type Notes

Java is a data type language and all data is defined with explicit use. This can be in the form of primitive data types or non primitive data types (objects/wrapper classes).

Primitives

Primitives are fundemental data types in Java that solely hold certain data types and lack any methods. Among the most basic primitives there are:

  • Booleans (true or false values)
    • boolean
  • Characters (individual characters)
    • char
  • Integers (integer numbers and its representations)
    • int
    • byte
    • long
    • short
  • Floating-Points (decimals)
    • float
    • double

The most commonly used ones in java are boolean, char, int, and double.

Non-Primitives

Because Java likes everything to be a class, all data types, including forms of the primitives, are iterated as classes. The difference between primitives and non-primitives however is that non-primitves are able to perform method calls. Among some examples of Non-Primitives are:

  • String
  • ArrayList
  • any other object that may take the form of data

Applications

Below is a demonstration of the use of some primitives and a string in Java. (examples include int, double, boolean, and String)

public class Primitives {
  public static void main (String[] args) {
    int integer = 55; // This is an integer, this is a primitive data type which holds integer values
    double doub = 10.92; // This is a double, this is a primitive data type which holds decimal values 
    boolean bool = true; // This is a boolean, this is a primitive data type which holds the two values true or false
    String string = "This is a string"; // This is a String, this is a wrapper class data type which an array of characters

    System.out.println("This is an integer: " + integer); 
    System.out.println("This is an double: " + doub); 
    System.out.println("This is an bool: " + bool); 
    System.out.println("This is an string: " + string); 
  }
}

Primitives.main(null);
This is an integer: 55
This is an double: 10.92
This is an bool: true
This is an string: This is a string

Salary Raise Calculator

About This Calculator

This is a calculator that demonstrates implementations of boolean, int, double, and String within the code.

Do you ever struggle to calculate your salary raise or are just too lazy to plug those large numbers into a calculator? Then, welcome to a salary raise calculator where your only job is to input your old salary and the amount your salary has been raised by.

Not only does it calculate it for you it calcualate your new salary but also the manages the percent raise of your salary before informing you whether you've been scammed in your raise and that your employer is not appreciating you enough. I would encourage you to go on strike but unfortunately I'm a code code coder and not a strike strike striker so I don't have any advice for that. Good luck!

How It Works

A scanner is created to read the inputs of users and prompts users to enter double type inputs for the users salary and raise which is then used to calculate the new salary by adding the two values together. The percent increase is calculated by dividing the calculated new salary by the old salary and multiplied by 100 before being subtracted by 100. The in code comments go more in detail with what each line of code does.

Use of Primitives

Integers
  • Outputs percent increase as a raise

Doubles

  • Salaries are taken in as double values which does double division and casted as an integer output when calculating the percent

Boolean

  • Uses booleans to check if the output of the percent increase is good or not returning true for a percent value that is good

String

  • Outputs string message which includes all the values computed or collected above into a message that outputs new salary (double), precent increase (int), and quality of raise (boolean)

Contributions

This code was made in java in conjuction with fellow coder Nathan using pair programming.

import java.util.Scanner;

public class SalaryRaiseCalculator{
  public static void main(String[] args) {

      Scanner salaryInput = new Scanner(System.in);  // Create a Scanner object

      System.out.println("Enter a salary: "); // salary input message prompt
      double salary = salaryInput.nextDouble();  // Read user input
      double oldSalary = salary; // Records oldsalary for percent calculation later

      System.out.println("Enter your pay raise: "); // raise input message prompt
      double raise = salaryInput.nextDouble();  // Read user input

      salary += raise; // The inputted number of "raise" is added onto the original inputted "salary"

      int percent = (int) (100*(salary / oldSalary)-100); // Calculates percent raise

      salaryInput.close(); //Closes Scanner object salaryInput; stops reading text inputs

      boolean payraisequality;
      String message;

      if(percent > 5){
        payraisequality = true;
      }
      else{
        payraisequality = false;
      }

      if (payraisequality == true){
          message = "You got a good pay raise!";
      }
      else{
          message = "You got a bad pay raise!";
      }

      System.out.println("Your final salary is: " + salary + ", which is around a " + percent + "% raise from your original salary. " + message);  // Output user input
  }
}

SalaryRaiseCalculator.main(null);
Enter a salary: 
Enter your pay raise: 
Your final salary is: 1020000.0, which is around a 2% raise from your original salary. You got a bad pay raise!