الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

طلب مساعدة في The Telephone Directory ضروري

بدأه A33 في 27 مايو 2009 · 14 رد · 948 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكــم ورحمـة الله وبركاتــه ،،

...أنا عندي مشكلة في حل هذا الواجب ... أتمنى حد يساعدني فيه

هو شامل لإستخدام Hashset

Hashmab ....

Arraylist

والكثير من الأشياء عشان انطلع بالأخير .... <H1 style="MARGIN: 12pt 0cm 3pt">The Telephone Directory

أنا حاولت أحله ... ولكن لما أشغله كل النواتج تطلع لي (null)

أنا أرفقت الملف الأصلي ومحاولتي أيضا في حله ....

أتمنى أن حد يقدر ايساعدني ......

.....</H1>

Ass_3.zip

Ass3.zip

تم تعديل هذه المشاركة بواسطة A33 في 27 مايو 2009 في 20:26

#2

أحتاج للمساعدة ضروووووووووووووووووووووووووووووووووووووووووووووووري ........

#3

أخي قل لنا أين تجد المشكل بالضبط

#4

المشكلة التي واجهتها :resentful: ......هي :

أنه عند إدخال المستخدم اسمه أو رقمه لا تظهر لي القيمة بل يظهر لي (null) في جميع الحالات :cry: .... وأنا لا أعرف لماذا ........

...... أرفقت حلي ... والأسئلة أيضا ليكون المطلوب واضحا بشكل أكبر :calc: ....... أتمنى المساعدة بأسرع وقت ممكن ..... :unsure:

وشكرا أخي لإهتمامك .... جزاك الله ألف خيــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ

ــــــــر .......

#5

>>>>> أرجوا المساعدة بأسرع وقت ممكن ............................. ؟؟؟؟؟؟؟؟؟

اليوم هو آخر فرصة لحله .........

جزاكم اللــــــــــــــــــــــــــــــه خير ....

أود أن أعرف أيــــــــــــــــن خطأي بتحديد وتصحيحه ...............

...

تم تعديل هذه المشاركة بواسطة A33 في 28 مايو 2009 في 11:53

#6

؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟

؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟

؟؟؟؟؟؟

؟؟

#7

بالطريقة هذه تأكد أنك لن تجد من يساعدك

تكلم عن برنامجك وأخبرنا من أين يبدأ وأين تقع المشكلة

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#8

.... تحيتي لك مشرفنا علاء الصالحي .....

......... مشكلتي هي في برنامج bluej >>>>>> >>>>

..... انا لا أعرف ماهي المشكلة بتحديد .... لأني طبقت كل الخطوات التي درستها خلال الفصل في حل هذا الواجب .... ولكن لم أعرف أين الخطأ بتحديد .....

.... أنا مشكلتي في طريقة عرض البيانات ... حيث أن كل النواتج التي تظهر لي تكون فقط null >>>>>

>>>>>> أخي,,,, أنا أرفقت الملفات لأن مشكلتي دائما في طريقة شرحي ... أغلبية الأحيان تكون غير مفهومة ....... " أدرجت محاولتي في حل هذه الأسئلة لتسهل عملية التصحيح "

...... آخر يوم لتسليم هذا الواجب اليوم قبل الساعة 11 ....... أتمنى المساعدة ......

........................................... وجزاكم الله كل الخيــــــــــــــــــــــــــــــــــــــــــــــــر ................................................

#9

<H1 style="MARGIN: 12pt 0cm 3pt">Telephone Directory </H1>

(1) This assignment is about using Hash Map as a phone directory

(2) Remove the text file: Default.txt and rename the text file: “Mapping.txt” to be: “Phone_Directory.txt” so that it contains the name of the person and its phone number + the address of the person in one line as shown in the following examples:

Ahmed, 023456789, ZU-Abu Dhabi or Mariam, 0501234567, USA.

(3) Rename the class Responder to be PhoneDirectory and remove the method: fillresponse(). Modify the method: fillResponseMap() so that it will read one line from the ReadTextFile object (from the file: Phone_Directory.txt), separate the line to three string: Name (string1), Phone Number (string2), Address (string3), and store them in two HashMaps using:

