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

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Apr 25th, 2005, 8: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 ();