From 7acd4c1cff11e2c5d6f9951cda21b23e86f77926 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Fri, 4 Oct 2019 10:55:25 -0500 Subject: Rename Lab file --- csci1913/Java/Driver.java | 101 --------------------------------------- csci1913/Java/lab4_strap012.java | 101 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 101 deletions(-) delete mode 100644 csci1913/Java/Driver.java create mode 100644 csci1913/Java/lab4_strap012.java diff --git a/csci1913/Java/Driver.java b/csci1913/Java/Driver.java deleted file mode 100644 index de3f2f6..0000000 --- a/csci1913/Java/Driver.java +++ /dev/null @@ -1,101 +0,0 @@ -// DRIVER. The MAIN method has tests for your class ZILLION. Each test has a -// comment that shows what the test should print if your code is correct. It -// also has the number of points you will receive if the test is successful. -// These tests are worth a total of 25 points. - -class Zillion { - private int s; - private int[] number; - public Zillion(int size) { - number = new int[size]; - s = size; - } - public void increment(){ - int n = 0; - boolean isCorrect = false; - while (isCorrect==false) { - number[n]+=1; - if (number[n] >= 10) { - number[n]=0; - if (n<(s-1)) { - n+=1; - } - else { - isCorrect = true; - } - } - else { - isCorrect=true; - } - } - - } - public String toString(){ - String test = ""; - for (int n=(s-1); n>=0; n-=1) { - test+=number[n]; - } - return test; - } -} - -class Driver -{ - public static void main(String[] args) - { - Zillion z = new Zillion(2); - System.out.println(z); // 00 2 points - - z.increment(); - System.out.println(z); // 01 2 points - - z.increment(); - System.out.println(z); // 02 2 points - - z.increment(); - z.increment(); - z.increment(); - z.increment(); - z.increment(); - z.increment(); - z.increment(); - z.increment(); - - System.out.println(z); // 10 2 points - z.increment(); - System.out.println(z); // 11 2 points - - z = new Zillion(4); - System.out.println(z); // 0000 2 points - - for (int j = 1; j <= 999; j += 1) - { - z.increment(); - } - System.out.println(z); // 0999 2 points - - z.increment(); - System.out.println(z); // 1000 2 points - - for (int j = 1; j <= 999; j += 1) - { - z.increment(); - } - System.out.println(z); // 1999 2 points - - z.increment(); - System.out.println(z); // 2000 2 points - - for (int j = 1; j <= 7999; j += 1) - { - z.increment(); - } - System.out.println(z); // 9999 2 points - - z.increment(); - System.out.println(z); // 0000 2 points - - z.increment(); - System.out.println(z); // 0001 1 point - } -} diff --git a/csci1913/Java/lab4_strap012.java b/csci1913/Java/lab4_strap012.java new file mode 100644 index 0000000..de3f2f6 --- /dev/null +++ b/csci1913/Java/lab4_strap012.java @@ -0,0 +1,101 @@ +// DRIVER. The MAIN method has tests for your class ZILLION. Each test has a +// comment that shows what the test should print if your code is correct. It +// also has the number of points you will receive if the test is successful. +// These tests are worth a total of 25 points. + +class Zillion { + private int s; + private int[] number; + public Zillion(int size) { + number = new int[size]; + s = size; + } + public void increment(){ + int n = 0; + boolean isCorrect = false; + while (isCorrect==false) { + number[n]+=1; + if (number[n] >= 10) { + number[n]=0; + if (n<(s-1)) { + n+=1; + } + else { + isCorrect = true; + } + } + else { + isCorrect=true; + } + } + + } + public String toString(){ + String test = ""; + for (int n=(s-1); n>=0; n-=1) { + test+=number[n]; + } + return test; + } +} + +class Driver +{ + public static void main(String[] args) + { + Zillion z = new Zillion(2); + System.out.println(z); // 00 2 points + + z.increment(); + System.out.println(z); // 01 2 points + + z.increment(); + System.out.println(z); // 02 2 points + + z.increment(); + z.increment(); + z.increment(); + z.increment(); + z.increment(); + z.increment(); + z.increment(); + z.increment(); + + System.out.println(z); // 10 2 points + z.increment(); + System.out.println(z); // 11 2 points + + z = new Zillion(4); + System.out.println(z); // 0000 2 points + + for (int j = 1; j <= 999; j += 1) + { + z.increment(); + } + System.out.println(z); // 0999 2 points + + z.increment(); + System.out.println(z); // 1000 2 points + + for (int j = 1; j <= 999; j += 1) + { + z.increment(); + } + System.out.println(z); // 1999 2 points + + z.increment(); + System.out.println(z); // 2000 2 points + + for (int j = 1; j <= 7999; j += 1) + { + z.increment(); + } + System.out.println(z); // 9999 2 points + + z.increment(); + System.out.println(z); // 0000 2 points + + z.increment(); + System.out.println(z); // 0001 1 point + } +} -- cgit v1.2.3