السلام عليكم ورحمة الله وبركاتة
لو سمحتم شباب ممكن مساعدة
الكود شغال تمام مافية اي خطا
الكود يقوم بقراء اسماء من ملف خارجي ثم يقوم بتخزين الاسماء في مصفوفة ثم يقوم بطباعة الاسماء
المشكلة في التعامل مع الارقام الكود بعد التعديل في اسفل الصفحة
/*
* Class Description:
* This is the initial draft of a class to represent a sequence of names.
*
*/
public class Names {
final int DEFAULT = 8;
int capacity = DEFAULT;
int nextIndex = 0;
String[] A;
public Names() {
A = new String[capacity];
}
public Names(int Capacity) {
if(Capacity < 0) {
Capacity = DEFAULT;
}
capacity = Capacity;
A = new String[capacity];
}
boolean Add(String Name) {
boolean result = false;
if(nextIndex < capacity) {
A[nextIndex] = Name;
nextIndex = nextIndex + 1;
result = true;
}
return result;
}
int indexOf(String Name) {
int result = -1;
for( int index=0; (result == -1) && (index < nextIndex); index++) {
if(A[index].equals(Name)) {
result = index;
}
}
return result;
}
public String toString() {
String result = "";
for(int index=0; index < nextIndex; index++) {
result = result + A[index];
if((index+1) < nextIndex) {
result = result + ", ";
}
}
return result;
}
}---------------------
---------------------
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.io.IOException;
public class ScannerReadFile {
public static void main(String[] args) throws IOException {
//double a = 84.75;
// Create an instance of File for data.txt file.
File file = new File("C:\\UnderOver.dat");
try {
//
// Create a new Scanner object which will read the data from the
// file passed in. To check if there are more line to read from it
// we check by calling the scanner.hasNextLine() method. We then
// read line one by one till all line is read.
//
Scanner scanner = new Scanner(file);
Names N = new Names(22);
while (scanner.hasNext()) {
N.Add(scanner.nextLine().trim());
}
System.out.println(N);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}--------------------------------------
هذا الكود بعد التعديل
public class Numbers {
final int DEFAULT = 8;
int capacity = DEFAULT;
int nextIndex = 0;
double[] A;
public Numbers() {
A = new double[capacity];
}
public Numbers(int Capacity) {
if(Capacity < 0) {
Capacity = DEFAULT;
}
capacity = Capacity;
A = new double[capacity];
}
boolean Add(double Numb) {
boolean result = false;
if(nextIndex < capacity) {
A[nextIndex] = Numb;
nextIndex = nextIndex + 1;
result = true;
}
return result;
}
int indexOf(double Numb) {
int result = -1;
for( int index=0; (result == -1) && (index < nextIndex); index++) {
if(A[index].equals(Numb)) {
result = index;
}
}
return result;
}
public String toString() {
String result = "";
for(int index=0; index < nextIndex; index++) {
result = result + A[index];
if((index+1) < nextIndex) {
result = result + ", ";
}
}
return result;
}
}المشكلة في التعامل مع الارقام
------------------------------
الرسالة التي تضهر عند التنفيذ
1 Error
Numbers.java:35: double cannot be dereferenced
if(A[index].equals(Numb)) {------------------------------
أرجو المساعدة
