بسم الله الرحمن الرحيم
السلام عليكم ورحمة الله وبركاته
أخواني وأخواتي الأعضاء أنا واجهت مشكلة في أستدعاء Method من Class في الـ Main
إنظروا إلى كود الـ Class
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Storage {
// Instance Variables
private int ID_item; // ID number of item
private int Num_item; // Number of items
private String Name_item; // Name of item
private double Price_item; // Price the item
private int numberUsed;
Storage[] list = new Storage[50];
// Constructors
public Storage(int ID_item, String Name_item, int Num_item, double Price_item) {
this.ID_item = ID_item;
this.Num_item = Num_item;
this.Name_item = Name_item;
this.Price_item = Price_item;
}
// To read data from file ["input.txt"]
public void ReadData() {
Scanner input = null;
try {
input = new Scanner (new File("input.txt"));
}
catch(FileNotFoundException e) {
System.out.println("1. The file [input.txt] was not found");
System.exit(0);
}
while (input.hasNextLine()) {
for (int i = 0; i < list.length; ++i) {
// Checking if the item ID already exists or not
if(list.ID_item != input.nextInt()) {
// Store data form file ["input.txt"] to an array
list = new Storage(input.nextInt(), input.next(), input.nextInt(), input.nextDouble());
numberUsed++;
}else {
System.out.println("[This item name] has a duplicate ID as [Name]");
}
}
}
// Close ["input.txt"] after reading
input.close();
}وبالنسبة للكود في الـ Main
public static void main(String[] args) {
int choice;
Scanner kb = new Scanner(System.in);
Storage[] list = new Storage[50];
do {
System.out.println("1. Read data from [input.txt]");
System.out.println("2. Quit");
System.out.println("");
System.out.println("");
System.out.print("Enter The Choise [1 Or 2] : ");
do {
choice = kb.nextInt();
if(choice < 1 || choice >2)
System.out.print("Invalid Choice! Enter the choice again : ");
}while (choice < 1 || choice > 2);
switch(choice) {
case 1:
list.ReadData(); //هنا يقع الخطأ ولا أعرف كيف أربط الميثود بالمصفوفة
break;
case 2:
System.out.println();
System.out.println("Thank you For using The program");
}
}while(choice != 6);
System.out.println("Thank you For using The program");
}ارجوا التكرم منكم ومساعدتي في إيجاد الحل المناسب للكود
ودمتم سالمين