responseMap1.put(string1, string2 + string3); and

responseMap2.put(string2, string1 + string3);

Repeat the reading until the end of the file “Phone_Directory.text” so that the two HashMaps will be filled with the required responses.

(4) Rename the class: TechnicalSupport to PhoneDirectoryManager and use static void main method.

(5) Your program must read an input string from the user which contains either the name of the person to get his/her phone number and address or the phone number to get his/her name and address. Accordingly, your program have to reply correctly to the requirement of different input string. If there is no name or no phone number match the input, you write a message to inform the user that this name or phone number does not exist and ask him/her to input another name or phone number or input bye to exit the system.

(6) Don’t forget to change the welcome statement and the goodbye statement too.

Documentation is very important in this assignment. You have to write full documentation for each class used.

>>>>>>>>>>>>>>>>>>> هذا هو السؤال كامل وأتمنى المساعدة فيه ....

تم تعديل هذه المشاركة بواسطة A33 في 28 مايو 2009 في 21:09

#10

عدنا في هذا البروجكت خمس كلاسات

الكلاس الأول هو

phone directory

ويتضمن :

import java.util.HashMap;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
import java.io.BufferedReader;

/**
* The responder class represents a response generator object.
* It is used to generate an automatic response, based on specified input.
* Input is presented to the responder as a set of words, and based on those
* words the responder will generate a String that represents the response.
*
* Internally, the reponder uses a HashMap to associate words with response
* strings and a list of default responses. If any of the input words is found
* in the HashMap, the corresponding response is returned. If none of the input
* words is recognized, one of the default responses is randomly chosen.
* 
* @author ()
*/
public class PhoneDirectory 
{
private HashMap responseMap1,responseMap2; // used to map key words to responses
private ArrayList defaultResponses; // default responses to use if we don't recognise a word
private Random randomGenerator;
private BufferedReader reader;
private int I;
private String inputLine;

/**
* Construct a PhoneDirectory 
*/
public PhoneDirectory (int i, String inline)
{
I = i;
inputLine = inline;
responseMap1 = new HashMap();
responseMap2 = new HashMap();

defaultResponses = new ArrayList();
fillResponseMap();
// fillDefaultResponses();
randomGenerator = new Random();
}


public char location(int I)
{
return inputLine.charAt(I); 
}

/**
* Generate a response from a given set of input words.
* 
* @param words A set of words entered by the user
* @return A string that should be displayed as the response
*/


public String generateResponse1(String inputLine)
{
String[] wordArray = inputLine.split(" "); 
HashSet words = new HashSet();
for(int i=0; i < wordArray.length; i++) {
words.add(wordArray);
}

Iterator it = words.iterator();
String re;
while(it.hasNext()) {
String word = (String) it.next();
String response1 = (String) responseMap1.get(word);
if((response1 != null) ) {
re = response1;
}
else{
return response1; 

}

}
return inputLine;
}
public String generateResponse2(String inputLine)
{
String[] wordArray = inputLine.split(" "); 
HashSet words = new HashSet();
for(int i=0; i < wordArray.length; i++) {
words.add(wordArray);
}

Iterator it = words.iterator();
while(it.hasNext()) {
String word = (String) it.next();
String response2 = (String) responseMap2.get(word);
if((response2 != null) ) {

}
return response2;
}
return inputLine;
} 


private void fillResponseMap()
{ 

String string1;
String string2;
String string3;

ReadTextFile read = new ReadTextFile("Phone_Directory.txt");
int i = 0;
while (((string1 = read.ReadLine())!= null)&&((string2 = read.ReadLine())!= null) && ((string3 = read.ReadLine())!= null)) {
responseMap1.put(string1, string2 + string3); 
responseMap2.put(string2, string1 + string3); 
i++;
} 
}

private String readInputLine()
{
String line = "";
try {
line = reader.readLine();
}
catch(java.io.IOException exc) {
System.out.println ("Read error: " + exc.getMessage());
}
return line;
}
}

ثانيا : Responder

import java.util.HashMap;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
import java.io.BufferedReader;

/**
* The responder class represents a response generator object.
* It is used to generate an automatic response, based on specified input.
* Input is presented to the responder as a set of words, and based on those
* words the responder will generate a String that represents the response.
*
* Internally, the reponder uses a HashMap to associate words with response
* strings and a list of default responses. If any of the input words is found
* in the HashMap, the corresponding response is returned. If none of the input
* words is recognized, one of the default responses is randomly chosen.
* 

*/
public class Responder
{
private HashMap responseMap; // used to map key words to responses
private ArrayList defaultResponses; // default responses to use if we don't recognise a word
private Random randomGenerator;
private BufferedReader reader;

/**
* Construct a Responder
*/
public Responder()
{
responseMap = new HashMap();
defaultResponses = new ArrayList();
fillResponseMap();
fillDefaultResponses();
randomGenerator = new Random();
}

/**
* Generate a response from a given set of input words.
* 
* @param words A set of words entered by the user
* @return A string that should be displayed as the response
*/
public String generateResponse(String inputLine)
{
String[] wordArray = inputLine.split(" "); // split at spaces

HashSet words = new HashSet();
for(int i=0; i < wordArray.length; i++) {
words.add(wordArray);
}

Iterator it = words.iterator();
while(it.hasNext()) {
String word = (String) it.next();
String response = (String) responseMap.get(word);
if(response != null) {
return response;
}
}
// If we get here, none of the words from the input line was recognized.
// In this case we pick one of our default responses (what we say when
// we cannot think of anything else to say...)



return pickDefaultResponse();
}
/**
* Enter all the known keywords and their associated responses
* into our response map.
*/
private void fillResponseMap()
{
/**

responseMap.put("crash", 
"Well, it never crashes on our system. It must have something\n" +
"to do with your system. Tell me more about your configuration.");
responseMap.put("crashes", 
"Well, it never crashes on our system. It must have something\n" +
"to do with your system. Tell me more about your configuration.");
responseMap.put("slow", 
"I think this has to do with your hardware. Upgrading your processor\n" +
"should solve all performance problems. Have you got a problem with\n" +
"our software?");
responseMap.put("performance", 
"Performance was quite adequate in all our tests. Are you running\n" +
"any other processes in the background?");
responseMap.put("bug", 
"Well, you know, all software has some bugs. But our software engineers\n" +
"are working very hard to fix them. Can you describe the problem a bit\n" +
"further?");
responseMap.put("buggy", 
"Well, you know, all software has some bugs. But our software engineers\n" +
"are working very hard to fix them. Can you describe the problem a bit\n" +
"further?");
responseMap.put("windows", 
"This is a known bug to do with the Windows operating system. Please\n" +
"report it to Microsoft. There is nothing we can do about this.");
responseMap.put("macintosh", 
"This is a known bug to do with the Mac operating system. Please\n" +
"report it to Apple. There is nothing we can do about this.");
responseMap.put("expensive", 
"The cost of our product is quite competitive. Have you looked around\n" +
"and really compared our features?");
responseMap.put("installation", 
"The installation is really quite straight forward. We have tons of\n" +
"wizards that do all the work for you. Have you read the installation\n" +
"instructions?");
responseMap.put("memory", 
"If you read the system requirements carefully, you will see that the\n" +
"specified memory requirements are 1.5 giga byte. You really should\n" +
"upgrade your memory. Anything else you want to know?");
responseMap.put("linux", 
"We take Linux support very seriously. But there are some problems.\n" +
"Most have to do with incompatible glibc versions. Can you be a bit\n" +
"more precise?");
responseMap.put("bluej", 
"Ahhh, BlueJ, yes. We tried to buy out those guys long ago, but\n" +
"they simply won't sell... Stubborn people they are. Nothing we can\n" +
"do about it, I'm afraid.");
*/

String inLine1;
String inLine2;
ReadTextFile read = new ReadTextFile("Mapping.txt");
int i = 0;
while (((inLine1 = read.ReadLine())!= null)&&((inLine2 = read.ReadLine())!= null)) {
responseMap.put(inLine1, inLine2);
i++;
} 
}

/**
* Build up a list of default responses from which we can pick one
* if we don't know what else to say.
*/
private void fillDefaultResponses()
{
/**
defaultResponses.add("That sounds odd. Could you describe that problem in more detail?");
defaultResponses.add("No other customer has ever complained about this before. \n" +
"What is your system configuration?");
defaultResponses.add("That sounds interesting. Tell me more...");
defaultResponses.add("I need a bit more information on that.");
defaultResponses.add("Have you checked that you do not have a dll conflict?");
defaultResponses.add("That is explained in the manual. Have you read the manual?");
defaultResponses.add("Your description is a bit wishy-washy. Have you got an expert\n" +
"there with you who could describe this more precisely?");
defaultResponses.add("That's not a bug, it's a feature!");
defaultResponses.add("Could you elaborate on that?");
*/
String inLine;
ReadTextFile read = new ReadTextFile("Default.txt");
int i = 0;
while ((inLine = read.ReadLine()) != null) {
defaultResponses.add(inLine);
i++;
}
read.closeFile();

}

/**
* Randomly select and return one of the default responses.
* @return A random default response
*/
private String pickDefaultResponse()
{
// Pick a random number for the index in the default response list.
// The number will be between 0 (inclusive) and the size of the list (exclusive).
int index = randomGenerator.nextInt(defaultResponses.size());
return (String) defaultResponses.get(index);
}
private String readInputLine()
{
String line = "";
try {
line = reader.readLine();
}
catch(java.io.IOException exc) {
System.out.println ("Read error: " + exc.getMessage());
}
return line;
}
}

