Advertisement
vencinachev

Packet

Feb 1st, 2021
1,099
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1.  
  2. public class Packet {
  3.     private String msg;
  4.     private int number;
  5.     private double losses;
  6.    
  7.     public Packet(String msg, int number, double losses) {
  8.         this.setMessage(msg);
  9.         this.setNumber(number);
  10.         this.setLosses(losses);
  11.     }
  12.    
  13.      void setLosses(double losses) {
  14.         if (losses < 0) {
  15.             this.losses = 0;
  16.         } else if (losses > 1) {
  17.             this.losses = 1;
  18.         } else {
  19.             this.losses = losses;
  20.         }
  21.     }
  22.    
  23.     private void setNumber(int number) {
  24.         this.number = Math.abs(number);
  25.     }
  26.    
  27.     private void setMessage(String msg) {
  28.         this.msg = msg;
  29.     }
  30.    
  31.     public int getNumber() {
  32.         return this.number;
  33.     }
  34.    
  35.     public double getLosses() {
  36.         return this.losses;
  37.     }
  38.     @Override
  39.     public String toString() {
  40.         if (this.losses < 0.5) {
  41.             return "-----";
  42.         }
  43.         return this.msg;
  44.     }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement