deyanmalinov

2. Salary Increase

Jun 9th, 2020
806
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package DPM;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Scanner;
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         int lines = Integer.parseInt(scan.nextLine());
  9.         List<Person> people = new ArrayList<>();
  10.         Person man = null;
  11.         for (int i = 0; i < lines; i++) {
  12.             String[] line = scan.nextLine().split(" ");
  13.             String fname = line[0];
  14.             String sname = line[1];
  15.             int age = Integer.parseInt(line[2]);
  16.             double salary = Double.parseDouble(line[3]);
  17.             man = new Person(fname, sname, age, salary);
  18.             people.add(man);
  19.         }
  20.         double bonus = Double.parseDouble(scan.nextLine());
  21.         for (Person person : people) {
  22.             person.increaseSalary(bonus);
  23.         }
  24.         for (Person person : people) {
  25.             System.out.println(person.toString());
  26.         }
  27.     }
  28. }
  29. ------------------------------------------------------------------------
  30. package DPM;
  31. import java.text.DecimalFormat;
  32. public class Person {
  33.     private String fname;
  34.     private String sname;
  35.     private int age;
  36.     private double salary;
  37.     public Person(String fname, String sname, int age, double salary){
  38.         this.fname=fname;
  39.         this.sname=sname;
  40.         this.age=age;
  41.         this.salary=salary;
  42.     }
  43.     public void setSalary(double salary){
  44.         this.salary=salary;
  45.     }
  46.     public void setFname(String fname){
  47.         this.fname=fname;
  48.     }
  49.     public void setSname(String sname){
  50.         this.sname=sname;
  51.     }
  52.     public void setAge(int age){
  53.         this.age=age;
  54.     }
  55.     public String getFname(){
  56.         return this.fname;
  57.     }
  58.     public String getSname(){
  59.         return this.sname;
  60.     }
  61.     public int getAge(){
  62.         return this.age;
  63.     }
  64.     public double getSalary(){
  65.         return this.salary;
  66.     }
  67.     public void increaseSalary(double bonus){
  68.         if (this.age > 30){
  69.             this.salary += this.salary * bonus/100;
  70.         }else {
  71.             this.salary += this.salary * bonus/200;
  72.         }
  73.     }
  74.     @Override
  75.     public String toString() {
  76.         DecimalFormat df = new DecimalFormat("#.0##############");
  77.         return String.format("%s %s gets %s leva",
  78.                 this.getFname(), this.getSname(), df.format(this.getSalary()));
  79.     }
  80. }
RAW Paste Data