ثالثا :

PhoneDirectoryManager

//import java.util.HashSet;
import java.util.Arrays;

/**
* This class implements a technical support system. It is the top level class in this 
* project. The support system communicates via text input/output in the text terminal.
* 
* This class uses an object of class InputReader to read input from the user, and an
* object of class Responder to generate responses. It contains a loop that repeatedly
* reads input and generates output until the users wants to leave.
* 
* @author () 
* @version (26/5/2009_G6)
*/
public class PhoneDirectoryManager 
{


public static void main()
{
InputReader reader = new InputReader();
PhoneDirectory responder = new PhoneDirectory(1 , " hala");
boolean finished = false;
printWelcome();
while(!finished) {
String input = reader.getInput();
if(input.contains("bye")) {
finished = true;
}
else {
if(responder.location(0) == 0 || responder.location(0) == 1 ||responder.location(0) == 2 || responder.location(0) == 3 || responder.location(0) == 4 ||responder.location(0) == 5 || responder.location(0) == 6 || responder.location(0) == 7|| responder.location(0) == 7 || responder.location(0) == 8 ||responder.location(0) == 9){
String response = responder.generateResponse2(input);
System.out.println(response);
}
else{
String response = responder.generateResponse1(input);
System.out.println(response);
}
}
}
printGoodbye();
}

/**
* Print a welcome message to the screen.
*/
private static void printWelcome()
{
System.out.println("Welcome to the Telephone Directory Support System.");
System.out.println();
System.out.println("Please put your name or the phone number to get your information");
System.out.println("We will assist you with any problem you might have.");
System.out.println("Please type 'bye' to exit our system.");
}

/**
* Print a good-bye message to the screen.
*/
private static void printGoodbye()
{
System.out.println("Nice talking to you. Bye...");
}
}

رابعا :

ReadTextFile

import java.io.*;

public class ReadTextFile {
private FileReader fr;
private BufferedReader br;
public ReadTextFile(String s) {
try {
fr = new FileReader(s);
}
catch(java.io.IOException exc) {
System.out.println ("Read error: " + exc.getMessage());
}
br = new BufferedReader(fr);
}
public String ReadLine() {
String line = "";
try {
line = br.readLine();
}
catch(java.io.IOException exc) {
System.out.println ("Read error: " + exc.getMessage());
}
return line;
}
public void closeFile() {
try {
br.close();
}
catch(java.io.IOException exc) {
System.out.println ("Read error: " + exc.getMessage());
}
}
}

