aspose file tools*
The moose likes Java in General and the fly likes please check this code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "please check this code" Watch "please check this code" New topic
Author

please check this code

anilkumar choudary
Greenhorn

Joined: Jun 15, 2006
Posts: 6
class Directory {
Directory dir;
File[] f;
...

boolean isDirectory() {
return f == null;
}
boolean isFile() {
return f != null;
}
File getFile(int i) {
if (isFile())
return f[i];
return null'
}
Directory getDirectory() {
if (isDirectory())
return dir;
return null;
}
....
}



class Employee {
String name;
double salary;
Employee(String n, double s){
name = n;
salary = s;
}
String getName() {
return name;
}
double getSalary() {
return salary;
}
public String toString() {
return "Employee " + name;
}
}
class Manager {
Manager mgr;
Employee[] ely;
String dept;
Manager(Manager mgr,Employee[] e, String d ) {
this(e, d);
this.mgr = mgr;
}

Manager(Employee[] e, String d) {
ely = e;
dept =d;
}
String getDept() {
return dept;
}
Manager getManager() {
return mgr;
}
Employee[] getEmployee() {
return ely;
}
public String toString() {
return dept + " manager";
}
}

class Test {
public static void main(String[] args) {
Employee[] e1 = {new Employee("Aaron", 50),
new Employee("Betty", 60)};
Manager m1 = new Manager(e1, "Accounting");

Employee[] e2 = {new Employee("Cathy", 70),
new Employee("Dan", 80),
new Employee("Eliz", 90)};
Manager m2 = new Manager(m1, e2, "Production");

System.out.println(m2);
Employee[] emp = m2.getEmployee();
if (emp != null)
for (int k = 0; k < emp.length; k++)
System.out.println(" "+emp[k]+" Salary: $"+ emp[k].getSalary());
Manager m = m2.getManager();
System.out.println(" " + m);
if (m!= null) {
Employee[] emps = m.getEmployee();
if (emps != null)
for (int k = 0; k < emps.length; k++)
System.out.println(" " + emps[k]+" Salary: $"+ emps[k].getSalary());

}
}
}


output
C:\> java Test
Production manager
Employee Cathy Salary: $70.0
Employee Dan Salary: $80.0
Employee Eliz Salary: $90.0
Accounting manager
Employee Aaron Salary: $50.0
Employee Betty Salary: $60.0




why is the output like this first it should call the accounting manager then it should call the production manager because first we called with manager m1 so say the reason for this please
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41508
    
  53
Welcome to JavaRanch.

I'm not following your reasoning. First you print m2 -the production mgr-, then the employess, then m2's manager -the accounting mgr-, then that persons employees. Looks fine to me.

What do you mean by
first we called with manager m1
? You're starting with m2, not m1.
[ June 15, 2006: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: please check this code