RU beehive logo ITEC dept promo banner
ITEC 120
2008fall
aaray,
ejderrick,
ibarland,
jmdymacek

home—info—labs—hws—exams
textbook—java.lang docs—java.util docs—archive

lab06b
lab06b

P4.17: Write a program that transforms numbers 1,2,…,12 into the corresponding month names "January", "February", …, "December".

Hint: Make one very long string "January February March …" in which you add spaces such that each month has the same length. Then use substring to extract the month you want. Implement a class Month whose constructor parameter is the month number and whose getName method returns the month name.
For an extra challenge, make sure you don't return any spaces at the end of the month name — find a String method which will remove the trailing spaces.
Do not use an “if” statement.

public class MonthTester {
  public static void main( String[] args ) {
    Month m1 = new Month(1);
    System.out.println( "Expect \"January\": " + m1.getName() );

    // Add at least two more tests here.
    }
  }

Super challenge: add a second method to class Month: one named getDays which returns how many days the Month has.

home—info—labs—hws—exams
textbook—java.lang docs—java.util docs—archive


©2008, Ian Barland, Radford University
Last modified 2008.Nov.02 (Sun)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme