Question

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 vo 1 II. Requirement 1. Input Prompt appropriate messages that asking use toenter: 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 of that input should be, then STOP the program. That Page 2 of 4

0 0
Add a comment Improve this question Transcribed image text
Answer #1

package yourfirstname_lastname_project;

public class Safety_Alert_VO {

   private String cityName;
   private String Season;
   private double Temperature;
   private int raining;

   public Safety_Alert_VO() {
       this.cityName = null;
       this.Season = null;
       this.Temperature = 0;
       this.raining = 0;

   }

   public String getCityName() {
       return cityName;
   }

   public void setCityName(String cityName) {
       this.cityName = cityName;
   }

   public String getSeason() {
       return Season;
   }

   public void setSeason(String season) {
       Season = season;
   }

   public double getTemperature() {
       return Temperature;
   }

   public void setTemperature(double temperature) {
       Temperature = temperature;
   }

   public int getRaining() {
       return raining;
   }

   public void setRaining(int raining) {
       this.raining = raining;
   }

}

package yourfirstname_lastname_project;

import java.util.Scanner;

public class Demo {

   public static final int MIN_TEMP = 20;

   public static void main(String[] args) {
       final String winter = null;
       final String summer = null;

       Safety_Alert_VO alert = new Safety_Alert_VO();

       Scanner scanner = new Scanner(System.in);

       System.out
               .println("enter the customer name with less than 20 characters");

       String cityName = scanner.next();
       System.out
               .println("enter the season winter/summer otherwise program will stop executing");
       String Season = scanner.next();
       System.out.println("enter the temperature in no's");

       double t = scanner.nextDouble();
       System.out.println("enter the rain density in no's");
       int raining = scanner.nextInt();

       if (Season.trim().matches("summer") || Season.trim().matches("winter")) {
           System.out.println("you entered season value is correct");
       } else {
           System.out.println("your entered season inputs are incorrect");
           System.exit(0);
       }
       if (cityName.length() > 20) {
           System.out.println("you entered city name is too lengthy");
           System.exit(0);
       }

       System.out.println("winter");
       System.out.println("summer");
       System.out.println("enter your choice");

       String season = scanner.next();

       switch (season) {
       case "winter":
           if (t < 32 && raining > 0) {
               System.out.println("true");
               break;
           }
           if (t < 5 || raining > 250) {
               System.out.println("yes,stay inside");
               break;
           }
           if (t < -5 || raining > 500) {
               System.out.println("call for help , call 911 now");
               break;
           } else
               System.out.println("nothing");

           break;
       case "summer":
           final int CONST_MIN_TEMP = -20;

           if (t < CONST_MIN_TEMP) {
               System.out.println("next part");
               break;
           } else
               System.out.println("weather is normal");
           break;

       default:
           System.out.println("you choosen wrong option");
           System.exit(0);

       }
   }

}

output

enter the customer name with less than 20 characters
david
enter the season winter/summer otherwise program will stop executing
winter
enter the temperature in no's
25
enter the rain density in no's
25
you entered season value is correct
1.winter
2.summer
enter your choice
winter
true

Add a comment
Know the answer?
Add Answer to:
Programing requirement for: Safety Alert System Version 01 I. Project and class name Create a new...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a new console application (using the .NET Framework and not .NET Core). Name your project...

    Create a new console application (using the .NET Framework and not .NET Core). Name your project and solution RandomGuess. Generate a random number between 1 and 100, using the Random (Links to an external site.) class. Prompt the user to guess the random number until they successfully guess it. Extra's: Allow the user to input the range for the random number (between X and Y) Validate that the user actually input a valid number, if they did not, prompt them...

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

  • Part I: Problem: Code the following in Java: Candy Class -price -number of pounds sold Create...

    Part I: Problem: Code the following in Java: Candy Class -price -number of pounds sold Create the following methods: -Two constructors – default and second - accessor and mutator methods for each of the fields. - check for invalid price. Negative price is invalid (use if then else and display error message) - a method named userInput to get user input for all the fields. - check for invalid price. Negative price is invalid (use a loop to prompt the...

  • In this assignment, you will implement Address and Residence classes. Create a new java project. Part...

    In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...

  • Use your Car class from the previous Programming Assignment. For this assignment, create a new class...

    Use your Car class from the previous Programming Assignment. For this assignment, create a new class that represents a Used Car Dealership. Your Java program will simulate an inventory system for the dealership, where the employees can manage the car information. Start by creating an array of 10 cars, with an "ID" of 0 through 9, and use the default constructor to create each car. For example, the third car in an array called cars would have ID 2. You...

  • In this homework, you will create a class that stores a list of transactions and computes...

    In this homework, you will create a class that stores a list of transactions and computes the average transaction for a given month. The user must input the name of the month and the transactions into the terminal. The Transaction_List Class First you will create two C++ files called abc1234_Transaction_List.h and abc1234_Transaction_List.cpp. Below is a UML class diagram that shows the basic design of the Transaction_List class. Transaction List -month : string transactions: vector-sdouble - num transactions: int +Transaction Listim...

  • Problem 1 - Print positive message Create a new project named whatever you want in Visual...

    Problem 1 - Print positive message Create a new project named whatever you want in Visual Studio using the Windows Desktop Wizard or in Xcode. If you're using Visual Studio, add a main.c file to your project; you can use the main.c template I provided on Canvas if you'd like. If you're using Xcode, Xcode automatically generates a main.c file for you. Read in an integer from the user; don't prompt for the user input, because that will confuse the...

  • Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete...

    Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete programs using two classes: client and supplier 2   User Interface Specification This is a console-based I/O program. Display should go to System.out (print or println) and the program will get user input using the Scanner class. The flow of execution should be as follows: When the program starts, display a one-line introduction to the user Display a menu with 5 options 1. validate zip...

  • Java programming for ticket price calculator.  It should ask the user if they would like to process...

    Java programming for ticket price calculator.  It should ask the user if they would like to process another ticket order. They should indicate their selection with a Y or N. If they indicate yes, then it should repeat the entire program with the exception of the welcome screen. If they indicate no, it should show the final thank you message and end the program. If they indicate an invalid answer, it should display an error and re-prompt them for a Y...

  • 1. Create a new multi-class Java program which implements a vending machine simulator which contains the...

    1. Create a new multi-class Java program which implements a vending machine simulator which contains the following functionality: A) At program startup, the vending machine is loaded with a variety of products in a variety of packaging for example soda/tonic/Coke in bottles, peanuts in bags, juice in cartons, etc. Also included is the cost of each item. The program should be designed to easily load a different set of products easily (for example, from a file). Also at program startup,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT