Question

I am trying to understand how to manipulate the Gregorian Calendar so that I can convert...

I am trying to understand how to manipulate the Gregorian Calendar so that I can convert my answer into a string format. What I'm hoping to do is to do is return string to a different file to add to a string in separate file (Object-oriented exercise between files), but once I can convert this into a string I can convert this file on my own. I added the System.out.println() to show what the results should look like.

In other words, I need to know the command funxs really for the conversion really.

import java.util.*;
import java.util.Date;
import java.util.GregorianCalendar;
public class Calendar{
  
public static void main(String[] args) {
  
int year = 2017;
int day = 31;
int month = 4;
int hourOfDay = 3;
int minute = 45;
GregorianCalendar c2 = new GregorianCalendar(year,month,day, hourOfDay, minute);
System.out.println(c2.getTime());

}
}

so the string should look like => Tue May 29 02:32:00 EDT 2018.

Then I can recreate a file to return this string to another file to add to the string in the other file.

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

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// Calendar.java

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;

public class Calendar {

   public static void main(String[] args) {

       int year = 2017;
       int day = 31;
       int month = 4;
       int hourOfDay = 3;
       int minute = 45;
       GregorianCalendar c2 = new GregorianCalendar(year, month, day,
               hourOfDay, minute);
       String date = c2.getTime().toString();
       try {
           FileWriter fw = new FileWriter(new File("DataOut.txt"));
           fw.write(date + "\n");
           fw.close();
       } catch (IOException e) {

           e.printStackTrace();
       }

   }
}

__________________________

OUtput: (DataOut.txt)

Wed May 31 03:45:00 IST 2017


_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
I am trying to understand how to manipulate the Gregorian Calendar so that I can convert...
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
  • Below I have my 3 files. I am trying to make a dog array that aggerates...

    Below I have my 3 files. I am trying to make a dog array that aggerates with the human array. I want the users to be able to name the dogs and display the dog array but it isn't working. //Main File import java.util.*; import java.util.Scanner; public class Main {    public static void main(String[] args)    {    System.out.print("There are 5 humans.\n");    array();       }    public static String[] array()    {       //Let the user...

  • Hello, How can I make the program print out "Invalid data!!" and nothing else if the...

    Hello, How can I make the program print out "Invalid data!!" and nothing else if the file has a grade that is not an A, B, C, D, E, or F or a percentage below zero? I need this done by tomorrow if possible please. The program should sort a file containing data about students like this for five columns: one for last name, one for first name, one for student ID, one for student grade percentage, one for student...

  • Using java, I am trying to recreate an arithmetic logic unit which performs an integer multiplication....

    Using java, I am trying to recreate an arithmetic logic unit which performs an integer multiplication. I should able to get an output like this: 387637653 x 366499587 = 142069039730149311 But I am not sure because something is wrong apparently. The algorithm of the program goes like: Test multiplier0 If multiplier0 = 0 Shift the multiplicand register left 1 bit Shift the multiplier register right 1 bit If multiplier0 = 1 Add multiplicand to product and place the result in...

  • How to replace elements in a 2D array? Okay so for my program, I am trying...

    How to replace elements in a 2D array? Okay so for my program, I am trying to create a fish tank. My program is to generate 4 different FISH: ><))'> in a tank of tilde (~) characters. The tank is a 2D array of 8 rows and 32 columns so it would look like ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for one of the eight rows (before I generate the random positions of the fish in the rank). Then one row could look like ~~~~~~~~~~><))'>~~~~~~~~~~~~~~~~...

  • How can I make this program sort strings that are in a text file and not...

    How can I make this program sort strings that are in a text file and not have the user type them in? I need this done by 5:00 AM EST tommorow please. import java.util.*; public class MergeDemo { public static void main(String args[]) { Scanner input=new Scanner(System.in); System.out.print("How many lines to be sorted:"); int size=input.nextInt(); String[] lines=new String[size]; lines[0]=input.nextLine(); System.out.println("please enter lines..."); for(int i=0;i { lines[i]=input.nextLine(); } System.out.println(); System.out.println("Lines Before Sorting:"); System.out.println(Arrays.toString(lines)); mergeSort(lines); System.out.println(); System.out.println("Lines after Sorting:"); System.out.println(Arrays.toString(lines)); } public...

  • (Reading & Writing Business Objects) I need to have my Classes be able to talk to...

    (Reading & Writing Business Objects) I need to have my Classes be able to talk to Files. How do I make it such that I can look in a File for an account number and I am able to pull up all the details? The file should be delimited by colons (":"). The Code for testing 'Select' that goes in main is: Account a1 = new Account(); a1.select(“90001”); a1.display(); Below is what it should look like for accounts 90000:3003:SAV:8855.90 &...

  • I am creating a program that will allow users to sign in with a username and...

    I am creating a program that will allow users to sign in with a username and password. Their information is saved in a text file. The information in the text file is saved as such: Username Password I have created a method that will take the text file and convert into an array list. Once the username and password is found, it will be removed from the arraylist and will give the user an opportunity to sign in with a...

  • How to add exceptions to this code for each month so that it won't exceed the...

    How to add exceptions to this code for each month so that it won't exceed the amount of days that in each one for them. Example there are only 28 days in feb and 31 days in march. import java.sql.Timestamp; public class RandomDate { public static void main(String[] args) { long begin=Timestamp.valueOf("1900-01-01 00:00:00").getTime(); long end=Timestamp.valueOf("2014-12-31 00:00:00").getTime(); long diff=end-begin+1; Timestamp rand=new Timestamp(begin+(long)(Math.random()*diff));    int month=rand.getMonth()+1,day=rand.getDate(),year=rand.getYear()+1900;    String[] months={"Janunary","February","March","April","May","June","July","August","September","October","November","December"}; String suffix="th"; if(day==2)suffix="nd"; else if(day==3)suffix="rd"; else if(day==1)suffix="st";    System.out.println("Random Date is: "+month+"/"+day+"/"+year); System.out.println("Formatted...

  • I am currently doing homework for my java class and i am getting an error in...

    I am currently doing homework for my java class and i am getting an error in my code. import java.util.Scanner; import java.util.Random; public class contact {       public static void main(String[] args) {        Random Rand = new Random();        Scanner sc = new Scanner(System.in);        System.out.println("welcome to the contact application");        System.out.println();               int die1;        int die2;        int Total;               String choice = "y";...

  • If anyone can please convert from Java to python. Thank you!! import javax.swing.*; import javax.swing.event.*; import...

    If anyone can please convert from Java to python. Thank you!! import javax.swing.*; import javax.swing.event.*; import javax.swing.table.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class CalenderProgram{ static JLabel lblMonth, lblYear; static JButton btnPrev, btnNext; static JTable tblCalendar; static JComboBox cmbYear; static JFrame frmMain; static Container pane; static DefaultTableModel mtblCalendar; //Table model static JScrollPane stblCalendar; //The scrollpane static JPanel pnlCalendar; static int realYear, realMonth, realDay, currentYear, currentMonth;    public static void main (String args[]){ //Look and feel try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());} catch (ClassNotFoundException...

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