Question

Please go to the Practice Exercises (at the end of Chapter 3 in your text on page 129) and do Exercise E 3.14 which asks you
Please go to the Practice Exercises (at the end of Chapter 3 in your text on page 129) and do Exercise E 3.14 which asks you
0 0
Add a comment Improve this question Transcribed image text
Answer #1

JAVA program for the provided problem statement

/* JAVA program to identify the Season based on the month and day number */

// import utility classes
import java.util.*;

// Main class
public class Main
{
// create a static object of Scanner class for user input
static Scanner in = new Scanner(System.in);
  
// this method displays seasons names for February month
public static void february(){
  
// first provide valid day number
int day = 0;
while(day<1 || day>28){
System.out.print("Enter Day: ");
day = in.nextInt();
if(day<1 || day>28){
System.out.println("Invalid day !!, Please enter number in range [1-28]\n");
}
}
  
// if day number is greater than 15 then it is Spring else it is Winter
if(day <= 15){
System.out.println("This is Indian Winter Season.");
}else{
System.out.println("This is Indian Spring Season.");
}
}
  
// this method displays seasons names for April, june, September, November
public static void monthsWith30thDays(int month){
// first provide valid day number
int day = 0;
while(day<1 || day>30){
System.out.print("Enter Day: ");
day = in.nextInt();
if(day<1 || day>30){
System.out.println("Invalid day !!, Please enter number in range [1-30]\n");
}
}
  
if(month == 4 || month == 6){
// display for April and june
System.out.println("This is Indian Summer Season.");
}else if(month == 9){
// display for September
System.out.println("This is Indian Autumn Season.");
}else{
// display for November
System.out.println("This is Indian Prewinter Season.");
}
}
  
// this method displays seasons names for remaining 7 months
public static void monthsWith31stDays(int month){
// first provide valid day number
int day = 0;
while(day<1 || day>31){
System.out.print("Enter Day: ");
day = in.nextInt();
if(day<1 || day>31){
System.out.println("Invalid day !!, Please enter number in range [1-31]\n");
}
}
  
if(month == 1 || (month == 12 && day>15)){
// display for January and late December
System.out.println("This is Indian Winter Season.");
}else if(month == 3){
// display for March
System.out.println("This is Indian Spring Season.");
}else if(month == 5){
// display for May
System.out.println("This is Indian Summer Season.");
}else if(month == 7 || month == 8){
// display for July and August
System.out.println("This is Indian Monsoon Season.");
}else if(month == 10){
// display for October
System.out.println("This is Indian Autumn Season.");
}else{
// display for early November
System.out.println("This is Indian Prewinter Season.");
}
}
  
// driver method
   public static void main(String[] args)
   {
   // first, take user input for month number
   // if user does not enter month number in a range [1-12],
   // it displays an error message and again asks for correct input
int month = 0;
while(month<1 || month>12){
System.out.print("Enter Month: ");
month = in.nextInt();
if(month<1 || month>12){
System.out.println("Invalid month !!, Please enter number in range [1-12]\n");
}
}
  
/* According to Indian weather:-
16 December - 15 February := "Winter"
16 February - 31 March := "Spring"
1 April - 30 june:= "Summer"
1 July - 31 August := "Monsoon"
1 September - 31 October := "Autumn"
1 November - 15 December := "Prewinter"
*/
  
/* Note-
February has 28 days (assuming no leap year)
April, June, September, November has 30 days
the remaining month of the year has 31 days
*/
  
// therefore, let's create three function using nested if-else
if(month == 2){
// for 28 days month
february();
}else if(month == 4 || month == 6 || month == 9 || month == 11){
// for 30 days months
monthsWith30thDays(month);
}else{
// for 31 days months
monthsWith31stDays(month);
}
   }
}

JAVA program Screenshots

JAVA program Output Screenshots

