Use Java programming Thank you very much Programing requirement for: Safety Alert System
Version 01 I. Project and class name Create a new project name: yourfirst lastname program01
(you must include your name in the project name) Create a new class name: Safety Alert V0 1 II.
Requirement i. Input Prompt appropriate messages that asking use to enter: city name, season,
temperature, and raining. Input validation: your program has to valid the user input and prompt
specific message when user enter invalid input. Base on following validation: City name: only
can be string of letters, not containing number. Maximum length is 20 Season: only can be either
SUMMER or WINTER Temperature is in double Raining is in integer number if the program
found an invalid input, prompt a specific message that tell which input is invalid and what is the
correction format ofthat input should be, then STOP the program. That Page 2 of 4
Solution
import java.util.*;
class Safety_Alert_VO_1
{
private static double CONST_MIN_TEMP_WINTER = -20;
private static double CONST_MAX_TEMP_SUMMER = 127;
public static void main (String[] args)
{
Scanner scan = new Scanner(System.in);
boolean road_ice,call_for_help,flood,tminchange,tmaxchange;
road_ice = false;
call_for_help = false;
tminchange = false;
tmaxchange = false;
String stay_inside = "no";
System.out.println("Enter city name ");
String city = scan.next();
if ((city.contains("[a-zA-Z]+") == true) || (city.length() > 20))
{
System.out.println("Error: city name should be a string with not more than 20
characters");
System.exit(0);
}
System.out.println("Enter season : ");
String season = scan.next();
if(!(season.equals("WINTER") || season.equals("SUMMER")))
{
System.out.println("Error Season can be SUMMER or WINTER");
System.exit(0);
}
System.out.println("Enter temperature : ");
double temp = scan.nextDouble();
System.out.println("Enter raining : ");
int rain = scan.nextInt();
switch(season)
{
case "WINTER": if((temp < 32)&&(rain > 0))
road_ice = true;
if((temp < 5)||(rain>250))
stay_inside = "yes";
else
stay_inside = "no";
if((temp<-15)||(rain>500))
call_for_help = true;
if(temp350)
flood = true;
if((temp>120)||(rain>250))
stay_inside = "yes";
else
stay_inside = "no";
if((temp>125)||(rain>500))
call_for_help = true;
if(temp>CONST_MAX_TEMP_SUMMER)
{
CONST_MAX_TEMP_SUMMER =
Math.max(temp,CONST_MAX_TEMP_SUMMER);
tmaxchange = true;
}
}
System.out.println("CS103 Spring 2017");
System.out.println("Student : first and last name ");
System.out.println("Index Number : ");
System.out.println("The Cities Safety Alert System V01");
System.out.println("City Name : "+city);
System.out.println("Season : "+season);
System.out.println("Temperature : "+temp+ " Raining : "+rain);
System.out.println("Road icing : "+road_ice+" Stay inside : "+stay_inside);
if(tminchange == true)
System.out.println("This is the new minimum temperature record");
if(tmaxchange == true)
System.out.println("This is the new maximum temperature record");
if(call_for_help == true)
System.out.println("Call 911 now!!");
}
}
output:

Use Java programming Thank you very much Programing requirement for.pdf

  • 1.
    Use Java programmingThank you very much Programing requirement for: Safety Alert System Version 01 I. Project and class name Create a new project name: yourfirst lastname program01 (you must include your name in the project name) Create a new class name: Safety Alert V0 1 II. Requirement i. Input Prompt appropriate messages that asking use to enter: city name, season, temperature, and raining. Input validation: your program has to valid the user input and prompt specific message when user enter invalid input. Base on following validation: City name: only can be string of letters, not containing number. Maximum length is 20 Season: only can be either SUMMER or WINTER Temperature is in double Raining is in integer number if the program found an invalid input, prompt a specific message that tell which input is invalid and what is the correction format ofthat input should be, then STOP the program. That Page 2 of 4 Solution import java.util.*; class Safety_Alert_VO_1 { private static double CONST_MIN_TEMP_WINTER = -20; private static double CONST_MAX_TEMP_SUMMER = 127; public static void main (String[] args) { Scanner scan = new Scanner(System.in); boolean road_ice,call_for_help,flood,tminchange,tmaxchange; road_ice = false; call_for_help = false; tminchange = false; tmaxchange = false; String stay_inside = "no"; System.out.println("Enter city name "); String city = scan.next(); if ((city.contains("[a-zA-Z]+") == true) || (city.length() > 20)) { System.out.println("Error: city name should be a string with not more than 20
  • 2.
    characters"); System.exit(0); } System.out.println("Enter season :"); String season = scan.next(); if(!(season.equals("WINTER") || season.equals("SUMMER"))) { System.out.println("Error Season can be SUMMER or WINTER"); System.exit(0); } System.out.println("Enter temperature : "); double temp = scan.nextDouble(); System.out.println("Enter raining : "); int rain = scan.nextInt(); switch(season) { case "WINTER": if((temp < 32)&&(rain > 0)) road_ice = true; if((temp < 5)||(rain>250)) stay_inside = "yes"; else stay_inside = "no"; if((temp<-15)||(rain>500)) call_for_help = true; if(temp350) flood = true; if((temp>120)||(rain>250)) stay_inside = "yes"; else stay_inside = "no"; if((temp>125)||(rain>500)) call_for_help = true; if(temp>CONST_MAX_TEMP_SUMMER)
  • 3.
    { CONST_MAX_TEMP_SUMMER = Math.max(temp,CONST_MAX_TEMP_SUMMER); tmaxchange =true; } } System.out.println("CS103 Spring 2017"); System.out.println("Student : first and last name "); System.out.println("Index Number : "); System.out.println("The Cities Safety Alert System V01"); System.out.println("City Name : "+city); System.out.println("Season : "+season); System.out.println("Temperature : "+temp+ " Raining : "+rain); System.out.println("Road icing : "+road_ice+" Stay inside : "+stay_inside); if(tminchange == true) System.out.println("This is the new minimum temperature record"); if(tmaxchange == true) System.out.println("This is the new maximum temperature record"); if(call_for_help == true) System.out.println("Call 911 now!!"); } } output: