Java school Project

Get help on programming - C++, Java, Delphi, etc.
DJT
I Bribed Ron With Foundry And All I Got Was This Lousy Title
Posts: 9387
Joined: 09 Aug 2002, 02:00
Location: Locked Down
Contact:

Java school Project

Post by DJT »

Jeez, take a look at what we have to do for our Gr 10 Computer studies project.
GRADE 10 CELL PHONE PROJECT


You are required to generate /simulate a cell phone. The cell phone must have the basic functions of sending and receiving telephone numbers. These numbers should include landline and cell numbers. In addition, include a SMS function of sending and receiving messages.

You will need to do:

1. create a class that contains the following attributes
1.1. ownNumber
1.2. incoming number
1.3. outgoing number
1.4. blocked number
1.5. SMS number
1.6. Engaged
1.7. Time
1.8. Cost_per_minute

(for the I want to do learner ? how about determining if the system is prepaid etc)

You will need to decide what data types you need for the attributes

2. The following methods
2.1. A set and get method for each attribute
2.2. A method that converts the time to hours, minutes and seconds
2.3. A method that determines the cost of the call.
2.4. ToString method
2.5. A print statement about the call, length of call.

3. A main method
That instantiates a Cell phone object and which simulates the front end of cell phone

4. NOTE: Generate random number for the incoming, outgoing - calls, cost and time and the engaged signal
No idea where to start on this. We were given a weird class that generates rendom phone numbers, but apart from that, nothing.
Want to support my creative work? Drop me a like and subscribe below. It will be greatly appreciated!
Clarke Media - YouTube Channel
Clarke Media - Facebook
Stevo
Registered User
Posts: 1277
Joined: 27 Jul 2004, 02:00

Post by Stevo »

ouch ........
Fishzn
Registered User
Posts: 2685
Joined: 19 May 2003, 02:00
Location: Durban
Contact:

Post by Fishzn »

Dude, i did this for an assignment in 1st year varsity. It was slightly more complex than what you have there, but still performed all those functions. If i can find it, i will send it to you!
"For what is a man profited, if he shall gain the whole world, and lose his own soul?"
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Re: Java school Project

Post by rustypup »

Project wrote: 1.1. ownNumber
1.2. incoming number
1.3. outgoing number
1.4. blocked number
1.5. SMS number
1.6. Engaged
1.7. Time
1.8. Cost_per_minute

Code: Select all

public abstract class Phone
{
private String ownNumber, incommingNumber, outgoingNumber, blockedNumber, SMS number;
private boolean engaged;
private java.util.Date callStart;
private BigDecimal costPerMinute;
}
i)Numbers stored as Strings...quickest route, unless you want to discuss regex...
ii) engaged is digital - either true/false..
iii) Using java.util.Date, calls to a getDuration() type method returns deviation from start to now... or you could store the system time as a long...
iv)BigDecimal... using this wrapper will help in not having to deal with NaN or infinity issues when engaged in double precision math...
Project wrote: 2.1. A set and get method for each attribute
Standard practice in any java app.... it's how things work...

Code: Select all

public void setPhoneNumber(String numbr)
{
    ownNumber = numbr==null?ownNumber:numbr;
}
public String getPhoneNumber()
{
    return ownNumber;
}
HINT: always validate params... this will save you a lot of unnecessary headaches around silly NPEs..... if the turnary *?* bugs you let me know...
Project wrote: 2.2. A method that converts the time to hours, minutes and seconds
Sure..why not... I'm sure the odds are that no codemonkey has ever needed this before, hence its exclusion from the jAPI... man... who teaches this stuff?

my favourites being...
Project wrote: 2.4. ToString method
3. A main method
:lol: someone did their homework... the first is default inherited from Object, but you will almost *always* override in order to make sense of anything... the second you cannot do without if you want the app to run...

....if this doesn't help... give us a shout.. :wink:

<edit to take care of mental problem... all better now...>
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Law
Registered User
Posts: 1569
Joined: 12 Sep 2003, 02:00
Location: UND

Post by Law »

Code: Select all

private java.util.Date callStart;
Do u really think that is nessecary. just easier to use Time as a float. then use Time = System.currentTimeMillis();then when the calls finish Time = (System.currentTimeMillis()-Time)/1000. then you got the call length in seconds. Just seems easier.
Image

MAY THE CHEESE BE WITH YOU!
{PK} Law
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

Law wrote:

Code: Select all

private java.util.Date callStart;
Do u really think that is nessecary. just easier to use Time as a float. then use Time = System.currentTimeMillis();then when the calls finish Time = (System.currentTimeMillis()-Time)/1000. then you got the call length in seconds. Just seems easier.
err..long .. not float :? ... that's why i said store start time as a long.. but then that's precisely what the java.util.Date class does, while at the same time including all those handy minute/hour/day functions attached along with being implicitly understood by java.util.Calendar... :wink:

long just seemed so boring... the API is chock-full of alternmatives to which the average student is never exposed... just seemed a good point at which to start the introduction... :)
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Law
Registered User
Posts: 1569
Joined: 12 Sep 2003, 02:00
Location: UND

Post by Law »

yeah it is long. BUt that is just a waste of performance creating a new object. NOOB :D
Image

MAY THE CHEESE BE WITH YOU!
{PK} Law
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

Code: Select all

public class NooBScanner() implements Serializable
{
     public static enum CONSTANT_NOOBS{
          LAW("Law", "Master of the Pubic kNights"), 
          BOB_MUGABE("Satan", "Raging Elton John fan"), 
          AUSTIN_POWERS("jamin_za", "Brick-less");
           
          private String descript, nick;
          
          CONSTANT_NOOBS(String nck, String descr)
          {
                  nick = nck;
                 descript = descr;
          }
          public String getNick()
          {
                return nick;
          }
          public String getDescription()
          {
                return descript;
          }
      }
      //no point instantiating...
      private NooBScanner()
      {     
            super();
      }
      public static boolean isNoob(String posterNick)
      {
           /*for(CONSTANT_NOOBS cn:CONSTANT_NOOBS.values())
                if(cn.getNick().equals(posterNick))
                      return true;
           return false;*/
           if(posterNick.toLowerCase().indexOf("law")>=0)
                return true;
           return false;
       }       
}
found this hiding on the server... :P
Last edited by rustypup on 01 Sep 2005, 08:45, edited 1 time in total.
Most people would sooner die than think; in fact, they do so - Bertrand Russel
amdretard
Registered User
Posts: 1177
Joined: 26 Oct 2002, 02:00
Location: Cape town

Post by amdretard »

Djt and i are doing the same thing

Anyway how do i randomly generate letters or even word to simulate a SMS
My friends think i need a life. What do you think?
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

amdretard wrote:Anyway how do i randomly generate letters or even word to simulate a SMS
Math.random()???
Most people would sooner die than think; in fact, they do so - Bertrand Russel
amdretard
Registered User
Posts: 1177
Joined: 26 Oct 2002, 02:00
Location: Cape town

Post by amdretard »

ok how do i get that to be just letters
My friends think i need a life. What do you think?
Law
Registered User
Posts: 1569
Joined: 12 Sep 2003, 02:00
Location: UND

Post by Law »

Well create an array of strings as sms' Then you at least have proper msgs
then for numbers use

Code: Select all

Math.random()


This generates a random number between (0;1) -> note the round and not square brckets

so you can times it by ten to make a number from 1-9

This makes a String that makes a number

Code: Select all

 String number="";
for(int i=0; i<10; i++)
{
  number +=""+((int) Math.random()*10);
}



then to select from the array

Code: Select all

int selectedMsg = (int) Math.random()*messageArray.length()

