23-08-2005, 06:06 PM
|
#1 (permalink)
|
|
Broken In
Join Date: Oct 2004
Posts: 162
|
please help in java program
Problem 4
DO NOT USE ANY LOOPS,IF ELSE OR SWITCH CASE
Write a program that transforms numbers 1, 2, 3, 4, ....12 into the corresponding month names January, .........
For example, input is 5
Output is as follows:
Month name corresponding to 5 is May.
You will be writing a class MonthNames with a method for returning month name and any other thing required.
You also need to write a class TestMonthNames for taking input from user, creating object, calling methods and for output as shown above.
PLEASE CAN YOU GIVE CONCEPT OF HOW TO SOLVE ABOVE PROB
DO NOT USE ANY LOOPS,IF ELSE OR SWITCH CASE
|
|
|
|
Advertisements. Register and be a member of the community to get rid of them.
|
|
Advertisement
|
|
23-08-2005, 07:32 PM
|
#2 (permalink)
|
|
Wise Old Owl
Join Date: May 2005
Location: Chennai, India, Asia, the Earth, the Solar system, the Milky Way, the Local group, this Universe.
Posts: 1,171
|
Code:
string GetMonth(int idx)
{
string months[]={"January", "february","march","april","may","june","july","august","september","october","november","december"};
return (months[idx]);
}
Put this in a class, format the output and submit the assignment.
__________________
http://myxp.blogspot.com
-----------------------
Winchester 3200+ @2,500MHz
LeadTek 7900GT VOLT MODDED @ 680 core, 1800 mem
2x1GB Transcend DDR400 @ DDR454 2.5,3,3,5,1T
|
|
|
23-08-2005, 07:38 PM
|
#3 (permalink)
|
|
Broken In
Join Date: Oct 2004
Posts: 162
|
NO ARRAY IS ALLOWED
|
|
|
23-08-2005, 08:30 PM
|
#4 (permalink)
|
|
Wise Old Owl
Join Date: May 2005
Location: Chennai, India, Asia, the Earth, the Solar system, the Milky Way, the Local group, this Universe.
Posts: 1,171
|
Quote:
|
Originally Posted by shivi4
NO ARRAY IS ALLOWED
|
You never said arrays were not allowed. Anyway, there must be some variation of calendar class u can use.
__________________
http://myxp.blogspot.com
-----------------------
Winchester 3200+ @2,500MHz
LeadTek 7900GT VOLT MODDED @ 680 core, 1800 mem
2x1GB Transcend DDR400 @ DDR454 2.5,3,3,5,1T
|
|
|
23-08-2005, 08:43 PM
|
#5 (permalink)
|
|
Wise Old Owl
Join Date: May 2005
Location: Chennai, India, Asia, the Earth, the Solar system, the Milky Way, the Local group, this Universe.
Posts: 1,171
|
import java.text.DateFormatSymbols
...
string GetMonth(int idx)
{
return (getMonths()[idx]);
}
...
It's more like a logic than actual code. See if that works.
__________________
http://myxp.blogspot.com
-----------------------
Winchester 3200+ @2,500MHz
LeadTek 7900GT VOLT MODDED @ 680 core, 1800 mem
2x1GB Transcend DDR400 @ DDR454 2.5,3,3,5,1T
|
|
|
23-08-2005, 09:39 PM
|
#6 (permalink)
|
|
Broken In
Join Date: Oct 2004
Posts: 162
|
WE HAVE TO USE SIMPLE LOGIC
NO EXTERNAL CLASSES NO ARRAYS NO LOOPS IF/ELSE
NO SWITCH OR BREAK
ONLY CLASSES AND OBJECT S AND CONSTRUCTOR
DEFAULT DATA TYPE
|
|
|
24-08-2005, 04:46 PM
|
#7 (permalink)
|
|
Commander in Chief
Join Date: Jul 2005
Posts: 6,658
|
This one shows a lot of output but the correct one is a complete word...
Code:
import java.io.*;
class Month
{
public static void main(String args[]) throws IOException
{
String A;
DataInputStream in = new DataInputStream(System.in);
A=in.readLine();
System.out.println(A.replaceAll("1","January"));
System.out.println(A.replaceAll("2","February"));
System.out.println(A.replaceAll("3","March"));
System.out.println(A.replaceAll("4","April"));
System.out.println(A.replaceAll("5","May"));
// And So on....
}
}
__________________
Harsh J
www.harshj.com
|
|
|
24-08-2005, 06:20 PM
|
#8 (permalink)
|
|
Broken In
Join Date: Oct 2004
Posts: 162
|
we have to use only string class and its method
|
|
|
24-08-2005, 06:24 PM
|
#9 (permalink)
|
|
Commander in Chief
Join Date: Jul 2005
Posts: 6,658
|
I dont get u ?
U mean i must not use replaceAll ?
Wat is string class and thier methods ?
__________________
Harsh J
www.harshj.com
|
|
|
24-08-2005, 06:53 PM
|
#10 (permalink)
|
|
Broken In
Join Date: Oct 2004
Posts: 162
|
PLEASE CAN YOU GIVE CONCEPT OF HOW TO SOLVE ABOVE PROB
DO NOT USE ANY LOOPS,IF ELSE OR SWITCH CASE
NO ARRAY IS ALLOWED
we have in built string class in java
we have to its method only like indexof,substring etc
|
|
|
24-08-2005, 06:56 PM
|
#11 (permalink)
|
|
Wise Old Owl
Join Date: May 2005
Location: Chennai, India, Asia, the Earth, the Solar system, the Milky Way, the Local group, this Universe.
Posts: 1,171
|
Well, he did use string clas and its methods. The datainputstream was only to get a kbd input. U can replace it with a function argument input.
__________________
http://myxp.blogspot.com
-----------------------
Winchester 3200+ @2,500MHz
LeadTek 7900GT VOLT MODDED @ 680 core, 1800 mem
2x1GB Transcend DDR400 @ DDR454 2.5,3,3,5,1T
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|