خامسا:

InputReader:

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Arrays;

/**
* Class InputReader reads typed text input from the standard text terminal. 
* The text typed by a user is then chopped into words, and a set of words 
* is provided.
* 
* @author ()
* ( )
* @version (26/5/2009)
*/
public class InputReader
{
private BufferedReader reader;

/**
* Create a new InputReader that reads text from the text terminal.
*/
public InputReader()
{
reader = new BufferedReader(new InputStreamReader(System.in));;
}

/**
* Read a line of text from standard input (the text 
* terminal), and return it as a set of words.
*
* @return A set of Strings, where each String is one of the 
* words typed by the user
*/
public String getInput() 
{
System.out.print("> "); // print prompt
String inputLine = readInputLine().trim().toLowerCase();

// String[] wordArray = inputLine.split(" "); // split at spaces

// add words from array into hashset 
// HashSet words = new HashSet();
// for(int i=0; i < wordArray.length; i++) {
// words.add(wordArray);
// }

return inputLine;
}

/**
* Read one line of input and return it as a String. 
*
* @return A String representing the input, or an empty String 
* if an error occurs.
*/
private String readInputLine()
{
String line = "";

try {
line = reader.readLine();
}
catch(java.io.IOException exc) {
System.out.println ("Read error: " + exc.getMessage());
}
return line;
}
}

وعند تجريبه ...............<<<<<<< يكون الناتج كما في الصورة :

http://img102.herosh.com/2009/05/28/493910646.bmp

أتمنى المساعدة ...... ضروووووووووووووووووووووووري قبل الساعة11

تم تعديل هذه المشاركة بواسطة A33 في 28 مايو 2009 في 20:57

#11

أختي أخبريني ما الذي يقوم به البرنامج بالضبط

لديك دليل تليفونات ما المدخلات التي تأخذيها من المستخدم؟؟؟

حاولي الإسراع فأنا أحاول مساعدتك

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#12

جزاك الله ألف خير أخي علاء الصالحي على تفاعلك .....ومحولتك مساعدتي .....

.... المطلوب هوأنه عند إدخال المستخدم إسمه ... يجب أن تظهر له معلومات عنه مثلا كرقمه وعنوانه .... وهي التي إدخلناها في HashMap

هذا ما فهمتـــــــــــــــــــــــــــــــــــــــــــــــــــــــــه ..... والله تعالى أعلم ....

>>>> أرجوا أن يكون المطلوب واضحا .............<<<<<

وأعتذر عن التاخير في الرد ........

وأكرر شكرري لكل من تابع و حاول مساعدتي ....

جزيتم جميعا كل الخير ....

تم تعديل هذه المشاركة بواسطة A33 في 30 مايو 2009 في 00:54

#13

هل انتهى الموضوع أم مازلت بحاجة إلى مساعدة؟؟

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#14

.... بصراحة يا أخي إنتهى موعد تسليم الواجب .......

ولكن مازالت المشكلة قائمة ..... سلمنا الواجب واتكلنا على الله ... نحن تقريبا أنجزناه كاملا ولكن كانت المشكله في الناتج .....

وننتظر أن نعرف أين خطأنا بتحديد ..... فإذا تمكن أحد أن يعرف المشكله لامانع أن يرشدنا.... لكي ننتبه ولانقع في هذا الخطأ مره أخرى ... لأن الامتحانات النهائية على الأبواب ....

(((دعواتكم)))

جزااااااااااك الله كل الخير أخي علاء الصالحي على متابعتك للمشكلة والشكرلكل من تعاون معنا وحاول أن يساعدنا .....

قال الله تعالى: وَتَعَاوَنُواْ عَلَى الْبرِ وَالتَّقْوَى وَلاَ تَعَاوَنُواْ عَلَى الإِثْمِ وَالْعُدْوَانِ [المائدة:2].

#15

الدالة location في الفئة PhoneDirectory

ما الذي يفترض أن تقوم به؟

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

مواضيع مشابهة