if you want generate a random number multiply by 26 then add 59(think to get letters
Last edited by Law on 31 Aug 2005, 16:57, edited 1 time in total.
Image

MAY THE CHEESE BE WITH YOU!
{PK} Law
amdretard
Registered User
Posts: 1177
Joined: 26 Oct 2002, 02:00
Location: Cape town

Post by amdretard »

Why dont one of you guys do this for ME :D
My friends think i need a life. What do you think?
amdretard
Registered User
Posts: 1177
Joined: 26 Oct 2002, 02:00
Location: Cape town

Post by amdretard »

Why dont one of you guys do this for ME :D

Since you guys are having a fight over who is best why dont you both do it and then i will judge by using that one
My friends think i need a life. What do you think?
Law
Registered User
Posts: 1569
Joined: 12 Sep 2003, 02:00
Location: UND

Post by Law »

caues it's piss easy. AND

you can do it! bite his %$#@en head off!

And i know i'm better newayz0rZ
Image

MAY THE CHEESE BE WITH YOU!
{PK} Law
amdretard
Registered User
Posts: 1177
Joined: 26 Oct 2002, 02:00
Location: Cape town

Post by amdretard »

well i tried

Anyway we havent learnt all this time stuff and we have to create a random time for it
so from creating the random time in seconds how do i convert that to h m s in short easy way
My friends think i need a life. What do you think?
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

:lol: :lol:

1000ms->1s
60s->1min
60m->1hr
24hr->1day

now class.. who can tell me how many days in a year...?
Most people would sooner die than think; in fact, they do so - Bertrand Russel
amdretard
Registered User
Posts: 1177
Joined: 26 Oct 2002, 02:00
Location: Cape town

Post by amdretard »

er 45 LOl

i mean in terms of java what algorithm and then to work out cost of that phone in terms of a cost being an object
My friends think i need a life. What do you think?
Law
Registered User
Posts: 1569
Joined: 12 Sep 2003, 02:00
Location: UND

Post by Law »

well if you did it my way. you can divide by 60 to get mins and divide by 60 again to get hrs> if you want hrs mins sec

you have total time in secs say int TotSec

mins = TotSecs/60;
hrs = mins/60

then in order

int secs= TotSec-mins*60;
min=mins-hrs*60;

you may think wtf because i'm dividing by 60 then multipling i'll get the same number. But thanks to my good friend integer division it works
Image

MAY THE CHEESE BE WITH YOU!
{PK} Law
amdretard
Registered User
Posts: 1177
Joined: 26 Oct 2002, 02:00
Location: Cape town

Post by amdretard »

How do it get it not to give me decimal but just remainders
My friends think i need a life. What do you think?
Law
Registered User
Posts: 1569
Joined: 12 Sep 2003, 02:00
Location: UND

Post by Law »

what ide are you using??
Image

MAY THE CHEESE BE WITH YOU!
{PK} Law
amdretard
Registered User
Posts: 1177
Joined: 26 Oct 2002, 02:00
Location: Cape town

Post by amdretard »

Ready to program jdk 1.2

Remind me which is the ide
My friends think i need a life. What do you think?
Law
Registered User
Posts: 1569
Joined: 12 Sep 2003, 02:00
Location: UND

Post by Law »

like int five = 45%10;

you can also use that to get secs and mins

secs = TotSec%60
mins = mins%60

but only after youve calculated the hrs

so TotSecs = 10000;// sec
mins = 166;
hrs = 2;
then secs = TotSecs%60;
mins = mins%60;

IDE = integrated development enviroment

It's the program you code in
Image

MAY THE CHEESE BE WITH YOU!
{PK} Law
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

yep... %==modulus == remainder...

but then again,

seriosuly get the latest Eclipse... or netbeans...

also, jdk1.2!?? nooooooo.....

<edit... someday...soon... i'm gonna hurt myself...>
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Law
Registered User
Posts: 1569
Joined: 12 Sep 2003, 02:00
Location: UND

Post by Law »

1.2 is kewl it closer to 1 than 1.5 :D











Yeah you should geta later JDK. esp since it's free
Image

MAY THE CHEESE BE WITH YOU!
{PK} Law
Post Reply