![]() |
|
| 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 |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4
![]() |
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 8:50 PM. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
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. |
|
|
|
|
|
#3 | |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4
![]() |
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:
Last edited by Dark Flare Knight; Apr 26th, 2005 at 8:02 AM. |
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() |
try with initilising the back1 variable in the program first before you use it.
|
|
|
|
|
|
#5 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#6 | |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#7 |
|
Professional Programmer
|
static String back="", back1="";
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
#8 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4
![]() |
K got that.....Can someone tell me how to put an image and (music or .wav) files here?
|
|
|
|
|
|
#9 |
|
Professional Programmer
|
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 1:02 AM. |
|
|
|
|
|
#10 | |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|