Ivelin_1936

Salary Increase

Jun 18th, 2018
106
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Main {
  2.     public static void main(String[] args) throws IOException {
  3.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  4.  
  5.         List<Person> people = new ArrayList<>();
  6.  
  7.         int inputsAmount = Integer.parseInt(reader.readLine());
  8.         for (int i = 0; i < inputsAmount; i++) {
  9.             String[] personData = reader.readLine().split("\\s+");
  10.             String firstName = personData[0];
  11.             String lastName = personData[1];
  12.             int age = Integer.parseInt(personData[2]);
  13.             double salary = Double.parseDouble(personData[3]);
  14.  
  15.             people.add(new Person(firstName, lastName, age, salary));
  16.         }
  17.  
  18.         double bonus = Double.parseDouble(reader.readLine());
  19.         for (Person person : people) {
  20.             person.increaseSalary(bonus);
  21.             System.out.println(person.toString());
  22.         }
  23.     }
  24. }
  25.  
  26. public class Person {
  27.  
  28.     private String firstName;
  29.     private String lastName;
  30.     private int age;
  31.     private double salary;
  32.  
  33.     public Person(String firstName, String lastName, int age, double salary) {
  34.         this.firstName = firstName;
  35.         this.lastName = lastName;
  36.         this.age = age;
  37.         this.salary = salary;
  38.     }
  39.  
  40.     public String getFirstName() {
  41.         return firstName;
  42.     }
  43.  
  44.     public void setFirstName(String firstName) {
  45.         this.firstName = firstName;
  46.     }
  47.  
  48.     public String getLastName() {
  49.         return lastName;
  50.     }
  51.  
  52.     public void setLastName(String lastName) {
  53.         this.lastName = lastName;
  54.     }
  55.  
  56.     public int getAge() {
  57.         return age;
  58.     }
  59.  
  60.     public void setAge(int age) {
  61.         this.age = age;
  62.     }
  63.  
  64.     public double getSalary() {
  65.         return salary;
  66.     }
  67.  
  68.     public void setSalary(double salary) {
  69.         this.salary = salary;
  70.     }
  71.  
  72.     public void increaseSalary(double bonus) {
  73.         double personalBonus = this.age >= 30 ? bonus : bonus / 2;
  74.         this.salary += this.salary * personalBonus / 100;
  75.     }
  76.  
  77.     @Override
  78.     public String toString() {
  79.         DecimalFormat df = new DecimalFormat("0.0#################");
  80.         return String.format("%s %s gets %s leva",
  81.                 this.getFirstName(),
  82.                 this.getLastName(),
  83.                 df.format(this.getSalary()));
  84.     }
  85. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×