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
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 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 :...
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...
Use Java (Geometry: point in a rectangle?) Write a program that prompts the user to enter...
Use Java (Geometry: point in a rectangle?) Write a program that prompts the user to enter a point (x, y) and checks whether the point is within the rectangle centered at (0, 0) with width 10 and height 5.  For example, (2, 2) is inside the rectangle and (6, 4) is outside the rectangle. (Hint: A point is in the rectangle if its horizontal distance to (0, 0) is less than or equal to10 / 2 and its vertical...
Do not use arrays and code a program that reads a sequence of positive integers from...
Do not use arrays and code a program that reads a sequence of positive integers from the keyboard and finds the largest and the smallest of them along with their number of occurrences. The user enters zero to terminate the input. If the user enters a negative number, the program displays an error and continues. Sample 1: Enter numbers: 3 2 6 2 2 6 6 6 5 6 0 Largest Occurrences Smallest Occurrences 6 5 2 3. Do not...
You MUST use VECTORS in this lab. Do NOT use ARRAYS. Write code in C++ with...
You MUST use VECTORS in this lab. Do NOT use ARRAYS. Write code in C++ with //comments . Please include a screen shot of the output Part 4: Calorie Counting Specifications: Write a program that allows the user to enter the number of calories consumed per day. Store these calories in an integer vector. The user should be prompted to enter the calories over the course of one week (7 days). Your program should display the total calories consumed over...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT