Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Packet {
- private String msg;
- private int number;
- private double losses;
- public Packet(String msg, int number, double losses) {
- this.setMessage(msg);
- this.setNumber(number);
- this.setLosses(losses);
- }
- void setLosses(double losses) {
- if (losses < 0) {
- this.losses = 0;
- } else if (losses > 1) {
- this.losses = 1;
- } else {
- this.losses = losses;
- }
- }
- private void setNumber(int number) {
- this.number = Math.abs(number);
- }
- private void setMessage(String msg) {
- this.msg = msg;
- }
- public int getNumber() {
- return this.number;
- }
- public double getLosses() {
- return this.losses;
- }
- @Override
- public String toString() {
- if (this.losses < 0.5) {
- return "-----";
- }
- return this.msg;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement