Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 23-08-2005, 06:06 PM   #1 (permalink)
Broken In
 
Join Date: Oct 2004
Posts: 162
Default 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
shivi4 is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 23-08-2005, 07:32 PM   #2 (permalink)
Wise Old Owl
 
siriusb's Avatar
 
Join Date: May 2005
Location: Chennai, India, Asia, the Earth, the Solar system, the Milky Way, the Local group, this Universe.
Posts: 1,171
Default

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
siriusb is offline  
Old 23-08-2005, 07:38 PM   #3 (permalink)
Broken In
 
Join Date: Oct 2004
Posts: 162
Default

NO ARRAY IS ALLOWED
shivi4 is offline  
Old 23-08-2005, 08:30 PM   #4 (permalink)
Wise Old Owl
 
siriusb's Avatar
 
Join Date: May 2005
Location: Chennai, India, Asia, the Earth, the Solar system, the Milky Way, the Local group, this Universe.
Posts: 1,171
Default

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
siriusb is offline  
Old 23-08-2005, 08:43 PM   #5 (permalink)
Wise Old Owl
 
siriusb's Avatar
 
Join Date: May 2005
Location: Chennai, India, Asia, the Earth, the Solar system, the Milky Way, the Local group, this Universe.
Posts: 1,171
Default

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
siriusb is offline  
Old 23-08-2005, 09:39 PM   #6 (permalink)
Broken In
 
Join Date: Oct 2004
Posts: 162
Default

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
shivi4 is offline  
Old 24-08-2005, 04:46 PM   #7 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default

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....
	}
}
Quote:
Save as Month.java
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 24-08-2005, 06:20 PM   #8 (permalink)
Broken In
 
Join Date: Oct 2004
Posts: 162
Default

we have to use only string class and its method
shivi4 is offline  
Old 24-08-2005, 06:24 PM   #9 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default

I dont get u ?
U mean i must not use replaceAll ?
Wat is string class and thier methods ?
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 24-08-2005, 06:53 PM   #10 (permalink)
Broken In
 
Join Date: Oct 2004
Posts: 162
Default

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
shivi4 is offline  
Old 24-08-2005, 06:56 PM   #11 (permalink)
Wise Old Owl
 
siriusb's Avatar
 
Join Date: May 2005
Location: Chennai, India, Asia, the Earth, the Solar system, the Milky Way, the Local group, this Universe.
Posts: 1,171
Default

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
siriusb is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by abhidev
- by Sujeet
- by Sarath
- by Krow

Advertisement




All times are GMT +5.5. The time now is 08:49 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2