enums - Output not printing after switch case utilized Java -


i'm working on using enum / switch case along zeller's formula saying day of year specific date be. code printing right days before implemented enum / switch portion of code (below). after put in enum/ switch case, when run in drjava prompt day, month , year, nothing prints once goes through switch case

 import java.util.*;  public class zeller {    public enum daysoftheweek {      sunday, monday, tuesday, wednesday, thursday, friday, saturday;   }    private static int value;      public zeller (int value){     this.value = value;   }   public int getvalue(){     return this.value;   }      public static void main(string[] args) {       determineday(value);        // create scanner         scanner input = new scanner(system.in);          // prompt user enter year, month , day           system.out.print("enter month: 1-12: ");         int month = input.nextint();          system.out.print("enter day of month: 1-31: ");         int day = input.nextint();          system.out.print("enter year (e.g., 2008): ");         int year = input.nextint();          // check if month january or february         // if month january , february, convert 13, , 14,         // , year has -1. (go previous year).         if (month == 1 || month == 2) {             month += 12;             year--;         }          // compute answer         int k = year % 100; // year of century         int j = (int)(year / 100.0); // century         int q = day;         int m = month;       int h = (q + (int)((13 * (m + 1)) / 5.0) + k + (int)(k / 4.0)             + (int)(j / 4.0) + (5 * j)) % 7;       value = h;        system.out.println(value);      }      public static string determineday(int value){          string result = "day of week ";       switch (value){        case 1 :         system.out.println(result + "sunday");         break;       case 2 :         system.out.println(result + "monday");          break;       case 3:       system.out.println(result + "tuesday");       break;       case 4:         system.out.println(result + "wednesday");          break;       case 5:         system.out.println(result + "thursday");          break;        case 6:         system.out.println(result + "friday");          break;       case 7 :         system.out.println( result + "saturday");         break;       default :          system.out.println ("looks day doesn't exist");         break;     }      return result;        } } 

  • if want output day using determineday need call method @ end after did calculation , assigned result value.
  • this seems work there problem in algorithm when trying program date 4/11/2016 find friday, when using date 5/5/2016 today output ¨looks day doesn't exist¨, yeah there that.
  • at end of determineday dont need return result since sop result inside switch.

    import java.util.*;  public class zeller {  public enum daysoftheweek {   sunday, monday, tuesday, wednesday, thursday, friday, saturday;  }   private static int value;   public zeller (int value){   this.value = value;  }   public int getvalue(){   return this.value;  }   public static void main(string[] args) {   // create scanner   scanner input = new scanner(system.in);    // prompt user enter year, month , day   system.out.print("enter month: 1-12: ");   int month = input.nextint();    system.out.print("enter day of month: 1-31: ");   int day = input.nextint();    system.out.print("enter year (e.g., 2008): ");   int year = input.nextint();    // check if month january or february   // if month january , february, convert 13, , 14,   // , year has -1. (go previous year).   if (month == 1 || month == 2) {     month += 12;     year--;   }    // compute answer   int k = year % 100; // year of century   int j = (int)(year / 100.0); // century   int q = day;   int m = month;   int h = (q + (int)((13 * (m + 1)) / 5.0) + k + (int)(k / 4.0) + (int)(j / 4.0) + (5 * j)) % 7;   value = h;    system.out.println(value);   determineday(value);  }   public static void determineday(int value){   string result = "day of week ";     switch (value){    case 1 :     system.out.println(result + "sunday");     break;      case 2 :      system.out.println(result + "monday");       break;      case 3:      system.out.println(result + "tuesday");      break;      case 4:      system.out.println(result + "wednesday");      break;      case 5:      system.out.println(result + "thursday");       break;      case 6:      system.out.println(result + "friday");       break;      case 7 :      system.out.println( result + "saturday");      break;      default :       system.out.println ("looks day doesn't exist");      break;   }  } } 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -