java - How do I return values from certain type of array list? -


is program doable getters or print statements, or should consider doing differently?

if i'm doing using getter no constructor, doesn't make sense me. so, believe make more sense standpoint of print statement. i'm assuming don't need make new class.

i think if easy, exercise have been earlier in textbook:

exercise 129:

in program fragment below, each of employees in employee database stored in arraylist. complete program names of employees output.

public class mainclass {   public static void main( string[] args )   {     arraylist<employee> employees = new arraylist<employee>();  employees.add( new teacher( "fred thompkins", 55, 525 ) ); employees.add( new salesassistant( "eric washington", 7, 72 ) ); employees.add( new military( "albert costa", 236237, "navy", "seaman" ) ); employees.add( new teacher( "jane austin", 724, 92 ) ); employees.add( new salesassistant( "jane black", 91, 295 ) ); employees.add( new employee( "scott black", 23 ) ); employees.add( new salesparttime( "janice dell", 552, 501, 8.0 ) );       ( employee e : employees )      {        }      } } 

it's simples that. have create getter name, , print it.

for ( employee e : employees ) {     system.out.println(e.getname()); } 

alternatively, can override tostring method of employee

@override  public string tostring() {      return this.name; } 

and then, call

for ( employee e : employees ) {     system.out.println(e); } 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -