Question

I need this in Java, please! The ISO 8601 Standard date format for Information Interchange indicates...

I need this in Java, please!

The ISO 8601 Standard date format for Information Interchange indicates that a date be written as such: yyyy-MM-dd (eg. 2012-07-02, 1999-12-05, 1998 -01-27 ) where yyyy represents the four digit year MM represents a two digit numerical month dd represents a two digit numerical day Chinese date format is specified as: yyyy-M-d Macedonean date format is specified as: d.M.yyyy where yyyy represents the four digit year M represents a one or two digit numerical month, as appropriate d represents a one or two digit numerical day, as appropriate

You are to write a program which converts dates from Chinese and Macedonean formats to ISO format. The program will : * ask the user which format they will be entering (C - Chinese or M - Macedonean) * accept the user input, determining which conversion to perform * output the ISO version of the date that was input * Your program should delegate at least one action to a function (for example single digit days will need to be converted to double digits, single digit months will need to be converted to double digits)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class Demo{
   public static void main(String args[]) {
       Scanner s=new Scanner(System.in);
       String date="";
       System.out.println("Enter format in which date will be entering (C - Chinese or M - Macedonean) ");
      
       char ch=s.next().charAt(0);
       System.out.println("Enter date");
       String d=s.next();
       if(ch=='C') {
           String m[]=d.split("-");
           date+=m[0]+"-";
           if(m[1].length()==1)
               date+="0"+m[1]+"-";
           else
               date+=m[1]+"-";
           if(m[2].length()==1)
               date+="0"+m[2];
           else
               date+=m[2];
       }
       else {
           String m[]=d.split("/.");
           date+=m[2];
           if(m[1].length()==1)
               date+="0"+m[1]+"-";
           else
               date+=m[1]+"-";
           if(m[0].length()==1)
               date+="0"+m[0];
           else
               date+=m[0];
          
       }
       System.out.println("Date in ISO format "+date);
   }
}

Add a comment
Know the answer?
Add Answer to:
I need this in Java, please! The ISO 8601 Standard date format for Information Interchange indicates...
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
  • Write a program that prompts the user to enter the date in mm/dd/yyyy format. The program...

    Write a program that prompts the user to enter the date in mm/dd/yyyy format. The program should use a single input statement to accept the date, storing each piece of the date into an appropriate variable. Demonstrate that the input was obtained correctly by outputting the month, day, and year to the screen. Sample output: Enter (date (mm/dd/yyyy): 02/08/2011 Month entered: 2 Day entered: 8 Year entered: 2011 Challenge: Although the user entered 02, C++ drops the 0 as insignificant...

  • I need help writing this program in C. (not C++) Armor Games CrazyMonkeyGames Max Games Palomar...

    I need help writing this program in C. (not C++) Armor Games CrazyMonkeyGames Max Games Palomar Collegeå ¯Wolfram|Alpha M Gmail EaXGen Studios How About a Date? Dinner and Dancing with your Computer The purpose of this assignment is to acquaint you with the capability of a computer program to systematically explore a set of possibilities and deter mine the validity of input to the program. HPal-CSC112Spring 2017/ Lab Solutions 12-How about a datelcheckDatelnC Debuglche... elcome to my Date Checker Project Enter...

  • -make an ordered single linked list -straight to screen (no user prompting) -the date is format...

    -make an ordered single linked list -straight to screen (no user prompting) -the date is format mm dd yyyy, and must be imbedded in the program (no user prompting) -example must be able to work with code -comments above each action/line encouraged Design, implement and test a C++ program that reads a series of data records from a file and stores each record in a linked list (in ascending order by items number). After creating the linked list the program...

  • Given the following date class interface: class date {private: int month;//1 - 12 int day;//1 -...

    Given the following date class interface: class date {private: int month;//1 - 12 int day;//1 - 28. 29. 30. 31 depending on month & year int year;//4-digit, e.g.. 2017 public: date();//Default constructor (investigate; find what it is used for)//Postcondition: the newly declared date object is initialized to 01/01/2000 date(int mm, int dd, int yyyy);//Second constructor//Postcondition: the newly declared data object is initialized to mm/dd/yyyy void setDate(int mm. int dd. int yyyy);//Postcondition: set the contents of the calling date object to...

  • Write a Java program that parse a date into the format of "m/d/y" that with month,...

    Write a Java program that parse a date into the format of "m/d/y" that with month, day, and year all in single digits.

  • C Program Question 1: Write a program that reads a date from the keyboard and tests...

    C Program Question 1: Write a program that reads a date from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. The input date will have the format: mm/dd/yyyy Note that there is no space in the above format. A date in this format must be entered in one line. A valid...

  • Question 1: Write a program in C that reads a date from the keyboard and tests...

    Question 1: Write a program in C that reads a date from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. The input date will have the format: mm/dd/yyyy Note that there is no space in the above format. A date in this format must be entered in one line. A valid...

  • please write C++ code to finish R0,R1,R2 Introduction In this assignment, you are going to develop...

    please write C++ code to finish R0,R1,R2 Introduction In this assignment, you are going to develop a "Schedule Book System that runs in the command line environment. The system stores the schedule of events input by user and allows users to add view or delete events. You can assume that the system can at most store 100 events Each group is required to write a Win32 Console Application program called ScheduleBook.cpp The requirements are listed below. RO When the program...

  • In the first task, you will write a Java program that accepts a string of the...

    In the first task, you will write a Java program that accepts a string of the format specified next and calculate the answer based on the user input. The input string should be of the format dddxxdddxx*, where d represents a digit and x represents any character and asterisk at the end represents that the string can have any number of characters at the end. 1. Prompt the user to enter a string with the specific format (dddxxdddxx*) 2. Read...

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