+ 1
I try to create this program, and get error, can anyone help?
import java.util.*; public class ABZmainClass{ public static void main(String[] args){ //main method //creating arrayList of objects ArrayList<ABZmainClass>employee=new ArrayList<ABZmainClass>(); //adding employees employee.add(new ABZmainClass("John", 555,"Clerk", 30000)); employee.add(new ABZmainClass("Lily", 888,"IT Consultant", 40000)); //printing the output for(ABZmainClass emp:employee){ //usingforeachloop System.out.println("-----New employee details-----"); System.out.println(emp); } } }
1 Réponse
+ 1
import java.util.*;
public class ABZmainClass{
      String name, prof;
      int id, cole;
      ABZmainClass(String n,int i,String p,int c){
          this.name = n;
          this.id = i;
          this.prof = p;
          this.cole = c;
      }
      
    public String toString(){
        return "Name: " + this.name + ", Profession: " + this.prof +"\n";
    }
      
      public static void main(String[] args){ //main method
	//creating arrayList of objects
	ArrayList<ABZmainClass>employee=new ArrayList<ABZmainClass>();
	//adding employees
	employee.add(new ABZmainClass("John", 555,"Clerk", 30000));
	employee.add(new ABZmainClass("Lily", 888,"IT Consultant", 40000));
	//printing the output
	for(ABZmainClass emp:employee){ //usingforeachloop
	     System.out.println("-----New employee details-----");
	     System.out.println(emp);
	}
      }
}



