Displaying Calendar For Each Month Of Given Year / Day

Feb 15, 2009

I'm working on a program that prompts the user to enter the year and first day of the year and displays the calendar table for that year on the console. For example, if the user entered the year 2005, and 6 for Saturday, Juanuary,1, 2005, the program should then display the calendar for each month of the year.

I have written the program and solved the problem for the most part. Only, I'm having terrific difficulty getting the output to properly format. I'm *almost* there. I'll post my program below and then output.

import java.util.Scanner;
public class DisplayCalendar {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the year: ");
int year = scanner.nextInt();

[Code] ....

___________________________________________
SunMonTueWedThuFriSat
1
2 3 4 5 6 7 8
9 10 11 12131415
16 17 18 19202122
23 24 25 26272829
30 31

February 2005
____________________________________________
SunMonTueWedThuFriSat
1 2 3 4 5
6 7 8 9 101112
13 14 1516171819
20 21 2223242526
27 28

See, my spacing is all off.

View Replies


ADVERTISEMENT

Get Month And Year From Calendar

Aug 8, 2014

I have Georgian Calendar object

GregorianCalendar date = (GregorianCalendar)pageContext.getAttribute("datetime");
System.out.println("date :::: "+date);

It prints :

date :::: java.util.GregorianCalendar[time=1408045500000,areFieldsSet=true,
areAllFieldsSet=true,lenient=false,zone=sun.util.calendar.ZoneInfo[id="GMT+05:30",
offset=19800000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],
firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2014,MONTH=7,

[Code] ....

I want month and year from this like August 2014. How can i do the same.

View Replies View Related

Java-8 :: Calendar Class GetDisplayName Method - Month March Be Repeated 2 Times

Mar 30, 2015

Operating System = Windows 7 version 6.1 running on amd64
Java; VM; Vendor = 1.8.0
Runtime = Java HotSpot(TM) 64-Bit Server VM 25.0-b70
 
Detect a bug in Java, specifically in the Calendar class will getDisplayName method. I put in the message code showing the error. If the code is executed you can see that the month March be repeated 2 times jumping the month of February.
 
Code Example:
 
import java.util.Calendar;
import java.util.Locale;
 public class BugInCalendarDisplayName {
  public static void main(String[] args) {
    Calendar aMonth = Calendar.getInstance();
    aMonth.set(Calendar.MONTH, 0);

[Code] ....
 
Obtained results of the code execution:
 
ENERO
MARZO
MARZO
ABRIL
MAYO
JUNIO
JULIO
AGOSTO
SEPTIEMBRE
OCTUBRE
NOVIEMBRE
DICIEMBRE

View Replies View Related

Parallel Arrays - User Input Integer 1-12 / Output Name Of Month And Number Of Days In That Month

May 11, 2015

I've been working on a question using parallel arrays where the user inputs an integer 1-12 and the output will be the name of the month and the number of days in that month. This is what I have so far

import java.util.*;
public class DaysMonth
{
public static void main (String args[]) {
Scanner keyIn = new Scanner(System.in);
int[] days = new int[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

[Code] ....

After I enter the user int it just ends.

View Replies View Related

Program Store Input Of Rainfall For Each Month - Print Out Month With Least And Most Rainfall

May 1, 2014

I have written program for rainfall that will store and give total, average, least and most. The program stores the input of rainfall for each month. However at the end it suppose to print out the month with the least and most rainfall. I am getting this on the print for

The month with the most rainfall: [Ljava.lang.String;@79a7bd3b

and for

The month with the least rainfall: [D@7378aae2[Ljava.lang.String;@79a7bd3b

. What have i done wrong?

View Replies View Related

How To Create JavaScript To Find Current Month And Current Day Of Month

Mar 17, 2015

I want to be able to use the current date to solve a math problem, specifically as follows:If today is March 17, the math problem of the day should be:

(Month times Day of Month) + 99 = Answer of the Day

(3 x 17) + 99 = 150

How can I create a java script to find the current month and the current day of month, multiple those two together, then add 99 and display the answer as a result.

View Replies View Related

Find The First Day Of Any Year?

Jan 25, 2014

write a program in java to enter a year and find out the first day of that year

View Replies View Related

Looping And Month Printing

Oct 4, 2014

Im working on an assignment with the following instructions:

Create a Date class with the following capabilities:

a)Output the date in multiple formats such as
MM/DD/YYYY
June 14, 1992

b )Use overloaded constructors to create Date objects initialized with dates of the formats in part a).

You should only have 3 member data: integer month, integer day, and integer year. Also, you should have at least 2 constructors and 2 methods in your Date.java.

View Replies View Related

How Does Program Know To Calculate For Only One Year

Mar 26, 2015

how does the program know to calculate for only one year?

public class Interest2 {
public static void main(String[] args) {
double principal; // The value of the investment.
double rate; // The annual interest rate.
double interest; // The interest earned during the year.

[code]....

View Replies View Related

Find Day Number Of The Year?

Apr 15, 2014

figuring out the logic to print the day number of the year. The directions for my homework are: Write a program that prints the day number of the year, given the date is in the form: month day year. For example, if the input is 1 1 05, the day number is 1; if the input is 12 25 05, the day number is 359. The program should check for a leap year . I have a basic outline of the program but i am having trouble with figuring out the logic to display the day number of the year given the date. This is what i have so far

import javax.swing.JOptionPane;
 public class Practice4 {
public static void main(String[] args){
String monthStr;
String dayStr;
int inputMonth;

[code]....

View Replies View Related

Day Of Year With Users Input

Apr 8, 2014

I'm doing a problem where I convert users input for the date (MM/DD/YY) into a written out date and year. That part is fine. The part I'm struggling with is then indicating what day that is in that year. how to use the user inputted MONTH, DAY, and YEAR to then get the day of year.

import java.util.Calendar;
import java.util.Scanner;
import java.util.regex.MatchResult;
import javax.swing.JOptionPane;
public class ConvertDate {

[code]...

View Replies View Related

Scheduling A Task Every Month In Java

Feb 22, 2015

I am new to Java , Every 5th date of every month , get 10$ in bank account .

View Replies View Related

Calculating Rainfall Quarterly Per Year

Mar 30, 2015

//calculates rainfall quarterly per year
 
import java.util.Scanner;
 public class SophiaKeyProgram2 {
 public static void main(String[] args) {
// TODO Auto-generated method stub
 
int numQuarter; //number of quarters in a year
double rainfall=0; //the amount of rain

[Code] ....

View Replies View Related

Program To Check If A Year Is Leap

Feb 5, 2015

I am doing an assignment for my class and I wish to know if there is anything I did wrong or what would make it easier to read, the assignment is to make a program to check if a year (the user provides the year) is a leap year.

import java.util.*;
public class Assignment1
{
public static void main(String[] args) {
int year;
System.out.println("Please enter a year.");
 
[Code] .....

View Replies View Related

How To Automatically Generate All Dates In A Year

Apr 23, 2014

I need a list of all the dates in 2014 in "YYYY-MM-DD" format (because I need to load them into a database), and I do not want to type them all myself. So is there a way to actually get it generated automatically?

View Replies View Related

Write A Program Where User Inputs A Month Between 1-12

Sep 21, 2014

I have an assignment where I'm supposed to write a program where the user inputs a month between 1-12 and then the right amount number in every month. I've tweaked the code a bunch of times, but I keep getting this error message:

insert "}" to complete StatementKALENDER_3.java
insert "}" to complete BlockKALENDER_3.java

The code:

import java.util.*;
import java.util.Scanner;
public class KALENDER_3
}
public static void main(String[] args){
Scanner scanner = new Scanner (System.in);
System.out.print("Skriv ett manadsnummer: ");

[code].....

I think I have just forgot to put in a few { } symbols, maybe an open loop?

View Replies View Related

Implement Dialog Class For Leap Year

Apr 1, 2015

This assignment uses the following description to implement a Dialog class for the Leap Year Problem. We need to decompose this problem into 2 classes:

1.The Date.java class: is a public class that represents a date composed of a month , day, and a year. So you need to declare month, day, and year as integers. Date has 1 constructor and 4 methods. Write the constructor for Date which has 3 parameters: int m, int d, int y ; (As an example of a constructor with 2 parameters for example chapter 3 page 152 code listing 3-13 has a perfect example for you to use which is the BankAccount.java.) and the 4 methods:

"dayIs()" which returns a day. It has no parameter.
"monthIs()" which returns a month. It has no parameter.
"yearIs()" which returns a year. It has not parameter.
"isLeapYear()" which returns a boolean value.

"isLeapYear()" has one parameter year and returns a boolean. Write the method isLeapYear() knowing that a year is defined to be a leapyear it is a multiple of 4, and if it is is a multiple of 100, it must also be a multiple of 400. isLeapYear() thus decides when a year is a leap year. (see the discussion on "Hints for Assign5" to discover specific examples of a LeapYear).

The purpose of the Date.java is to decide whether a year is a leap year. Here is a definition of when a year is considered a leap year :

-year y1 is a leap year if it is multiple of 4.
-year y1 is a leap year if it is a multiple of 100, it must be a multiple of 400.
-Otherwise y1 is not a leap year.

2. The DateJDialog.java class: implements the GUI. Please use the Dialog boxes developed in the book in chapter2 in pages 99-100 in the code-listing 2-32 (NamesDialog.java) for input and output.

Remember that you will prompt the user to enter:
-a month;
-a day;
-a year

And out of these 3 you will be able to create a Date. Then you will use the dialog box to tell the user whether the year entered was a leapyear or not a leapyear.

Remember that we defined in 1- what it means a year is a leap year or not a leap year.

Do not forget to compile the 2 java files. To verify that the DateJDialog.java works, in TextPad after you compile DateJDialog.java, Click on Tools, Click on "Run Java Application".

When you have completed the assignment, please remember to submit Date.java and DateJDialog.java.

View Replies View Related

Multiplying Last 2 Digits In A Year From User Input

May 2, 2014

I Have been playing with this for while, and I can not seem to get my head around, how I can do this. I need to get the last two digits of a year that a user will enter. For example, a date like July 2 , 2014, I want to get the last two digits of year 2014 which are "14" and divide it by 4. This will give me 3.5; how ever I will disregard the ".5" and just keep the 14. I have no problem doing the division, my biggest this is how to just get the last two digits of a year. This is what I have so far, it is basically a template of how I want my program; I just need getting the last 2 digits of a year.

public class DateCalc
{
public static void main (String[] args)
{
String month;
int day;
int year;

[Code] ....

" This will give me 3.5; how ever I will disregard the ".5" and just keep the 14 ". I meant that I just want to keep the 3 from the 3.5 that will be generated when you divide 14 by 4.

View Replies View Related

Find Date Of Monday Which Comes After Third Friday Of Nearest Month

Sep 10, 2014

Write a program to find the date of the monday which comes after the third friday of the nearest month.

Input : yyyy,mm,dd,Day
Output : yyyy,mm,dd,Monday

suppose the input is 29/1/2014
the output should be 24/2/2014

View Replies View Related

Iterating Through Months While Keeping In Mind Different Length Of Month

May 20, 2015

I have to create a method to find the current month with the input being a number of milliseconds using System.currentTimeMillis(). Now I was able to solve the problem with the following extremely cumbersome method:

public static int monthLeap(long ms) {
int result = 0;
int jan = 31, mar = 31, may = 31, jul = 31, aug = 31, oct = 31, dec = 31;
int apr = 30, jun = 30, sep = 30, nov = 30;
int feb = 28;
int febLeap = 29;

[Code] ....

I first go through a loop that goes through all the years and subtracting the number of days of a normal year or a leap year in milliseconds from the total milliseconds. At the end I should have a rest value of milliseconds that represents the amount of milliseconds that have passed already this year. Out of this number I then find the month we are currently in.

My problem is that the above method is way to large and I get a checkstyle warning: "NPath Complexity is 12,288 (max allowed is 80)".

I know that this can somehow be solved with a for loop iterating through the time and counting up months until there is no more month left. My problem though is the different lengths of the months. If each month was the same I could just subtract the amount of days in each month from the rest value.

(Since I already got it down to <= 12 months, I shouldnt bother with the extra days to find the month. Yet if I want to find the month when the date is the first or last day of the month it is important to be very precise) ....

View Replies View Related

Find Date Of Monday Which Comes After Third Friday Of Nearest Month

Sep 10, 2014

Write a program to find the date of the monday which comes after the third friday of the nearest month.

Input : yyyy,mm,dd,Day
Output : yyyy,mm,dd,Monday

Honestly, I don't know how to start......

View Replies View Related

Calculate And Display Price Of Each Object Each Year For 5 Years

Apr 18, 2015

For this program I am calculating the annual costs of 5 office supplies (user input) each with a 5.7% inflation. The user inputs the cost of each object and my program must calculate and display the price of each object each year for 5 years. I already have this part. What I need is how to add the total costs of all 5 supplies per year and display each total cost. Here is the program:

import java.util.Scanner;//Using keyboard to enter data
//Start of Class
public class OfficeSupplyCalculator {
//Start of Method
public static void main(String args[]) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the first item");

[Code] .....

At the moment all I get for the grand total loop is the same number showing up 5 times. I feel like the problem is how I am declaring the grandtotalperyear variable but I'm not sure what is wrong.

View Replies View Related

Swing/AWT/SWT :: Show Year Value In A Class That Extends JSpinner

Mar 15, 2014

I am working on a project where i need to show a year value in a class that extends JSpinner.Its working just fine but when i try to set an alignment value for the editor textfield it all falls apart and i know im missing something really critical here but i can't see or find it all i know is that i can't make a proper reference to the textfield component in the editor i use in the correct way or aproach.

public class JNumberSpinner extends JSpinner {
private String actionCommand;
private boolean isEnabled;
private int startValue;
private int columns;
private int alignment;
private SpinnerNumberModel model;
private JSpinner.NumberEditor numEditor;
private JFormattedTextField jTxtEditorView;

[code]....

View Replies View Related

Display Month Using Enumerated Data Type From String Variable

Apr 1, 2014

I have created an enumerated data type that represents months. In my program I have asked the user for the month. I hold the month entered by user into a string variable. From that string variable I'm trying to display the month using my enumerated data type. I know I can use if statements, but is there another simple way to do it?

import java.util.Scanner;
public class demo {
 //Enum class called month that has constants in it representing months
enum month{january,february,march,april,may,june, july,august,september,
october,november, december};
 
[Code] ....

View Replies View Related

JSP :: Error Page Is Not Displaying Instead Error Status Code Is Displaying

Apr 5, 2014

I have written some error checking code

File name ErrorPage.jsp

<%@ page language="java" isErrorPage="true" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Error</title>
</head>

[code]...

I have put error.jsp and badpage.jsp file in public access folder that is web content in eclipsewhen I am running the code I am status code of 500 and not the errorpage.jsp message .

View Replies View Related

Program To Determine Number Of Days In A Year Up To And Including The Current Day

Nov 23, 2014

So basically we have this question to do : Write a method dayNumber that determines the number of days in a year up to and including the current day. The method should have three int parameters: year, month, and day. If the value of any parameter is invalid, the method should print a warning message and return the value zero. The table gives some examples of the action of the method. Accept any non-negative year as being valid. You may want to assume the existence of a method numberOfDays that returns the number of days in a given month of a given year. And you should have a method call isLeapYear, if the user enter a year that is a leap year.

This is what I did so far:

class dayMonthYear {
public static void main(String[] args) {
System.out.println("Enter a year");
int year = In.getInt();
System.out.println("Enter the month for '1' to be January - '12' to be december");

[Code] ....

It works and compiles but my problem is that: let say I enter "12" for December and December has 31 days, so what my program will do since December has 31 days, it thinks each month has 31 days and add them up which will give me 372 when it's suppose to give me 365. How do I make it that it won't do that and that it will work if the year is a leap year too.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved