Hello, I need help adding one overriding method and one overloading method. The main method should show
Question:
Hello, I need help adding one overriding method and one overloading method. The main method should show an instance of the class and demonstrate the correct functionality of the overriding and overloading methods.Then my main class has to stay at the bottom of the program. I am having trouble. Below is my code, thank you in advance.
import java.util.*;
class test {
// establishing variables String employ_name; double salary; // constructor test(String employ_name,double salary) { this.employ_name = employ_name; this.salary = salary; } // function get, to get the employee's name String getName() { return employ_name; } // function get, to get the employee's salary double getAnualSalary() { return salary * 12; } public String toString() { String output =""; output = output + "Name of Employee is: " + getName() + " "; output = output + "Employee's salary is : $ " + getAnualSalary(); return output; } public void display1() { System.out.println("Thank you for using the program. GoodBye"); } } class Section extends test { String section_name; Section(String nm, double sal, String snm) { super(nm,sal); section_name = snm; } String getsection_name() { return section_name; } public String toString() { System.out.println(super.toString()); return "Top earner is: " + getsection_name() +" "; } }
class Employee extends test { String job_title; Employee(String nm, double sal, String title) { super(nm,sal); job_title = title; } // get function to get job title String getjob_title() { return job_title; } public String toString() { System.out.println(super.toString()); return "Job title: " + getjob_title() +" "; } }
class Addition extends test{ Scanner scan = new Scanner(System.in); String address; int employeeAge; Addition(String employ_name, double salary, String address, int employeeAge) { super(employ_name, salary); }
public String getAddress() { return address; }
public void setAddress(String address) { System.out.println("Enter your address:"); address = scan.nextLine(); this.address = address; }
public int getEmployeeAge() { return employeeAge; }
public void setEmployeeAge(int employeeAge) { System.out.println("Enter the employee ages:"); employeeAge = scan.nextInt(); this.employeeAge = employeeAge; }
public void addInfor() { System.out.println("The emplyee age is "+ getEmployeeAge()); System.out.println("The emplyee address is "+ getAddress()); }
}
public class WK3MeeksT { public static void main(String[] args) { // variables to use in scanner tool String nameF,nameS,dname,title; double salF,salS; Scanner sc = new Scanner(System.in); System.out.print("Please input the name of the section: "); nameF = sc.nextLine(); System.out.print("Please input the total Salary for the Section: "); salF = sc.nextDouble(); System.out.print("Please input the name of the top earner: "); dname = sc.next(); sc.nextLine(); System.out.print("Please input the Employee Name: "); nameS = sc.nextLine(); System.out.print("Please input the salary: "); salS = sc.nextDouble(); System.out.print("Please input the Job Title: "); title = sc.next(); // Instant of Section Section sec = new Section(nameF,salF,dname); System.out.println("Details of Section: "); System.out.println("----------------------------------"); System.out.println(sec); // Instant of Employee Employee emp = new Employee(nameS,salS,title); System.out.println("Detail of Employee: "); System.out.println("----------------------------------"); System.out.println(emp); System.out.println(" "); //Instant Addition Addition add = new Addition(nameF, salF, dname, 0); String address = " "; int age = 0; System.out.println("More information: "); System.out.println("----------------------------------"); add.setAddress(address); add.getAddress(); add.setEmployeeAge(age); add.addInfor(); add.display1();
} }
Microsoft Visual C# An Introduction to Object-Oriented Programming
ISBN: 978-1337102100
7th edition
Authors: Joyce Farrell