Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help in Java Class

 
Leeee Ming
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Leeee Ming
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These are my codes....

Is there any way i can improve it...
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, there is.
Check method and variable naming conventions.
Use the code formatting tags to make your code readable here.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also properly javadoc the class, and use a proper logging strategy other than just System.out.println.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic