Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

View Poll Results: Please rate as much as i've done so far
Awsome 1 14.29%
Good 1 14.29%
Ok 5 71.43%
Whatever 0 0%
Try Harder 0 0%
Voters: 7. You may not vote on this poll

Reply
 
Thread Tools Display Modes
Old Apr 25th, 2005, 7:27 PM   #1
Dark Flare Knight
Hobbyist Programmer
 
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4 Dark Flare Knight is on a distinguished road
Red face major class project

Hello. I got a class project to make a cell phone service. So far i got this much done:
import java.awt.*;
import java.io.*;
import hsa.Console;
public class cell
{
    static Console c = new Console (25, 65);
    static String user = "Guest", pass = "Sample", entry = "", enter = "";
    static String user1 = "DFKnight", pass1 = "123456";
    static String user2 = "admin", pass2 = "admin";
    static char letter;
    static String acall, caller, call1, call2;
    static String option1;
    static String back, back1;
    static String gender;
    static String name;
    static int call;
    static public void main (String[] args)
    {
        c.setTextBackgroundColor (Color.gray);
        c.setTextColor (Color.black);
        c.clear ();
        c.println ("Dark Cell Services");
        do
        {
            c.print ("Username: ");
            c.setTextColor (Color.white);
            enter = c.readString ();
            c.setTextColor (Color.black);
            if (enter.equals (user) == false && enter.equals (user1) == false && enter.equals (user2) == false)
            {
                c.setTextColor (Color.red);
                c.println ("Please enter a valid username");
                c.setTextColor (Color.black);
            }
        }
        while (!enter.equals (user) && !enter.equals (user1) && !enter.equals (user2));
        if (enter.equals (user) == true)
        {
            do
            {
                c.print ("Password: ");
                do
                {
                    // note (int) placed in front of a char will give the decimal ASCII equivelant
                    // this is called 'casting' ie if b='A', (int)b will give 65
                    // getChar does not 'echo'(show) on the screen
                    c.setTextColor (Color.white);
                    letter = c.getChar ();
                    // ASCII character set to enter is 32-126
                    c.setTextColor (Color.black);
                    if ((int) letter >= 32 && (int) letter <= 126)
                    {
                        c.setTextColor (Color.white);
                        // if valid entry, show a * to make entry invisible
                        c.print ("*");
                        c.setTextColor (Color.black);
                        // add entry onto the string 'entry' to make word
                        entry = entry + letter;
                    }
                    // 8 = backspace ... if backspace hit and there IS something in entry
                    else if ((int) letter == 8 && entry.length () != 0)
                    {
                        // locate cursor to the last '*' displayed
                        c.setCursor (3, (11 + entry.length ()) - 1);
                        // erase last '*'
                        c.setTextColor (Color.gray);
                        c.print (" ");
                        c.setTextColor (Color.black);
                        // reset cursor
                        c.setCursor (3, 11 + entry.length () - 1);
                        // when there is more than 1 letter left in the word entry, reduce by 1
                        if (entry.length () > 1)
                            entry = entry.substring (0, entry.length () - 1);

                        else
                            // otherwise set entry back to nothing (when the only 1 letter was erased)
                            entry = "";
                    }
                }
                while ((int) letter != 10); // continue as long as an enter was not hit
                // if the entry was not equal to the password ...
                c.setTextColor (Color.black);
                if (entry.equals (pass) == false)
                {
                    c.setTextColor (Color.red);
                    c.println ("Invalid ... try again");
                    entry = "";
                    c.setTextColor (Color.black);
                }
            }
            while (!entry.equals (pass));
        }
        else if (enter.equals (user1) == true)
        {
            do
            {
                c.print ("Password: ");
                do
                {
                    c.setTextColor (Color.white);
                    letter = c.getChar ();
                    c.setTextColor (Color.black);
                    if ((int) letter >= 32 && (int) letter <= 126)
                    {
                        c.setTextColor (Color.white);
                        c.print ("*");
                        c.setTextColor (Color.black);
                        entry = entry + letter;
                    }
                    else if ((int) letter == 8 && entry.length () != 0)
                    {
                        c.setCursor (3, (11 + entry.length ()) - 1);
                        c.setTextColor (Color.gray);
                        c.print (" ");
                        c.setTextColor (Color.black);
                        c.setCursor (3, 11 + entry.length () - 1);
                        if (entry.length () > 1)
                            entry = entry.substring (0, entry.length () - 1);
                        else
                            entry = "";
                    }
                }
                while ((int) letter != 10);
                c.setTextColor (Color.black);
                if (entry.equals (pass1) == false)
                {
                    c.setTextColor (Color.red);
                    c.println ("Invalid ... try again");
                    entry = "";
                    c.setTextColor (Color.black);
                }
            }
            while (!entry.equals (pass1));
        }
        else if (enter.equals (user2) == true)
        {
            do
            {
                c.print ("Password: ");
                do
                {
                    c.setTextColor (Color.white);
                    letter = c.getChar ();
                    c.setTextColor (Color.black);
                    if ((int) letter >= 32 && (int) letter <= 126)
                    {
                        c.setTextColor (Color.white);
                        c.print ("*");
                        c.setTextColor (Color.black);
                        entry = entry + letter;
                    }
                    else if ((int) letter == 8 && entry.length () != 0)
                    {
                        c.setCursor (3, (11 + entry.length ()) - 1);
                        c.setTextColor (Color.gray);
                        c.print (" ");
                        c.setTextColor (Color.black);
                        c.setCursor (3, 11 + entry.length () - 1);
                        if (entry.length () > 1)
                            entry = entry.substring (0, entry.length () - 1);

                        else
                            entry = "";
                    }
                }
                while ((int) letter != 10);
                c.setTextColor (Color.black);
                if (entry.equals (pass2) == false)
                {
                    c.setTextColor (Color.red);
                    c.println ("Invalid ... try again");
                    entry = "";
                    c.setTextColor (Color.black);
                }
            }
            while (!entry.equals (pass2));
        }
        if (enter.equals (user1) == true || enter.equals (user2) == true)
        {
            do
            {
                {
                    c.clear ();
                    c.println ("Dark Cell Services");
                    c.println ();
                    c.println ("Menu");
                    c.println ("Make A Call");
                    c.println ("Turn Off");
                    c.println ();
                    c.print ("What do you want to do? ");
                    c.setTextColor (Color.white);
                    option1 = c.readLine ();
                    c.setTextColor (Color.black);
                    if (option1.equals ("Menu") == true || option1.equals ("menu") == true)
                    {
                        c.clear ();
                        c.println ("Dark Cell Services");
                        c.println ();
                        c.println ("This Section Is Currently Under Construction.");
                        c.println ("Please Check Back For Furth Updates.");
                        c.println ();
                        c.print ("Go Back? ");
                        c.setTextColor (Color.white);
                        back = c.readString ();
                        c.setTextColor (Color.black);
                    }
                    else
                        if (option1.equals ("Make A Call") == true || option1.equals ("make a call") == true || option1.equals ("Make a call") == true)
                        {
                            c.clear ();
                            c.println ("Dark Cell Services");
                            c.println ();
                            c.print ("Reciever's Name: ");
                            c.setTextColor (Color.white);
                            caller = c.readLine ();
                            c.setTextColor (Color.black);
                            c.print ("Your Name: ");
                            c.setTextColor (Color.white);
                            name = c.readLine ();
                            do
                            {
                                c.setTextColor (Color.black);
                                c.print ("Reciever's Gender: ");
                                c.setTextColor (Color.white);
                                gender = c.readLine ();
                                if (gender.equals ("Male") == false || gender.equals ("male") == false || gender.equals ("Female") == false || gender.equals ("female") == false)
                                {
                                    c.setTextColor (Color.red);
                                    c.println ("Unrecognized Gender!");
                                }
                            }
                            while (gender.equals ("Male") == false || gender.equals ("male") == false || gender.equals ("Female") == false || gender.equals ("female") == false);
                            c.setTextColor (Color.black);
                            c.print ("Phone Number: ");
                            c.setTextColor (Color.white);
                            call = c.readInt ();
                            c.setTextColor (Color.black);
                            if (gender.equals ("Male") == true || gender.equals ("male") == true)
                            {
                                c.clear ();
                                do
                                {
                                    c.setTextColor (Color.black);
                                    c.println ("Dark Cell Services");
                                    c.setTextColor (Color.blue);
                                    c.println ();
                                    c.println ();
                                    c.print ("Hey, ");
                                    c.setTextColor (Color.white);
                                    c.println (name);
                                    c.setTextColor (Color.blue);
                                    c.println ("What's up man? ");
                                    c.setTextColor (Color.white);
                                    call1 = c.readLine ();
                                    c.setTextColor (Color.blue);
                                    c.println ("Cool. Well I Gotta Go Somewhere Now.");
                                    c.println ("Call Me Later K?");
                                    c.setTextColor (Color.white);
                                    call2 = c.readLine ();
                                    c.setTextColor (Color.blue);
                                    c.println ("Aight Be Cool.");
                                    c.println ();
                                    c.println ();
                                    c.setTextColor (Color.black);
                                    c.println ("Make another call? ");
                                    acall = c.readString ();
                                    if (acall.equals ("yes") == true || acall.equals ("Yes") == true || acall.equals ("aight") == true || acall.equals ("Aight") == true || acall.equals ("Sure") == true || acall.equals ("sure") == true)
                                        c.println ("_______________________________");
                                }
                                while (acall.equals ("yes") == true || acall.equals ("Yes") == true || acall.equals ("aight") == true || acall.equals ("Aight") == true || acall.equals ("Sure") == true || acall.equals ("sure") == true);
                            }
                            else
                                if (gender.equals ("Female") == true || gender.equals ("female") == true)
                                {
                                    {
                                        c.clear ();
                                        do
                                        {
                                            c.setTextColor (Color.black);
                                            c.println ("Dark Cell Services");
                                            c.setTextColor (Color.blue);
                                            c.println ();
                                            c.println ();
                                            c.print ("Hey, ");
                                            c.setTextColor (Color.white);
                                            c.println (name);
                                            c.setTextColor (Color.blue);
                                            c.println ("What's up gal? ");
                                            c.setTextColor (Color.white);
                                            call1 = c.readLine ();
                                            c.setTextColor (Color.blue);
                                            c.println ("Cool. Well I Gotta Go Somewhere Now.");
                                            c.println ("Call Me Later K?");
                                            c.setTextColor (Color.white);
                                            call2 = c.readLine ();
                                            c.setTextColor (Color.blue);
                                            c.println ("Aight Cool Gal.");
                                            c.println ();
                                            c.println ();
                                            c.setTextColor (Color.black);
                                            c.println ("Make another call? ");
                                            acall = c.readString ();
                                            if (acall.equals ("yes") == true || acall.equals ("Yes") == true || acall.equals ("aight") == true || acall.equals ("Aight") == true || acall.equals ("Sure") == true || acall.equals ("sure") == true)
                                                c.println ("_______________________________");
                                        }
                                        while (acall.equals ("yes") == true || acall.equals ("Yes") == true || acall.equals ("aight") == true || acall.equals ("Aight") == true || acall.equals ("Sure") == true || acall.equals ("sure") == true);
                                    }
                                }
                        }
                }
            }
            while (back.equals ("Yes") == true || back.equals ("yes") == true);
        }
        else
            if (enter.equals (user) == true)
            {
                do
                {
                    c.clear ();
                    c.println ("Dark Cell Services");
                    c.println ();
                    c.println ("Menu");
                    c.println ("Make A Call");
                    c.println ("Turn Off");
                    c.println ();
                    c.print ("What do you want to do? ");
                    c.setTextColor (Color.white);
                    option1 = c.readLine ();
                    c.setTextColor (Color.black);
                    if (option1.equals ("Menu") == true || option1.equals ("menu") == true)
                    {
                        c.clear ();
                        c.println ("Dark Cell Services");
                        c.println ();
                        c.println ("This Section Is Currently Under Construction.");
                        c.println ("Please Check Back For Furth Updates.");
                        c.println ();
                        c.print ("Go Back? ");
                        c.setTextColor (Color.white);
                        back1 = c.readLine ();
                        c.setTextColor (Color.black);
                        if (back1.equals ("no") == true || back1.equals ("No") == true)
                        {
                            c.println ("Thank You For Using Our Service.");
                            break;
                        }
                    }
                    else
                        if (option1.equals ("Make A Call") == true || option1.equals ("make a call") == true || option1.equals ("Make a call") == true)
                        {
                            c.clear ();
                            c.println ("Dark Cell Services");
                            c.println ();
                            c.setTextColor (Color.white);
                            c.println ("THIS SECTION IS CURRENTLY OFF LIMITS.");
                            c.println ("WE HAVE BEEN EXPERIENCING A FEW BUGS.");
                            c.println ("AS SOON AS THEY ARE FIXED, THIS SECTION WILL BE BACK.");
                            c.println ();
                            c.println ("THANKS,");
                            c.println ("DARK CELL SERVICES STAFF");
                        }
                }
                while (back1.equals ("Yes") == true || back1.equals ("yes") == true);
            }
    }
}

I seem to be getting an error here. This part is in the end of the code abouve:

if (enter.equals (user) == true)
            {
                do
                {
                    c.clear ();
                    c.println ("Dark Cell Services");
                    c.println ();
                    c.println ("Menu");
                    c.println ("Make A Call");
                    c.println ("Turn Off");
                    c.println ();
                    c.print ("What do you want to do? ");
                    c.setTextColor (Color.white);
                    option1 = c.readLine ();
                    c.setTextColor (Color.black);
                    if (option1.equals ("Menu") == true || option1.equals ("menu") == true)
                    {
                        c.clear ();
                        c.println ("Dark Cell Services");
                        c.println ();
                        c.println ("This Section Is Currently Under Construction.");
                        c.println ("Please Check Back For Furth Updates.");
                        c.println ();
                        c.print ("Go Back? ");
                        c.setTextColor (Color.white);
                        back1 = c.readLine ();
                        c.setTextColor (Color.black);
                        if (back1.equals ("no") == true || back1.equals ("No") == true)
                        {
                            c.println ("Thank You For Using Our Service.");
                                break;
                        }
                    }
                    else
                        if (option1.equals ("Make A Call") == true || option1.equals ("make a call") == true || option1.equals ("Make a call") == true)
                        {
                            c.clear ();
                            c.println ("Dark Cell Services");
                            c.println ();
                            c.setTextColor (Color.white);
                            c.println ("THIS SECTION IS CURRENTLY OFF LIMITS.");
                            c.println ("WE HAVE BEEN EXPERIENCING A FEW BUGS.");
                            c.println ("AS SOON AS THEY ARE FIXED, THIS SECTION WILL BE BACK.");
                            c.println ();
                            c.println ("THANKS,");
                            c.println ("DARK CELL SERVICES STAFF");
                        }
                }
                while (back1.equals ("Yes") == true || back1.equals ("yes") == true);
            }

