לוגו אתר Fresh          
 
 
  אפשרות תפריט  ראשי     אפשרות תפריט  צ'אט     אפשרות תפריט  מבזקים     אפשרות תפריט  צור קשר     חץ שמאלה ‎print ‎"Hello World!"; if‎ ‎not rules.‎know ‎then rules.‎read(); חץ ימינה  

לך אחורה   לובי הפורומים > מחשבים > תכנות ובניית אתרים
שמור לעצמך קישור לדף זה באתרי שמירת קישורים חברתיים
תגובה
 
כלי אשכול חפש באשכול זה



  #1  
ישן 22-10-2008, 04:20
  c4designer c4designer אינו מחובר  
 
חבר מתאריך: 22.10.08
הודעות: 15
[JAVA] עזרה בכמה דברים בספר טלפונים

קודם כל, אני חדש כאן.
לעניין: עשיתי מן ספר טלפונים ואני רוצה לדעת איך אפשר לעשות שכשה המשתמש מכניס את אותו השם פעמיים, התוכנה תראה שגיאה "כבר יש שם כזה"

הינה הקוד:

קוד:
import hsa.PhoneBook; import hsa.Stdin; public class BetterPhoneBook { public static void main (String[] args) { PhoneBook book; int command; book = new PhoneBook (); System.out.println ("Enter a command"); System.out.println (" 0 - Quit"); System.out.println (" 1 - Add an entry"); System.out.println (" 2 - Look up and entry"); System.out.println (" 3 - Remove an entry"); System.out.println (" 4 - Edit an entry"); System.out.print ("Command: "); command = Stdin.readInt (); // Loop while (command != 0) { if (command == 1) { // Add entry. String name, phone; System.out.print ("Enter new name: "); name = Stdin.readLine (); System.out.print ("Enter phone number: "); phone = Stdin.readLine (); book.add (name, phone); System.out.println ("Added " + name + " to the phone book"); } // if (command == 1) else if (command == 2) { // Look up entry. String name, phone; System.out.print ("Enter name: "); name = Stdin.readLine (); phone = book.lookUp (name); if (phone.length () == 0) { System.out.println (name + " was not found " + "in phone book"); } else { System.out.println (name + "'s phone " + "number is " + phone); } } // if (command == 2) else if (command == 3) { // Delete entry. String name, phone; System.out.print ("Enter name to be deleted: "); name = Stdin.readLine (); phone = book.lookUp (name); if (phone.length () == 0) { System.out.println (name + " was not found " + "in phone book"); } else { book.remove (name); System.out.println (name + " is deleted"); } } // if (command == 3) else if (command == 4) { // Edit entry. String name, phone; System.out.print ("Enter name to be edited: "); name = Stdin.readLine (); phone = book.lookUp (name); if (phone.length () == 0) { System.out.println (name + " was not found " + "in phone book"); } else { System.out.print ("Enter new phone number: "); phone = Stdin.readLine (); book.remove (name); book.add (name, phone); System.out.println (name + "'s phone " + "number is now " + phone); } } // if (command == 4) else { System.out.println ("Illegal command. Command"); System.out.println ("must be from 0 to 4"); } // else // Prompt user and read the command. System.out.print ("Command: "); command = Stdin.readInt (); } // while (command != 0) } }
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #3  
ישן 23-10-2008, 00:54
  c4designer c4designer אינו מחובר  
 
חבר מתאריך: 22.10.08
הודעות: 15
בתגובה להודעה מספר 2 שנכתבה על ידי רמי ד שמתחילה ב "קודם כל, איפה כל הקוד? היכן..."

ציטוט:
במקור נכתב על ידי רמי ד
קודם כל, איפה כל הקוד? היכן המחלקה PhoneBook? דבר שני מה הבעיה להשתמש בפעולה book.lookUp ליפני ההכנסה "לספר"?


שיט שחכתי להעלות..
הינה:
קוד:
package hsa; public class PhoneBook { int numEntries; String [] names; String [] phoneNumbers; public PhoneBook () { numEntries = 0; names = new String [100]; phoneNumbers = new String [100]; } // PhoneBook constructor public void add (String name, String phoneNumber) { names [numEntries] = name; phoneNumbers [numEntries] = phoneNumber; numEntries++; } // add method public String lookUp (String name) { for (int cnt = 0 ; cnt < numEntries ; cnt++) { if (name.equals (names [cnt])) { return phoneNumbers [cnt]; } } return ""; } // lookUp method public void remove (String name) { for (int cnt = 0 ; cnt < numEntries ; cnt++) { if (name.equals (names [cnt])) { // Delete the entry for (int cnt1 = cnt + 1 ; cnt++ < numEntries ; cnt1++) { names [cnt1 - 1] = names [cnt1]; phoneNumbers [cnt1 - 1] = phoneNumbers [cnt1]; } return; } } } // lookUp method }
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #10  
ישן 07-11-2008, 03:45
  c4designer c4designer אינו מחובר  
 
חבר מתאריך: 22.10.08
הודעות: 15
בתגובה להודעה מספר 8 שנכתבה על ידי דור שמתחילה ב "כבר ענו לך... [QUOTE]יפני..."

ציטוט:
במקור נכתב על ידי דור
כבר ענו לך...


הינה התקדמות קטנה:
קוד:
//p.361 #1 import hsa.PhoneBook; import hsa.Stdin; public class BetterPhoneBook { public static void main (String[] args) { PhoneBook book; int command; book = new PhoneBook (); System.out.println ("Enter a command"); System.out.println (" 0 - Quit"); System.out.println (" 1 - Add an entry"); System.out.println (" 2 - Look up and entry"); System.out.println (" 3 - Remove an entry"); System.out.println (" 4 - Edit an entry"); System.out.print ("Command: "); command = Stdin.readInt (); // Loop while (command != 0) { if (command == 1) { // Add entry. String name, phone, personName; int a, i; System.out.print ("Enter new name: "); name = Stdin.readLine (); personName = book.lookUp (name); a = personName.length (); for (i = 1; i <= a; i++) { if (a == 0) { System.out.print ("error"); break; } } System.out.print ("Enter phone number: "); phone = Stdin.readLine (); book.add (name, phone); System.out.println ("Added " + name + " to the phone book"); } // if (command == 1) else if (command == 2) { // Look up entry. String name, phone; System.out.print ("Enter name: "); name = Stdin.readLine (); phone = book.lookUp (name); if (phone.length () == 0) { System.out.println (name + " was not found " + "in phone book"); } else { System.out.println (name + "'s phone " + "number is " + phone); } } // if (command == 2) else if (command == 3) { // Delete entry. String name, phone; System.out.print ("Enter name to be deleted: "); name = Stdin.readLine (); phone = book.lookUp (name); if (phone.length () == 0) { System.out.println (name + " was not found " + "in phone book"); } else { book.remove (name); System.out.println (name + " is deleted"); } } // if (command == 3) else if (command == 4) { // Edit entry. String name, phone; System.out.print ("Enter name to be edited: "); name = Stdin.readLine (); phone = book.lookUp (name); if (phone.length () == 0) { System.out.println (name + " was not found " + "in phone book"); } else { System.out.print ("Enter new phone number: "); phone = Stdin.readLine (); book.remove (name); book.add (name, phone); System.out.println (name + "'s phone " + "number is now " + phone); } } // if (command == 4) else { System.out.println ("Illegal command. Command"); System.out.println ("must be from 0 to 4"); } // else // Prompt user and read the command. System.out.print ("Command: "); command = Stdin.readInt (); } // while (command != 0) } }


זה לא אומר "שגיאה" שמכניסים את אותו השם פעם שנייה.
למה?
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
תגובה

כלי אשכול חפש באשכול זה
חפש באשכול זה:

חיפוש מתקדם
מצבי תצוגה דרג אשכול זה
דרג אשכול זה:

מזער את תיבת המידע אפשרויות משלוח הודעות
אתה לא יכול לפתוח אשכולות חדשים
אתה לא יכול להגיב לאשכולות
אתה לא יכול לצרף קבצים
אתה לא יכול לערוך את ההודעות שלך

קוד vB פעיל
קוד [IMG] פעיל
קוד HTML כבוי
מעבר לפורום



כל הזמנים המוצגים בדף זה הם לפי איזור זמן GMT +2. השעה כעת היא 03:56

הדף נוצר ב 0.05 שניות עם 10 שאילתות

הפורום מבוסס על vBulletin, גירסא 3.0.6
כל הזכויות לתוכנת הפורומים שמורות © 2024 - 2000 לחברת Jelsoft Enterprises.
כל הזכויות שמורות ל Fresh.co.il ©

צור קשר | תקנון האתר