Main Activity Java class
package com.apdim3.opps;
import android.os.Bundle;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.apdim3.opps.blueprintclass.Bricks;
import com.apdim3.opps.blueprintclass.Employee;
public class MainActivity extends AppCompatActivity {
TextView tvDisplay;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvDisplay = findViewById(R.id.tvDisplay);
//====================== get Name from another public Java class =========
Bricks bricks = new Bricks();
bricks.seal = "IMRAN";
tvDisplay.setText(bricks.seal);
//=============== Get Name Position and Salary form Getter and Setter =========
Employee employee1 = new Employee();
employee1.setName("IMRAN");
employee1.setPosition("CEO");
employee1.setSalary(10000);
Employee employee2 = new Employee();
employee2.setName("Jon");
employee2.setPosition("Developer");
employee2.setSalary(20000);
tvDisplay.append("\nName: "+ employee1.getName());
tvDisplay.append("\nPosition: "+employee1.getPosition());
tvDisplay.append("\nSalary: "+employee1.getSalary()+"$");
tvDisplay.append("\n\nName: "+employee2.getName());
tvDisplay.append("\nPosition: "+employee2.getPosition());
tvDisplay.append("\nSalary: "+employee2.getSalary()+"$");
//====================Get Name Position Salary from Constrictor ============
Employee employee = new Employee("AHMAD","Senior Developer",15000);
tvDisplay.append("\n\nName: "+employee.getName());
tvDisplay.append("\nPosition: "+employee.getPosition());
tvDisplay.append("\nSalary: "+employee.getSalary()+"$");
}
}
Employ Java Class
package com.apdim3.opps.blueprintclass;
import android.widget.Space;
public class Employee {
private String name;
private String position;
private int salary;
public Employee(){
}
public Employee (String empName, String empPosition, int empSalary){
this.name = empName;
this.position = empPosition;
this.salary = empSalary;
}
public void setName (String empName){
this.name = empName;
}
public void setPosition (String empPosition){
this.position = empPosition;
}
public void setSalary (int empSalary){
this.salary = empSalary;
}
public String getName (){
return name;
}
public String getPosition() {
return position;
}
public int getSalary (){
return salary;
}
}
Class 3008 to 3009
abstract Method in Java
Main Activity java code
package com.apdim3.opps;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.apdim3.opps.blueprintclass.Employee;
import com.apdim3.opps.blueprintclass.FullTimeEmployee;
import com.apdim3.opps.blueprintclass.PartTimeEmployee;
public class MainActivity extends AppCompatActivity {
TextView tvDisplay;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvDisplay = findViewById(R.id.tvDisplay);
FullTimeEmployee fEmploye = new FullTimeEmployee("IMRAN","CEO",10000);
tvDisplay.append("\nName: "+fEmploye.getName());
tvDisplay.append("\nPosition: "+fEmploye.getPosition());
tvDisplay.append("\nTotal Salary: "+fEmploye.getSalary()+"$");
tvDisplay.append("\nTex: "+fEmploye.calculateTex()+"$");
tvDisplay.append("\nFinal Salary: "+fEmploye.calculateSalary()+"$");
PartTimeEmployee pEmployee = new PartTimeEmployee("Devid","Developer",15000);
tvDisplay.append("\n\nName: "+pEmployee.getName());
tvDisplay.append("\nPosition: "+pEmployee.getPosition());
tvDisplay.append("\nTotal Salary: "+pEmployee.getSalary()+"$");
tvDisplay.append("\nTex: "+pEmployee.calculateTex()+"$");
tvDisplay.append("\nFinal Salary: "+pEmployee.calculateSalary()+"$");
}
}
Employee class java code
package com.apdim3.opps.blueprintclass;
import android.widget.Space;
public abstract class Employee {
private String name;
private String position;
private int salary;
public abstract float calculateTex();
public abstract float calculateSalary();
public Employee (String empName, String empPosition, int empSalary){
this.name = empName;
this.position = empPosition;
this.salary = empSalary;
}
public String getName (){
return name;
}
public String getPosition() {
return position;
}
public int getSalary (){
return salary;
}
}
Full-Time Employee class Java code
package com.apdim3.opps.blueprintclass;
public class FullTimeEmployee extends Employee{
public FullTimeEmployee(String empName, String empPosition, int empSalary) {
super(empName, empPosition, empSalary);
}
@Override
public float calculateTex() {
return getSalary() * 5/100;
}
@Override
public float calculateSalary() {
return getSalary() - calculateTex();
}
}
Part-Time Employee class Java code
package com.apdim3.opps.blueprintclass;
public class PartTimeEmployee extends Employee{
public PartTimeEmployee(String empName, String empPosition, int empSalary) {
super(empName, empPosition, empSalary);
}
@Override
public float calculateTex() {
return getSalary() * 10/100;
}
@Override
public float calculateSalary() {
return getSalary() - calculateTex();
}
}
Post a Comment