Wednesday, April 8, 2026
//NetIncome.java

// A program to calculate one's net income - UK

class NetIncome {
  public int grossIncome, taxableIncome, basicIncome, higherIncome, additionalIncome;
  public int personalAllowance = 12500;
  public double basic = 0.20;
  public double higher = 0.40;
  public double additional = 0.45;

  public int getAllowance(int grossIncome) {
    return grossIncome - personalAllowance;
  }

  public String minimumWage() {
    return String.format("Your net income is %d", grossIncome);
  }

  public String getBasic() {
    taxableIncome = getAllowance(grossIncome);
    basicIncome = grossIncome - ((int) (taxableIncome * basic));
    return String.format("Your net income is %d", basicIncome);
  }

  public String getHigher() {
    taxableIncome = getAllowance(grossIncome);
    higherIncome = grossIncome - ((int) (taxableIncome * higher));
    return String.format("Your net income is %d", higherIncome);
  }

  public String getAdditional() {
    taxableIncome = getAllowance(grossIncome);
    additionalIncome = grossIncome - ((int) (taxableIncome * additional));
    return String.format("Your net income is %d", additionalIncome);
  }
}
//Main.java

import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    NetIncome sample = new NetIncome();
    Scanner scanner = new Scanner(System.in);

    System.out.println("How much is your annual gross income?e.g 10000 ");
    sample.grossIncome = scanner.nextInt();
    if (sample.grossIncome <= sample.personalAllowance) {
      System.out.println(sample.minimumWage());
    }
    if(sample.grossIncome > sample.personalAllowance && sample.grossIncome <= 50270){
      sample.getAllowance(sample.grossIncome);
      System.out.println(sample.getBasic());
    }
    if(sample.grossIncome > 50270 && sample.grossIncome <= 150000 ){
      sample.getAllowance(sample.grossIncome);
      System.out.println(sample.getHigher());
    }
    if(sample.grossIncome > 150000){
      sample.getAllowance(sample.grossIncome);
      System.out.println(sample.getAdditional());
    }
  }
}
Tags: , , ,
lare (pronounced as LAH-RAY) is a Computer Scientist and Creative Artist who loves creating different ideas with both technology and design. Whenever I'm learning a new technology or programming language, I like to create a journal of my journey - javabyprojects - is my journal for learning java.

0 Comments

Leave a Comment