Hey Guys Can Somebody Help me With This PROGRAMMING Tutorial Sheet
Hey guys help is much appreciated...I attempted it but its really hard as i am new to programming and only joined my class recently i'd like to get these answered correctly by some one really good at this stuff so i can then review it and learn from it,I'm willing to donate some money to a kind enough gentleman or lady
Pretty please [-O<
Here are the Q's
Q1 Using the method header
public void monthName(int month)
{
// put your code here
}
Supply the code to display (using System.out.println) the name of the month on the screen. The method is passed an integer in the range 1 to 12. The number identifies a particular calendar month.
Q2 Alter your answer to Q1 so that the method returns the name of the month instead of displaying it.
Q3 Using the method header
public void dayName(int dayNum)
{
// put your code here
}
Supply the code to display (using System.out.println) the name of the day on the screen. The method is passed an integer in the range 0 to 6. The number identifies a particular day of the week. Thursday is day 0; Friday is day 1; etc.
Q4 Alter your answer to Q3 so that the method returns the name of the day instead of displaying it.
Q5 Using the method header
public int daysInMonth(int month, int year)
{
// put your code here
}
Supply the code to return the number of days in the month. (FYI, the days in each month are 31, 28/29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.) The method is passed two integers. The first is an integer in the range 1 to 12 which identifies the month. The second is an integer representing the year.
Q6 Consider a calendar year as a series of days numbered from 1 to 365/366. For example, 1-Jan-2011 is day 1 in the year 2011; 21-Jan-2011 is day 21 of that year; 1-Feb-2011 is day 32; 14-Feb-2011 is day 45; and so on. Using the method header
public int serialNumberInYear(int day, int month, int year)
{
// put your code here
}
Supply the code to return the serial number of a particular day (identified by its date) in the year.
Q7 Using the method header
public int leapYearsBetween(int startYear,int endYear)
{
// put your code here
}
Supply the code to return the number or count of leap years between a startYear and endYear - inclusive.
Q8 (NOTE: This question is like Q6 except that it involves more than one year.) Say we select a particular date as our base date or starting date for recording time. For example, say we decide to use 1-Jan-1970 as our base date. Now each day after that date has a serial number. For example, 1-Jan-1970 is day 1; 21-Jan-1970 is day 21; 1-Feb-1970 is day 32; 1-Jan1971 is day 366 (because 1970 was NOT a leap year); and so on. Using the method header
public int serialNumberFromBase(int day, int month, int year)
{
// put your code here
}
Supply the code to return the serial number of a specified date. Use 1-Jan-1970 as the base date.
Q9 Given two dates since 1-Jan-1970 supply the code to return the number of days between them. Use the method header
public int daysBetween(int d1,int m1,int y1,int d2, int m2,int y2)
{
// put your code here
}
Q10 Given a date supply the code to return the number of milliseconds that have elapsed since 1-Jan-1970 up to, but NOT including, the specified date. Use the method header
public int millisecondsUpTo(int day,int month,int year)
{
// put your code here
}
Re: Hey Guys Can Somebody Help me With This PROGRAMMING Tutorial Sheet
Quote:
Originally Posted by
SarahBabyX
Hey guys help is much appreciated...I attempted it but its really hard as i am new to programming and only joined my class recently i'd like to get these answered correctly by some one really good at this stuff so i can then review it and learn from it,I'm willing to donate some money to a kind enough gentleman or lady
Pretty please [-O<
Here are the Q's
Q1 Using the method header
public void monthName(int month)
{
// put your code here
}
Supply the code to display (using System.out.println) the name of the month on the screen. The method is passed an integer in the range 1 to 12. The number identifies a particular calendar month.
Q2 Alter your answer to Q1 so that the method returns the name of the month instead of displaying it.
Q3 Using the method header
public void dayName(int dayNum)
{
// put your code here
}
Supply the code to display (using System.out.println) the name of the day on the screen. The method is passed an integer in the range 0 to 6. The number identifies a particular day of the week. Thursday is day 0; Friday is day 1; etc.
Q4 Alter your answer to Q3 so that the method returns the name of the day instead of displaying it.
Q5 Using the method header
public int daysInMonth(int month, int year)
{
// put your code here
}
Supply the code to return the number of days in the month. (FYI, the days in each month are 31, 28/29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.) The method is passed two integers. The first is an integer in the range 1 to 12 which identifies the month. The second is an integer representing the year.
Q6 Consider a calendar year as a series of days numbered from 1 to 365/366. For example, 1-Jan-2011 is day 1 in the year 2011; 21-Jan-2011 is day 21 of that year; 1-Feb-2011 is day 32; 14-Feb-2011 is day 45; and so on. Using the method header
public int serialNumberInYear(int day, int month, int year)
{
// put your code here
}
Supply the code to return the serial number of a particular day (identified by its date) in the year.
Q7 Using the method header
public int leapYearsBetween(int startYear,int endYear)
{
// put your code here
}
Supply the code to return the number or count of leap years between a startYear and endYear - inclusive.
Q8 (NOTE: This question is like Q6 except that it involves more than one year.) Say we select a particular date as our base date or starting date for recording time. For example, say we decide to use 1-Jan-1970 as our base date. Now each day after that date has a serial number. For example, 1-Jan-1970 is day 1; 21-Jan-1970 is day 21; 1-Feb-1970 is day 32; 1-Jan1971 is day 366 (because 1970 was NOT a leap year); and so on. Using the method header
public int serialNumberFromBase(int day, int month, int year)
{
// put your code here
}
Supply the code to return the serial number of a specified date. Use 1-Jan-1970 as the base date.
Q9 Given two dates since 1-Jan-1970 supply the code to return the number of days between them. Use the method header
public int daysBetween(int d1,int m1,int y1,int d2, int m2,int y2)
{
// put your code here
}
Q10 Given a date supply the code to return the number of milliseconds that have elapsed since 1-Jan-1970 up to, but NOT including, the specified date. Use the method header
public int millisecondsUpTo(int day,int month,int year)
{
// put your code here
}
public void monthName(int month)
{
// put your code here
}
Supply the code to display (using System.out.println) the name of the month on the screen. The method is passed an integer in the range 1 to 12. The number identifies a particular calendar month.
Q2 Alter your answer to Q1 so that the method returns the name of the month instead of displaying it.
Q3 Using the method header
Code java:
public void monthName(int month)
{
/*code goes here*/
}
Code java:
public String monthName(int month)
{
/*code goes here*/
}
For the miliseconds, perhaps go to:
Time (Java 2 Platform SE v1.4.2)
Also, this link will be very helpful: Calendar (Java 2 Platform SE v1.4.2)
Re: Hey Guys Can Somebody Help me With This PROGRAMMING Tutorial Sheet
Re: Hey Guys Can Somebody Help me With This PROGRAMMING Tutorial Sheet
For the one where you try to find daysInMonth,
have a bunch of final constants, however, you'll have to check for a leap year for February so it can't be constant.
final int DAYS_IN_JANUARY = 31;
final constants have to be all caps and have _ separating them and not spaces.
public int daysInMonth(int month, int year)
{
if (monthName(month).equals("January")
{
return (DAYS_IN_JANUARY);
you can also just have return (31) and avoid the constants altogether if you want.
For February, you'll need to check to see if it is a leap year.
Leap years are
2000
2004
2008
2012
2016
The % opearator returns a remainder.
So if
(year%4 == 0)
then it is a leap year and days in February is 29 and the days in year is 366.
Otherwise
days in February is 28 and days in year is 365.
Re: Hey Guys Can Somebody Help me With This PROGRAMMING Tutorial Sheet
Quote:
Originally Posted by
javapenguin
For the one where you try to find daysInMonth,
have a bunch of final constants, however, you'll have to check for a leap year for February so it can't be constant.
final int DAYS_IN_JANUARY = 31;
final constants have to be all caps and have _ separating them and not spaces.
public int daysInMonth(int month, int year)
{
if (monthName(month).equals("January")
{
return (DAYS_IN_JANUARY);
you can also just have return (31) and avoid the constants altogether if you want.
For February, you'll need to check to see if it is a leap year.
Leap years are
2000
2004
2008
2012
2016
The % opearator returns a remainder.
So if
(year%4 == 0)
then it is a leap year and days in February is 29 and the days in year is 366.
Otherwise
days in February is 28 and days in year is 365.
Hi Thank you so much for this JavaPenguin im wondering is it possible you could actually write the code for the remaining questions like u have done with the first few Pretty please :confused:
Re: Hey Guys Can Somebody Help me With This PROGRAMMING Tutorial Sheet
This is a forum, not a 'cheat your way through a Java course' service. Abuse reported.
db
Re: Hey Guys Can Somebody Help me With This PROGRAMMING Tutorial Sheet
@javapenguin : Please don't post links to Java APIs that are already EOL. The Java 6 API can be found at
Java Platform SE 6
db
Re: Hey Guys Can Somebody Help me With This PROGRAMMING Tutorial Sheet
To the original poster, cheating your way through life will only get you so far. If you make the effort to accomplish what you need, and encounter a problem other than 'do this for me', then I encourage you to post your code along with any errors and specific questions regarding that code.As of right now, this thread has run its course and I am locking it.