Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.Calendar;

public class Main {
    public static final int WINTER_SEMESTER = 0;
    public static final int SUMMER_SEMESTER = 1;
    public static final String STRING_WINTER = "WS %d/%d";
    public static final String STRING_SUMMER = "SS %d";

    public static String getSemesterString() {
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);

        if (getSemester() == 0) {
            year = year % 100;
            int next_year = year + 1;
            return String.format(STRING_WINTER, year, next_year);
        } else {
            return String.format(STRING_SUMMER, year);
        }
    }

    public static int getSemester() {
        Calendar cal = Calendar.getInstance();

        int month = cal.get(Calendar.MONTH);

        if (month > Calendar.FEBRUARY && month < Calendar.SEPTEMBER)
            return SUMMER_SEMESTER;
        else
            return WINTER_SEMESTER;
    }
}