By GokiSoft.com|
19:35 04/07/2022|
Java Basic
[Source Code] Java Basic- OOP - Tổng hợp - Quản lý sinh viên - giáo viên bằng java - C2108L
Java Basic- OOP - Tổng hợp - Quản lý sinh viên - giáo viên bằng java
#Teacher.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bt989;
import java.util.Scanner;
/**
*
* @author Diep.Tran
*/
public class Teacher extends Person{
String className;
int salary;
float totalHours;
@Override
public void inputInfo() {
super.inputInfo();
Scanner scan = new Scanner(System.in);
System.out.println("Nhap lop hoc: ");
className = scan.nextLine();
System.out.println("Nhap luong: ");
salary = Integer.parseInt(scan.nextLine());
System.out.println("Nhap tong gio day: ");
totalHours = Float.parseFloat(scan.nextLine());
}
public float getSalary() {
if(className.contains("M") ||
className.contains("L") ||
className.contains("m") ||
className.contains("l")) {
return salary * totalHours + 200000;
}
return salary * totalHours;
}
@Override
public String toString() {
return super.toString() + ", className=" + className + ", salary=" + salary + ", totalHours=" + totalHours;
}
}
#Person.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bt989;
import java.util.Scanner;
/**
*
* @author Diep.Tran
*/
public class Person {
String fullname, gender, address, birthday;
public Person() {
}
public void inputInfo() {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap ten: ");
fullname = scan.nextLine();
System.out.println("Nhap gioi tinh: ");
gender = scan.nextLine();
System.out.println("Nhap dia chi: ");
address = scan.nextLine();
System.out.println("Nhap ngay sinh: ");
birthday = scan.nextLine();
}
public void displayInfo() {
System.out.println(this);
}
@Override
public String toString() {
return "fullname=" + fullname + ", gender=" + gender + ", address=" + address + ", birthday=" + birthday;
}
public String getFullname() {
return fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
}
#Main.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bt989;
/**
*
* @author Diep.Tran
*/
public class Main {
public static void main(String[] args) {
Teacher t = new Teacher();
t.inputInfo();
t.displayInfo();
System.out.println("Luong: " + t.getSalary());
}
}
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)