Total salary paid for java-

Source: Internet
Author: User

Company class

public class Company {
	employee[] Employee;
	Double salaries=0;
	Company (employee[] Employee) {
	this.employee=employee
	}
	Public double Salariedpay () {
		salaries=0;
		for (int i=0;i<employee.length;i++) {
			salaries=salaries+employee[i].earings ();
		}
		Return salaries
	}
}


Companysalary class

public class Companysalary {public
	static void Main (string[] args) {
		employee[] employee=new employee[29];< c16/>for (int i=0;i<employee.length;i++) {
			if (i%3==0)
				employee[i]=new weekworker ();
			else if (i%3==1)
				employee[i]=new monthworker ();
			else if (i%3==2)
				employee[i]=new yearworker ();
		}
		Company Company=new Company (employee);
		SYSTEM.OUT.PRINTLN ("Total Company Salary:" +company.salariedpay () + "Yuan");
	}


Employee class

Public abstract class Employee {public
	abstract double earings ();
}


Monthworker class

public class Monthworker extends Employee {public
	double earings () {return
		12*2300;
	}

}


Weekworker class

public class Weekworker extends Employee {public
	double earings () {return
		52*780;
	}

}

Yearworker class

public class Yearworker extends Employee {public
	double earings () {return
		12000;
	}

}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.