prj03-group06/src/weather/WeatherController.java
private int extractMoonPhase() {
		// Average moon phase period +/-0.27 days
		BigDecimal moonPeriod = new BigDecimal("29.5305882");
		// Divide moon phase by 2 to determine the current phase
		moonPeriod = moonPeriod.divide(new BigDecimal("2"));
		// JSON file containing moon phase data for 2020
		InputStream file = getClass().getResourceAsStream("/Lunar_Phases/mooninfo_2020.json");
		// Fetch the current date and time
		SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy HH");
		sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
		String date = sdf.format(System.currentTimeMillis());

		// Parse JSON data for the current date and time, return 
		try {
			JSONArray json = (JSONArray) new JSONParser().parse(new BufferedReader(new InputStreamReader(file)));
			Pattern pattern = Pattern.compile(".*" + date + ".*");
			for (int i=0; i < json.size(); i++) {
				Matcher matcher = pattern.matcher(json.get(i).toString());
				if (matcher.find()) {
					@SuppressWarnings("rawtypes")
					Map moonPhase = (Map) json.get(i);
					BigDecimal currentPhase = new BigDecimal(moonPhase.get("phase").toString());
					currentPhase = currentPhase.divide(new BigDecimal("25"), 0,  RoundingMode.HALF_UP);
					BigDecimal age = new BigDecimal(moonPhase.get("age").toString());
					if (age.compareTo(moonPeriod) == 1) {
						switch(currentPhase.intValue()) {
						case 1:
							currentPhase = new BigDecimal("7");
							break;
						case 2:
							currentPhase = new BigDecimal("6");
							break;
						case 3:
							currentPhase = new BigDecimal("5");
							break;
						default:
							break;
						}
					}
					return currentPhase.intValue();
				}
			}
		} catch (IOException | ParseException e) {
			e.printStackTrace();
		}
		// Just tossed this in to make the compiler happy, code should never get here.
		return -1;
	}
/**
	 * Fetches moon phase from json file.
	 * @return and integer value of moon phase.
	 */
Fetches moon phase from json file.
@return and integer value of moon phase.
Fetches moon phase from json file . @return and integer value of moon phase .
private int extractMoonPhase() {
		BigDecimal moonPeriod = new BigDecimal("29.5305882");
		moonPeriod = moonPeriod.divide(new BigDecimal("2"));
		InputStream file = getClass().getResourceAsStream("/Lunar_Phases/mooninfo_2020.json");
		SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy HH");
		sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
		String date = sdf.format(System.currentTimeMillis());
		try {
			JSONArray json = (JSONArray) new JSONParser().parse(new BufferedReader(new InputStreamReader(file)));
			Pattern pattern = Pattern.compile(".*" + date + ".*");
			for (int i=0; i < json.size(); i++) {
				Matcher matcher = pattern.matcher(json.get(i).toString());
				if (matcher.find()) {
					@SuppressWarnings("rawtypes")
					Map moonPhase = (Map) json.get(i);
					BigDecimal currentPhase = new BigDecimal(moonPhase.get("phase").toString());
					currentPhase = currentPhase.divide(new BigDecimal("25"), 0,  RoundingMode.HALF_UP);
					BigDecimal age = new BigDecimal(moonPhase.get("age").toString());
					if (age.compareTo(moonPeriod) == 1) {
						switch(currentPhase.intValue()) {
						case 1:
							currentPhase = new BigDecimal("7");
							break;
						case 2:
							currentPhase = new BigDecimal("6");
							break;
						case 3:
							currentPhase = new BigDecimal("5");
							break;
						default:
							break;
						}
					}
					return currentPhase.intValue();
				}
			}
		} catch (IOException | ParseException e) {
			e.printStackTrace();
		}
		return -1;
	}
private int extractMoonPhase ( ) { BigDecimal moonPeriod = new BigDecimal ( "29.5305882" ) ; moonPeriod = moonPeriod . divide ( new BigDecimal ( "2" ) ) ; InputStream file = getClass ( ) . getResourceAsStream ( "/Lunar_Phases/mooninfo_2020.json" ) ; SimpleDateFormat sdf = new SimpleDateFormat ( "dd MMM yyyy HH" ) ; sdf . setTimeZone ( TimeZone . getTimeZone ( "UTC" ) ) ; String date = sdf . format ( System . currentTimeMillis ( ) ) ; try { JSONArray json = ( JSONArray ) new JSONParser ( ) . parse ( new BufferedReader ( new InputStreamReader ( file ) ) ) ; Pattern pattern = Pattern . compile ( ".*" + date + ".*" ) ; for ( int i = 0 ; i < json . size ( ) ; i ++ ) { Matcher matcher = pattern . matcher ( json . get ( i ) . toString ( ) ) ; if ( matcher . find ( ) ) { @ SuppressWarnings ( "rawtypes" ) Map moonPhase = ( Map ) json . get ( i ) ; BigDecimal currentPhase = new BigDecimal ( moonPhase . get ( "phase" ) . toString ( ) ) ; currentPhase = currentPhase . divide ( new BigDecimal ( "25" ) , 0 , RoundingMode . HALF_UP ) ; BigDecimal age = new BigDecimal ( moonPhase . get ( "age" ) . toString ( ) ) ; if ( age . compareTo ( moonPeriod ) == 1 ) { switch ( currentPhase . intValue ( ) ) { case 1 : currentPhase = new BigDecimal ( "7" ) ; break ; case 2 : currentPhase = new BigDecimal ( "6" ) ; break ; case 3 : currentPhase = new BigDecimal ( "5" ) ; break ; default : break ; } } return currentPhase . intValue ( ) ; } } } catch ( IOException | ParseException e ) { e . printStackTrace ( ) ; } return - 1 ; }
Fetches moon phase from json file.
Fetches moon phase from json file .
// Average moon phase period +/-0.27 days // Divide moon phase by 2 to determine the current phase // JSON file containing moon phase data for 2020 // Fetch the current date and time // Parse JSON data for the current date and time, return  // Just tossed this in to make the compiler happy, code should never get here.