From 8737449c248d7e5832c9c148841b3cfd6dc64573 Mon Sep 17 00:00:00 2001 From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com> Date: Tue, 5 Dec 2023 17:24:43 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BD=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CountWheels.java | 9 ++------- DrawingWheels.java | 11 ++++++++++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CountWheels.java b/CountWheels.java index e4f6bd3..c6803ae 100644 --- a/CountWheels.java +++ b/CountWheels.java @@ -6,16 +6,11 @@ public enum CountWheels{ private CountWheels(int val){ this.val = val; } - private int countWheels; + public int getCountWheels(){ return val; } - public void setCountWheels(int countWheels){ - this.countWheels = countWheels; - } - public void setEnumValue(){ - CountWheels enumvalue = CountWheels.values()[countWheels]; - } + public static CountWheels fromNumberToEnum(int number) { try{ for (CountWheels countWheels : CountWheels.values()) { diff --git a/DrawingWheels.java b/DrawingWheels.java index 4ae5258..90e8fe9 100644 --- a/DrawingWheels.java +++ b/DrawingWheels.java @@ -7,12 +7,21 @@ public class DrawingWheels{ Color color; private CountWheels _countWheels; + public void setNumWheels(int numRollers) { + if (numRollers < 4 || numRollers > 6 ){ + + _countWheels = CountWheels.fromNumberToEnum(numRollers); + return; + } + _countWheels = CountWheels.fromNumberToEnum(numRollers); + } + public DrawingWheels(Graphics g, int startPosX, int startPosY, Color color, int countWheels){ this.g = g; _startPosX = startPosX; _startPosY = startPosY; this.color = color; - _countWheels.setCountWheels(countWheels); + setNumWheels(countWheels); } public void Draw(){ switch(_countWheels){