السلام عليكم
اتمنى ان لا يكون التاخير جعلك تنسي الموضوع، ولكن على اي حال هذا هو الحل ان شاء الله:
اضيفي method ترجع string بدل من طباعة النتيجة بالحوار، ال class كما يلي:
//market class
import
javax.swing.JOptionPane;
public
class market {
private String name;
privateintcompany;
private String place;
public market(String s, int c, String p) {
name = s;
company = c;
place = p;
}
publicvoid dispaly() {
JOptionPane.showMessageDialog(null, "Name: " + name + "\nCompany: "
+
company + "\nPlace: " + place);
}
public String displayString() {
return"Name: " + name + "\nCompany: " + company + "\nPlace: " + place;
}
public String getname() {
returnname;
}
publicint getnocomp() {
returncompany;
}
public String getplace() {
returnplace;
}
}
واجعلي الطباعة داخل ال Markets class داخل ال main ، كما يلي:
//Markets class
import javax.swing.JOptionPane;
public
class Markets {
publicstaticvoid main(String[] args) {
market[] list = new market[4];
String t_name, t_place;
String no_comp;
int c;
int i;
for (i = 0; i <= 3; i++) {
t_name = JOptionPane.showInputDialog("Enter Name:");
no_comp = JOptionPane.showInputDialog("Enter no of company:");
t_place = JOptionPane.showInputDialog("Enter Place:");
c = Integer.parseInt(no_comp);
list = new market(t_name, c, t_place);
}
String allResult = "";
for (i = 0; i <= 3; i++) {
[i]allResult += list.displayString();
}
[i]JOptionPane.showMessageDialog(null, allResult);
}
}