File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Need help in Java Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need help in Java Class" Watch "Need help in Java Class" New topic
Author

Need help in Java Class

Leeee Ming
Greenhorn

Joined: May 24, 2004
Posts: 12
Hi, newbie here to java...

Currently using BlueJ to do my Java...

I need help with this problem...

Three many different Java classes make up a complete phone emulator program.

I have been assigned to write a Java class that manages a list of SMS messages. This class has the following features:-
i) Create (input as string, no output) and store SMS text messages in the �phone�. The maximum number of characters allowed for each message is 120.
ii) Show a selected message � input as integer, output as string
iii) Count the number of text messages stored. � no user input, output as integer

I must provide text-based interface for each feature..

Please Help me...

Thanks

[ EJFH: Removed "(UREGET!!!)" from subject line. ]
[ May 24, 2004: Message edited by: Ernest Friedman-Hill ]
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
Hi Leeee Ming,

Try to do your assignments by yourself. Try to write the code yourself and if you find any problem then you can post here.

See java.util.Arraylist to store the messages. This java collection class with provide you all the facilities that you want to store,create,get and count messages.

See String class for text messages. It has many methods which will help you.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


I need help with this problem...
...
Please Help me...

You haven't asked a specific question, so there is nothing any of us will be inclined to help you with - and it's frowned upon in Java Ranch to ask people to write your code.

What I will say is you need a text based interface - so have a look at how Java programs can read input in from the command line as character arrays.
You need some simple string validation, so have a look at the methods provided with the String class. And you need a placeholder for these messages, for which I suggest you look at the Collections java provides, and perhaps look at the collections tutorial at Sun to see how they work and which one you might need.

Feel free to come back to us when you have written some code, if you need any more help. People tend to be more helpful if it look like you've tried to write something yourself first.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Leeee Ming
Greenhorn

Joined: May 24, 2004
Posts: 12
import java.util.*;


/**
* Write a description of class CreateSms here.
*
* @author (your name)
* @version (a version number or a date)
*/

public class Phone
{
// instance variables - replace the example below with your own
private ArrayList list;
private String sms1;
private String getmsg;
// To store number of sms
private int counter=0;
//To store the maximum amount of sms
//private Object[] listsms;
Object[] listsms=new Object[150];

public Phone(){

list = new ArrayList ();

}

public String showsms()
{
return sms1;
}



public int nosms()
{
return counter;
}


/**
* create sms and count sms
*/

public void CreateSms(String getmsg){

list.add(getmsg);

if (getmsg.length()>120)
{
System.out.println("exceed");
}
else
{
sms1 = getmsg;

listsms [counter] = sms1;

System.out.println(listsms[counter]);
counter = counter++;
}
}


/*
* retrieve sms
*/

public void Rsms(int i)
{

System.out.println(list.get(i));
}



}
Leeee Ming
Greenhorn

Joined: May 24, 2004
Posts: 12
These are my codes....

Is there any way i can improve it...
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
yes, there is.
Check method and variable naming conventions.
Use the code formatting tags to make your code readable here.


42
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You could also properly javadoc the class, and use a proper logging strategy other than just System.out.println.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help in Java Class