Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Hey Guys Can Somebody Help me With This PROGRAMMING Tutorial Sheet

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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


    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
    }


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Hey Guys Can Somebody Help me With This PROGRAMMING Tutorial Sheet

    Quote Originally Posted by SarahBabyX View Post
    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


    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

    public void monthName(int month)
    {
    /*code goes here*/
    }

    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)
    Last edited by copeg; October 26th, 2010 at 02:26 PM.

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Hey Guys Can Somebody Help me With This PROGRAMMING Tutorial Sheet

    Do your own homework.

  4. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default 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.

  5. The Following User Says Thank You to javapenguin For This Useful Post:

    SarahBabyX (October 26th, 2010)

  6. #5
    Junior Member
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Hey Guys Can Somebody Help me With This PROGRAMMING Tutorial Sheet

    Quote Originally Posted by javapenguin View Post
    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

  7. #6
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default 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

  8. #7
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default 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

  9. #8
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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.

  10. The Following User Says Thank You to copeg For This Useful Post:

    Darryl.Burke (October 27th, 2010)

Similar Threads

  1. Alphabet from sprite sheet
    By Asido in forum Java Theory & Questions
    Replies: 2
    Last Post: September 18th, 2010, 11:49 AM
  2. appending from shell script to excel sheet
    By krishnamohan in forum Java Theory & Questions
    Replies: 1
    Last Post: August 16th, 2010, 10:01 AM
  3. how to copy cells to a new sheet of excel with JexcelAPI??
    By 19world in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: June 15th, 2010, 03:49 AM
  4. an easy clear java programming tutorial
    By zkil_jpf in forum The Cafe
    Replies: 2
    Last Post: April 22nd, 2010, 08:40 AM
  5. Print Content on Pre Printed Sheet
    By kalees in forum Java Theory & Questions
    Replies: 0
    Last Post: February 24th, 2010, 03:26 AM