Question
Program in java language Dates are printed in several common formats. Two of the more common formats are: 07/21/55 and July 21, 1955 Write a
Program in java language Dates are printed in several common formats. Two of the more common formats are:
07/21/55 and July 21, 1955
Write a program that reads a date in the first format and prints that date in the second format.
- Prompt the user and accept user input for the date in MM/DD/YYYY format.
- Retrieve the month portion of the date entered and convert it to an integer.
- Do the same thing for day and year
- Create a string named months that contains the number of the month and the name of the month: 1 January2 February3 March.
- Convert the month into a string
- Find the index where the numeric value for the month is held
- Retrieve the text version of the month.
- Output the date in expanded format.
//Sample run #1
Enter a date in MM/DD/YYYY format: 04/12/2000
April 12, 2000
//Sample run #2
Enter a date in MM/DD/YYYY format: 11/10/2000
November 10, 2000
//Sample run #3
Enter a date in MM/DD/YYYY format: 12/20/2000
December 20, 2000
Note that for sample run 3, you are likely to get an out of bounds error unless you provide a 13th option within the string.
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: begin 90, end -1, length 98
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3107)
at java.base/java.lang.String.substring(String.java:1873)
at edu.ilstu.DateProgram.main(DateProgram.java:20)
Program 2: Part 2
In this program, you will generate a series of random numbers and implement methods of the Math class to manipulate these numbers.
- Generate three random numbers, variables a, b and c, and store them in three integer variables. The range of the numbers should be from 1-50.
- Calculate the quadratic formula for the three numbers. The formula is:
x=-bb2-4ac2
Note: You must use Math functions to calculate the square root and the power.
//Sample run #1 Because of the random nature of your numbers, your results will be different.
The two possible solutions for 13 17 2 are
-0.13 and -1.18
//Sample run #2
The two possible solutions for 7 44 11 are
-0.26 and -6.02
//Sample run #3
The two possible solutions for 48 7 10 are
NaN and NaN
Note that you will get NaN as a result when the result is an imaginary number, which occurs when the radical portion of the answer (the part in the square root) is negative.
Here is the actual result of the above numbers:
= | -0.072916666666667 0.45057351570588i |
- The i shown at the end of the solution indicates imaginary. Your program will generate the NaN result when this is the case.
To test your answer, go https://www.calculator.net/quadratic-formula-calculator.html?av=48&bv=7&cv=10&x=62&y=9 , enter the three random numbers generated and calculate the result.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started