Question

In: Computer Science

Use Selections, DO NOT USE ARRAYS AND METHODS. (Find future dates) Write a program that prompts...

Use Selections, DO NOT USE ARRAYS AND METHODS.

(Find future dates)
Write a program that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1, ..., and Saturday is 6). Also prompt the user to enter the number of days after today for a future day and display the future day of the week.

** Can not use java.time.DayOfWeek;

SAMPLE RUN #1: java FindFutureDates

Enter today's day: 4↵
Enter the number of days elapsed since today: 53↵
Today is Thursday and the future day is Monday↵

SAMPLE RUN #2: java FindFutureDates

Enter today's day: 8↵
Enter the number of days elapsed since today: 99↵
Today is an invalid starting day Today's day must be 0-6↵

PLEASE USE SELECTIONS DO NOT USE ARRAYS AND METHODES.

Solutions

Expert Solution

import java.util.Scanner;

public class FindFutureDates {
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                System.out.print("Enter today's day: ");
                int day = sc.nextInt();
                System.out.println("Enter the number of days elapsed since today: 53: ");
                int elapseDays = sc.nextInt();
                if(day<0||day>6) {
                        System.out.println("Today is an invalid starting day Today's day must be 0-6");
                        return;
                }
                System.out.print("Today is ");
                switch(day) {
                case 0: System.out.print("Sunday");break;
                case 1: System.out.print("Monday");break;
                case 2: System.out.print("Tuesday");break;
                case 3: System.out.print("Wednesday");break;
                case 4: System.out.print("Thursday");break;
                case 5: System.out.print("Friday");break;
                case 6: System.out.print("Saturday");break;
                }
                System.out.print(" and the future day is ");
                switch((day + elapseDays)%7) {
                case 0: System.out.print("Sunday");break;
                case 1: System.out.print("Monday");break;
                case 2: System.out.print("Tuesday");break;
                case 3: System.out.print("Wednesday");break;
                case 4: System.out.print("Thursday");break;
                case 5: System.out.print("Friday");break;
                case 6: System.out.print("Saturday");break;
                }
                
        }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

C++ DO not use arrays to write this program. Write a program that repeatedly generates three...
C++ DO not use arrays to write this program. Write a program that repeatedly generates three random integers in the range [1, 100] and continues as follows: If the right-most digit of all the three integers is equal, the program displays them in ascending order on the screen and continues. If the generated integers have different right-most digits, they are not displayed and the program continues. The program terminates once the right-most digits of all the three random numbers are...
Write a program to use Math methods to calculate and display the followings: Prompts the user...
Write a program to use Math methods to calculate and display the followings: Prompts the user to enter an angle, in degrees, and then display the angle in radians and the Sine of the angle. Prompts the user to enter a positive integer and calculates the square root of the number. Computational thinking: Your program must check if it is a positive number. If a negative number is entered, it must ask for another number until the positive number is...
Use Java (Find the number of days in a month) Write a program that prompts the...
Use Java (Find the number of days in a month) Write a program that prompts the user to enter the month and year and displays the number of days in the month. For example, If the user entered month 2 and year 2012, the program should display that February 2012 has 29 days. If the user entered month 3 and year 2015, the program should display that March 2015 has 31 days. Sample Run 1 Enter a month in the...
Write methods contains and remove for the BinarySearchTree class. Use methods find and delete to do...
Write methods contains and remove for the BinarySearchTree class. Use methods find and delete to do the work
USE PYTHON. Write a program that prompts the user to enter 5 test scores. The program...
USE PYTHON. Write a program that prompts the user to enter 5 test scores. The program should display a letter grade for each score and the average test score. Hint: Declare local variables under main() program Prompts the user to enter 5 test scores Define a function to calculate the average score: this should accept 5 test scores as argument and return the avg Define a function to determine the letter grade: this should accept a test score as argument...
Write a JAVA program that prompts the user to enter a single name. Use a for...
Write a JAVA program that prompts the user to enter a single name. Use a for loop to determine if the name entered by the user contains at least 1 uppercase and 3 lowercase letters. If the name meets this policy, output that the name has been accepted. Otherwise, output that the name is invalid.
Write a program that randomly generates 100 dates and store them into a vector. Use the...
Write a program that randomly generates 100 dates and store them into a vector. Use the Date.h provided . The dates generated must be within 1000 days after 1/1/2000. and Sort the 100 dates generated in ascending order. date.h #ifndef DATE_H_ #define DATE_H_ #include #include using namespace std; class Date {    friend ostream &operator<<( ostream &, const Date & ); private:    int day;    int month;    int year; static const int days[]; // array of days per...
write this program in C++ Write a program that prompts a user for three characters. The...
write this program in C++ Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value. Example 1: Input : 10 Input : 20 Input : 30 The largest is 30. The lowest is 10. Example 2: Input : 100 Input : 50 Input :...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for a file name. If the file is not found, an error message is output, and the program terminates. Otherwise, the program prints each token in the file, and the number of times it appeared, in a well formatted manner. To accomplish all this, do the following: - Open the file - the user must be prompted and a file name input. DO NOT hardcode...
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT