Create a method to return the tax rate in Java

The sales tax rate has changed from 8% to 10%.

The tax rate is

  public static final String TAX_PERCENT = "0.08";

It is dangerous to have it as a constant like this.

April 2014 8% October 2019 10%

The tax rate has changed in this way, and it is expected that the timing of tax increases will occur in the future.

Since the tax rate changes depending on the date and time in this way, it is recommended to prepare a method that returns the tax rate as shown below.

  public static final String EIGHT_TAX_PERCENT = "0.08";

  public static final String TEN_TAX_PERCENT = "0.10";

  public static final String TEN_TAX_PERCENT_CHANGE_DAY = "2019-10-01 00:00:00";

  public static BigDecimal getTaxPercent() {
    try {
      Date now = new Date();
      SimpleDateFormat sdformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      Date dateTime = sdformat.parse(TEN_TAX_PERCENT_CHANGE_DAY);
      return now.getTime() >= dateTime.getTime()
        ? new BigDecimal(TEN_TAX_PERCENT)
        : new BigDecimal(EIGHT_TAX_PERCENT);
    } catch (ParseException e) {
      System.out.println(e);
    }
    //I'm sure it won't come forever
    return new BigDecimal("0");
  }

Recommended Posts

Create a method to return the tax rate in Java
Try to create a bulletin board in Java
Create a java method [Memo] [java11]
How to create a method
How to create a Java environment in just 3 seconds
I tried to create a Clova skill in Java
How to create a data URI (base64) in Java
How to get the class name / method name running in Java
[Android, Java] Convenient method to calculate the difference in days
How to create a placeholder part to use in the IN clause
[Java] How to create a folder
When I wanted to create a method for Premium Friday, it was already in the Java 8 standard API
Call the super method in Java
How to create a new Gradle + Java + Jar project in Intellij 2016.03
Connecting to a database with Java (Part 1) Maybe the basic method
How to store the information entered in textarea in a variable in the method
[Java] I tried to make a maze by the digging method ♪
Let's create a TODO application in Java 5 Switch the display of TODO
Java reference to understand in the figure
[Java] How to use the toString () method
Create a TODO app in Java 7 Create Header
What is the main method in Java?
How to get the date in java
About the method to convert a character string to an integer / decimal number (cast data) in Java
[Java] How to search for a value in an array (or list) with the contains method
How to test a private method in Java and partially mock that method
Declare a method that has a Java return value with the return value data type
The story of forgetting to close a file in Java and failing
To create a Zip file while grouping database search results in Java
I thought about the best way to create a ValueObject in Ruby
How to get the absolute path of a directory running in Java
How to reference a column when overriding the column name method in ActiveRecord
Set up a Java GUI in a separate thread to keep the main
How to create your own annotation in Java and get the value
[Java] Handling of JavaBeans in the method chain
Two ways to start a thread in Java + @
Create a CSR with extended information in Java
A story about the JDK in the Java 11 era
How to display a web page in Java
Measure the size of a folder in Java
Code to escape a JSON string in Java
Let's create a super-simple web framework in Java
How to create a theme in Liferay 7 / DXP
How to easily create a pull-down in Rails
How to use the replace () method (Java Silver)
I tried to create Alexa skill in Java
Let's make a calculator application with Java ~ Create a display area in the window
[Java] Is it unnecessary to check "identity" in the implementation of the equals () method?
[Java] Create a filter
Create JSON in Java
3. Create a database to access from the web module
[Java] How to omit the private constructor in Lombok
[Android / Java] Set up a button to return to Fragment
How to create a Spring Boot project in IntelliJ
Source used to get the redirect source URL in Java
A note for Initializing Fields in the Java tutorial
I tried to make a login function in Java
How to mock a super method call in PowerMock
Java classes and instances to understand in the figure
How to convert A to a and a to A using AND and OR in Java
How to convert a file to a byte array in Java