From ab0c8686b4bf5e45d25e78d504a089f759b50dd1 Mon Sep 17 00:00:00 2001 From: patel-nikhil Date: Mon, 27 Jan 2020 22:30:39 -0500 Subject: [PATCH 1/2] Added counter class --- Counter.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Counter.java diff --git a/Counter.java b/Counter.java new file mode 100644 index 0000000..c8ef943 --- /dev/null +++ b/Counter.java @@ -0,0 +1,20 @@ +package samples; + +import sl4j.logger.log; + +public class Counter { + private int value; + + public Counter() { + this.value = 0; + log.log("Counter created"); + } + + public int increment(){ + return ++this.value; + } + + public int reset(){ + return this.value = 0; + } +} From 18f66eb4f1784758e43bc168bae789165cbc6410 Mon Sep 17 00:00:00 2001 From: patel-nikhil Date: Mon, 27 Jan 2020 22:37:19 -0500 Subject: [PATCH 2/2] Made counter static and removed logging for production --- Counter.java | 27 +++++++++++++++------------ Example_v0.java | 11 ++++------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Counter.java b/Counter.java index c8ef943..8d33696 100644 --- a/Counter.java +++ b/Counter.java @@ -1,20 +1,23 @@ -package samples; - -import sl4j.logger.log; +package sample; public class Counter { - private int value; + private static int value = 0; - public Counter() { - this.value = 0; - log.log("Counter created"); - } + /** + * Creates a counter instance + * @return Counter instance + */ + private Counter() {} - public int increment(){ - return ++this.value; + /** + * Increments the counter value + * @return counter value + */ + public static int increment(){ + return ++value; } - public int reset(){ - return this.value = 0; + public static void reset(){ + value = 0; } } diff --git a/Example_v0.java b/Example_v0.java index 8d5507a..c110938 100644 --- a/Example_v0.java +++ b/Example_v0.java @@ -1,19 +1,16 @@ -package controller; +package sample; import java.util.Random; +import java.awt.font.*; public class A { - private static int Z; + private static final int Z; public A() { A.Z = 5; } - public int fcn(){ - return A.Z * 5; - } - - public int test(){ + public int production(){ return A.Z * 5; } }