The error occurs when i go to make a call and it has something to do with the do/while loop i think cause when i go to make a call, i get some error and the while loop is highlighted black which means it's causing the problem. Can someone figure out what i'm doing wrong here?

EDIT

I also need some help on how i can load a .wav or a picture file here.

Last edited by Dark Flare Knight; Apr 25th, 2005 at 7:50 PM.
Dark Flare Knight is offline   Reply With Quote
Old Apr 26th, 2005, 2:33 AM   #2
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
 

while (back1.equals ("Yes") == true || back1.equals ("yes") == true);

if it is this while loop then it should be

while (back1.equals ("Yes") || back1.equals ("yes") );

or

while (back1.equalsIgnoreCase ("Yes"));

you do not need the "== yes" part as the above evaluation will be true and go into the loop or false and not.
Berto is offline   Reply With Quote
Old Apr 26th, 2005, 6:51 AM   #3
Dark Flare Knight
Hobbyist Programmer
 
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4 Dark Flare Knight is on a distinguished road
Do you know how i can use a .wav or a picture file on java?

EDIT

I'm still getting the same (following) error:

Quote:
java.lang.NullPointerException
at cell.main(cell.java:369)

Last edited by Dark Flare Knight; Apr 26th, 2005 at 7:02 AM.
Dark Flare Knight is offline   Reply With Quote
Old Apr 26th, 2005, 7:33 AM   #4
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
try with initilising the back1 variable in the program first before you use it.
Berto is offline   Reply With Quote
Old Apr 26th, 2005, 1:45 PM   #5
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Voted. If you are still having problems by the time I get home, I will look into it some more... i don't have access to javac at the moment.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Apr 26th, 2005, 5:46 PM   #6
Dark Flare Knight
Hobbyist Programmer
 
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4 Dark Flare Knight is on a distinguished road
Quote:
Originally Posted by Berto
try with initilising the back1 variable in the program first before you use it.
I don't know what u mean by saying that.
Dark Flare Knight is offline   Reply With Quote
Old Apr 26th, 2005, 11:56 PM   #7
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 383
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
static String back="", back1="";
At the begining of your program. When declare stuff.
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Apr 27th, 2005, 3:05 PM   #8
Dark Flare Knight
Hobbyist Programmer
 
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4 Dark Flare Knight is on a distinguished road
K got that.....Can someone tell me how to put an image and (music or .wav) files here?
Dark Flare Knight is offline   Reply With Quote
Old Apr 28th, 2005, 10:57 PM   #9
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 383
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
Ok, I googled a bit and here's what I found:
this is for adding sound:
http://data.uta.edu/~telemm/JavaSound/

this is for adding pictures:
http://www.sunncity.com/Tutorial_Jav...Two/swing.html
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Toolkit.html#getImage(java.lang.String)

I hope it helps ... i'm amazed i couldn't find anything better .....
__________________
Don't take life too seriously, it's not permanent !

Last edited by xavier; Apr 29th, 2005 at 12:02 AM.
xavier is offline   Reply With Quote
Old Apr 29th, 2005, 2:45 PM   #10
Dark Flare Knight
Hobbyist Programmer
 
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4 Dark Flare Knight is on a distinguished road
Quote:
Originally Posted by xavier
Ok, I googled a bit and here's what I found:
this is for adding sound:
http://data.uta.edu/~telemm/JavaSound/

this is for adding pictures:
http://www.sunncity.com/Tutorial_Jav...Two/swing.html
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Toolkit.html#getImage(java.lang.String)

I hope it helps ... i'm amazed i couldn't find anything better .....
Well i want something that's less advanced than that and i only want to enter in the program, one image. No more than one image. The one they talk about there is something more advanced than what i know.
Dark Flare Knight is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:57 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC