Question
Urgent Java 1 Help Void methods are useful for printing out information in a particular format. Let's consider dates and times. In America, we use
Urgent Java 1 Help
- Void methods are useful for printing out information in a particular format.
- Let's consider dates and times.
- In America, we use the 12 hour clock, but in Europe, the 24 hour clock is used.
- For example, in America, 8:30 at night is represented as 8:30pm, while in Europe, it is represented as 20:30.
- In America, we write dates in this format MM-DD-YYYY. In Europe, dates are often written as DD.MM.YYYY
- Let's write a program that uses void methods to format dates and times.
- We will print each date and time in both the American and European formats for our user.
- Open up Eclipse and create a new Java class named DateTime
- Copy and paste the starter code below into your file:
/**
* @author
* CIS 36A, Activity 16.1 */ import java.util.Scanner; public class DateTime { public static void main(String[] args) { int year; int day; int month; int hour; int minutes; String dayEve; Scanner input = new Scanner(System.in); System.out.println("Welcome! This program will print dates and times " + "in both the American and European styles! "); System.out.println("First, let's print a formatted date. "); System.out.print("Please enter the current year: "); year = input.nextInt(); System.out.print("Please enter the current month: "); month = input.nextInt(); System.out.print("Please enter the current day: "); day = input.nextInt(); System.out.println(); //call to the formatDateAmerican method here //call to the formatDateEuropean method here System.out.println(" Now, let's print a formatted time. "); System.out.print("Please enter the current hour: "); hour = input.nextInt(); System.out.print("Please enter the current minutes: "); minutes = input.nextInt(); System.out.print("Please enter whether it is \"morning\" or \"evening\": "); dayEve = input.next(); System.out.println(); //call to the formatTimeAmerican method here //call to the formatTimeEuropean method here System.out.println(" Have a good day!"); } }
- Now, you need to write four methods as follows:
formatDateAmerican
takes as input three integer parameter, one for the year, one for the month and one for the day
prints a formatted version of the date to the console, using the format m/d/yyyy
returns nothing
formatDateEuropean
takes as input three integer parameters, one for the year, one for the month and one for the day
prints a formatted version of the date to the console, using the format d.m.yyyy
returns nothing
formatTimeAmerican
takes as input two integer parameters, one for the hour, one for the minutes, and a string parameter that contains either "morning" or "evening"
prints a formatted version of the time to the console, using the format H:MMam or H:MMpm
returns nothing
formatTimeEuropean
takes as input two integer parameters, one for the hour, one for the minutes, and a string parameter that contains either "morning" or "evening"
prints a formatted version of the time to the console, using the 24 hour clock. Note that there is no am or pm in this format.
returns nothing
- These methods should be written outside of main (above or below is fine!).
- When you are finished writing your methods, call them in main in the place indicated by the comments.
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