Add a comment
Know the answer?
Add Answer to:
Please go to the Practice Exercises (at the end of Chapter 3 in your text on...
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
  • i need the sloution with java code please :) Using your Queue class write a GUI...

    i need the sloution with java code please :) Using your Queue class write a GUI program that opens a file contains integers in the range [0 .. 999] "in.txt". The program stops reading if -1 is read. Your program should use queues to make the output such that the first textfield output contains the integers in the range 0..9 but in their same order as in the input, the same for the second textfield but in the range 10..19,...

  • Java Program 4: Methods Purpose: To practice using both void and value-returning methods and understand when,...

    Java Program 4: Methods Purpose: To practice using both void and value-returning methods and understand when, where, and how to use them. The following problem employs the use of both void and value-returning methods: (Be sure to start with an algorithm to help you organize your ideas and provide a blueprint as to how to approach the problem. Think about what kind of return type your method will need. Carefully examine and follow ALL the program specifications (for full credit)....

  • *USE JAVA In this project you will create program that calculate the number of times every...

    *USE JAVA In this project you will create program that calculate the number of times every word appears in a given text file. Your program will take in the name of the file as well as the number of threads to create to speed up the process. The numbers of threads must be greater than 0. The output will be saved into a file in alphabetical order. Besides creating the program itself, you are to run experiments to show how...

  • This is JAVA programing problem. Please give me all necessary screenshot and comments. (I use Ecl...

    This is JAVA programing problem. Please give me all necessary screenshot and comments. (I use Eclipse) Thanks Write a program that implements the FIFO, LRU, and Optimal page replacement algorithms presented in chapter 8 of your text. First generate a random page-reference string (this should be 20 entries long) where page numbers range from 0 to 9. Apply the random page-reference string to each algorithm, and record the number of page faults incurred by each algorithm. Implement the replacement algorithms...

  • In this exercise, write a complete Java program that reads integer numbers from the user until...

    In this exercise, write a complete Java program that reads integer numbers from the user until a negative value is entered. It should then output the average of the numbers, not including the negative number. If no non-negative values are entered, the program should issue an error message. You are required to use a do-while loop to solve this problem. Solutions that do not use a do-while loop will be given a zero. Make sure to add appropriate comments to...

  • What this Assignment Is About: Review on Java I topics, such as primitive data types, basic...

    What this Assignment Is About: Review on Java I topics, such as primitive data types, basic I/O, conditional and logical expressions, etc. Review on Java loops. Documentation Requirements to get full credits in Documentation The assignment number, your name, StudentID, Lecture number(time), and a class description need to be included at the top of each file/class. A description of each method is also needed. Some additional comments inside of methods (especially for a "main" method) to explain code that are...

  • Please solve using Java and comment your code for clarity. Sample 3. Input: 4 1 231...

    Please solve using Java and comment your code for clarity. Sample 3. Input: 4 1 231 Output: 0 This sequence also does not have a majority element (note that the element 1 appears twice and hence is not a majority element). Problem Introduction Majority rule is a decision rule that selects the alternative which has a majority, that is, more than half the votes. Given a sequence of elements (1.02....,On, you would like to check whether it contains an element...

  • The files must be called Proper coding conventions required the first letter of the class start...

    The files must be called Proper coding conventions required the first letter of the class start with a capital letter and the first letter of each additional word start with a capital letter. Only submit the .java file needed to make the program run. Do not submit the .class file or any other file. 5% Style Components Include properly formatted prologue, comments, indenting, and other style elements as shown in Chapter 2 starting page 64 and Appendix 5 page 881-892....

  • (PLEASE UPLOAD ALL PARTS TO THE QUESTION) (IE: PSEUDO CODE AND JAVA CODE TOGETHER NOT ONE...

    (PLEASE UPLOAD ALL PARTS TO THE QUESTION) (IE: PSEUDO CODE AND JAVA CODE TOGETHER NOT ONE OR THE OTHER) Design an Employee class that fields for the following pieces of information: 1) Employee name 2) Employee number Next design a class named ProductionWorker that extends the Employee class. The ProductionWorker class should have fields to hold the following information: 1) Shift number (an integer, such as 1, 2, or 3) 2)Hourly pay The workday is divided into two shifts day...

  • Assignment on Java programing 1. Write programs for the following exercises in Java. Each file should...

    Assignment on Java programing 1. Write programs for the following exercises in Java. Each file should have short description of the implemented class and for files with main method the problem it is solving. Make sure your files have appropriate names. Programs should write output to the Console. b) BST: Implement Binary Search Tree ADT with insert(int key), delete(int key), Node find(int key), and in-order traverse() where it prints the value of the key. Your operations should use recursion. The...

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
ADVERTISEMENT