diff --git a/Assignments/MP3_CalebFontenot/Calendar.html b/Assignments/MP3_CalebFontenot/Calendar.html new file mode 100644 index 0000000..5c11e5e --- /dev/null +++ b/Assignments/MP3_CalebFontenot/Calendar.html @@ -0,0 +1,128 @@ + + + +Calendar.java + + + + +
/home/caleb/ASDV-Java/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/Calendar.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package mp3_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class Calendar {
+
+    public static void main(String[] args) {
+        Scanner input = new Scanner(System.in);
+        System.out.print("Enter a year: ");
+        int year = input.nextInt();
+        System.out.print("Enter the first day of the year: ");
+        int firstDay = input.nextInt();
+
+        int startDay = firstDay;
+        int numberOfDaysInMonth = 0;
+        for (int month = 1; month <= 12; month++) {
+            System.out.print("         ");
+            switch (month) {
+                case 1:
+                    System.out.println("January " + year);
+                    numberOfDaysInMonth = 31;
+                    break;
+                case 2:
+                    System.out.println("February " + year);
+                    if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
+                        numberOfDaysInMonth = 29;
+                    } else {
+                        numberOfDaysInMonth = 28;
+                    }
+                    break;
+                case 3:
+                    System.out.println("March " + year);
+                    numberOfDaysInMonth = 31;
+                    break;
+                case 4:
+                    System.out.println("April " + year);
+                    numberOfDaysInMonth = 30;
+                    break;
+                case 5:
+                    System.out.println("May " + year);
+                    numberOfDaysInMonth = 31;
+                    break;
+                case 6:
+                    System.out.println("June " + year);
+                    numberOfDaysInMonth = 30;
+                    break;
+                case 7:
+                    System.out.println("July " + year);
+                    numberOfDaysInMonth = 31;
+                    break;
+                case 8:
+                    System.out.println("August " + year);
+                    numberOfDaysInMonth = 31;
+                    break;
+                case 9:
+                    System.out.println("September " + year);
+                    numberOfDaysInMonth = 30;
+                    break;
+                case 10:
+                    System.out.println("October " + year);
+                    numberOfDaysInMonth = 31;
+                    break;
+                case 11:
+                    System.out.println("November " + year);
+                    numberOfDaysInMonth = 30;
+                    break;
+                case 12:
+                    System.out.println("December " + year);
+                    numberOfDaysInMonth = 31;
+                    break;
+            }
+            System.out.println("------------------------------");
+            System.out.println(" Sun Mon Tue Wed Thu Fri Sat");
+            int i = 0;
+            for (i = 0; i < startDay; i++) {
+                System.out.print("    ");
+            }
+
+            for (i = 1; i <= numberOfDaysInMonth; i++) {
+                if (i < 10) {
+                    System.out.print("   " + i);
+                } else {
+                    System.out.print("  " + i);
+                }
+
+                if ((i + startDay) % 7 == 0) {
+                    System.out.println();
+                }
+            }
+            System.out.println();
+            System.out.println();
+            startDay = (startDay + numberOfDaysInMonth) % 7;
+        }
+    }
+}
+
+
+ diff --git a/Assignments/MP3_CalebFontenot/CalendarWhile.html b/Assignments/MP3_CalebFontenot/CalendarWhile.html new file mode 100644 index 0000000..532adb8 --- /dev/null +++ b/Assignments/MP3_CalebFontenot/CalendarWhile.html @@ -0,0 +1,90 @@ + + + +CalendarWhile.java + + + + +
/home/caleb/ASDV-Java/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/CalendarWhile.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package mp3_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class CalendarWhile {
+    public static void main(String[] args) {
+        Scanner input = new Scanner(System.in);
+        System.out.print("Enter a year: ");
+        int year = input.nextInt();
+        System.out.print("Enter the first day of the year: ");
+        int firstDay = input.nextInt();
+        System.out.println();
+        System.out.println();
+        
+        int startDay = firstDay;
+        int numberOfDaysInMonth = 0;
+        int month = 1;
+        while (month <= 12) {
+            System.out.print("         "); 
+            switch (month) {
+                case 1: System.out.println("January " + year); numberOfDaysInMonth = 31; break;
+                case 2: System.out.println("February " + year);
+                    if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) numberOfDaysInMonth = 29;
+                    else numberOfDaysInMonth = 28;
+                    break;
+                case 3: System.out.println("March " + year); numberOfDaysInMonth = 31; break;
+                case 4: System.out.println("April " + year); numberOfDaysInMonth = 30; break;
+                case 5: System.out.println("May " + year); numberOfDaysInMonth = 31; break;
+                case 6: System.out.println("June " + year); numberOfDaysInMonth = 30; break;
+                case 7: System.out.println("July " + year); numberOfDaysInMonth = 31; break;
+                case 8: System.out.println("August " + year); numberOfDaysInMonth = 31; break;
+                case 9: System.out.println("September " + year); numberOfDaysInMonth = 30; break;
+                case 10: System.out.println("October " + year); numberOfDaysInMonth = 31; break;
+                case 11: System.out.println("November " + year); numberOfDaysInMonth = 30; break;
+                case 12: System.out.println("December " + year); numberOfDaysInMonth = 31; break;
+            }
+            System.out.println("------------------------------");
+            System.out.println(" Sun Mon Tue Wed Thu Fri Sat");
+            int i = 0;
+            for (i = 0; i < startDay; i++) {
+                System.out.print("    ");
+            }
+            for (i = 1; i <= numberOfDaysInMonth; i++) {
+                if (i < 10) System.out.print("   " + i);
+                else System.out.print("  " + i);
+            
+            if ((i + startDay) % 7 == 0) {
+                System.out.println();
+            }
+            }
+            System.out.println();
+            System.out.println();
+            startDay = (startDay + numberOfDaysInMonth) % 7;
+            month++;
+        } 
+    }
+}
+
+
+ diff --git a/Assignments/MP3_CalebFontenot/FindHighestScore.html b/Assignments/MP3_CalebFontenot/FindHighestScore.html new file mode 100644 index 0000000..5ba65ce --- /dev/null +++ b/Assignments/MP3_CalebFontenot/FindHighestScore.html @@ -0,0 +1,60 @@ + + + +FindHighestScore.java + + + + +
/home/caleb/ASDV-Java/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/FindHighestScore.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package mp3_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class FindHighestScore {
+    public static void main(String[] args)
+    {
+        Scanner input = new Scanner(System.in);
+        System.out.print("Enter the number of students: ");
+        int numOfStudents = input.nextInt();
+        System.out.print("Enter a student name: ");
+        String student1 = input.next();
+        System.out.print("Enter a student score: ");
+        double score1 = input.nextDouble();
+        for (int i = 0; i < numOfStudents - 1; i++) {
+            System.out.print("Enter a student name: ");
+            String student = input.next();
+            System.out.print("Enter a student score: ");
+            double score = input.nextDouble();
+            if (score > score1) {
+                student1 = student;
+                score1 = score;
+            }
+        }
+        System.out.println("Top student " + student1 + "'s score is " + score1);
+    }
+}
+
+
+ diff --git a/Assignments/MP3_CalebFontenot/FindHighestScoreDoWhile.html b/Assignments/MP3_CalebFontenot/FindHighestScoreDoWhile.html new file mode 100644 index 0000000..d12e73f --- /dev/null +++ b/Assignments/MP3_CalebFontenot/FindHighestScoreDoWhile.html @@ -0,0 +1,61 @@ + + + +FindHighestScoreDoWhile.java + + + + +
/home/caleb/ASDV-Java/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/FindHighestScoreDoWhile.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package mp3_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class FindHighestScoreDoWhile {
+    public static void main(String[] args)
+    {
+        int i = 0;
+        String student1 = "";
+        double score1 = 0;
+        
+        Scanner input = new Scanner(System.in);
+        System.out.print("Enter the number of students: ");
+        int numOfStudents = input.nextInt();
+        do  {
+            System.out.print("Enter a student name: ");
+            String student = input.next();
+            System.out.print("Enter a student score: ");
+            double score = input.nextDouble();
+            if (score > score1) {
+                student1 = student;
+                score1 = score;
+            } 
+            i++;
+        } while (i < numOfStudents);
+        System.out.println("Top student " + student1 + "'s score is " + score1);
+    }
+}
+
+
+ diff --git a/Assignments/MP3_CalebFontenot/FindHighestScoreWhile.html b/Assignments/MP3_CalebFontenot/FindHighestScoreWhile.html new file mode 100644 index 0000000..2afe5ed --- /dev/null +++ b/Assignments/MP3_CalebFontenot/FindHighestScoreWhile.html @@ -0,0 +1,63 @@ + + + +FindHighestScoreWhile.java + + + + +
/home/caleb/ASDV-Java/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/FindHighestScoreWhile.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package mp3_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class FindHighestScoreWhile {
+    public static void main(String[] args)
+    {
+        int i = 0;
+        
+        Scanner input = new Scanner(System.in);
+        System.out.print("Enter the number of students: ");
+        int numOfStudents = input.nextInt();
+        System.out.print("Enter a student name: ");
+        String student1 = input.next();
+        System.out.print("Enter a student score: ");
+        double score1 = input.nextDouble();
+        while (i < numOfStudents - 1) {
+            System.out.print("Enter a student name: ");
+            String student = input.next();
+            System.out.print("Enter a student score: ");
+            double score = input.nextDouble();
+            if (score > score1) {
+                student1 = student;
+                score1 = score;
+            }
+            i++;
+        }
+        System.out.println("Top student " + student1 + "'s score is " + score1);
+    }
+}
+
+
+ diff --git a/Assignments/MP3_CalebFontenot/FindTwoHighestScores.html b/Assignments/MP3_CalebFontenot/FindTwoHighestScores.html new file mode 100644 index 0000000..5e2a791 --- /dev/null +++ b/Assignments/MP3_CalebFontenot/FindTwoHighestScores.html @@ -0,0 +1,71 @@ + + + +FindTwoHighestScores.java + + + + +
/home/caleb/ASDV-Java/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/FindTwoHighestScores.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package mp3_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class FindTwoHighestScores {
+
+    public static void main(String[] args) {
+        // Create scanner
+        Scanner input = new Scanner(System.in);
+
+        // Define variables
+        double highScore1 = 0, highScore2 = 0, score;
+        String bestStudent1 = "", bestStudent2 = "", student;
+        int numberToIterate = 0;
+        
+        // Compute
+        System.out.print("Enter the number of students: ");
+        numberToIterate = input.nextInt();
+        for (int i = 0; i != numberToIterate; i++) {
+            System.out.print("Enter a student name: ");
+            student = input.next();
+            System.out.print("Enter " + student + "'s score: ");
+            score = input.nextDouble();
+
+            if (score > highScore1) { // New high score detected
+
+                if (highScore1 != 0) {
+                    highScore2 = highScore1; // assign highScore1 to highScore2
+                    bestStudent2 = bestStudent1;
+                }
+                highScore1 = score; // assign current score to high score
+                bestStudent1 = student;
+            }
+        }
+        System.out.println("Best score belongs to " + bestStudent1 + ", with a score of " + highScore1);
+        System.out.println("Next best score belongs to " + bestStudent2 + ", with a score of " + highScore2);
+    }
+}
+
+
+ diff --git a/Assignments/MP3_CalebFontenot/FindTwoHighestScoresDoWhile.html b/Assignments/MP3_CalebFontenot/FindTwoHighestScoresDoWhile.html new file mode 100644 index 0000000..280943b --- /dev/null +++ b/Assignments/MP3_CalebFontenot/FindTwoHighestScoresDoWhile.html @@ -0,0 +1,73 @@ + + + +FindTwoHighestScoresDoWhile.java + + + + +
/home/caleb/ASDV-Java/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/FindTwoHighestScoresDoWhile.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package mp3_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class FindTwoHighestScoresDoWhile {
+
+    public static void main(String[] args) {
+        // Create scanner
+        Scanner input = new Scanner(System.in);
+
+        // Define variables
+        double highScore1 = 0, highScore2 = 0, score;
+        String bestStudent1 = "", bestStudent2 = "", student;
+        int numberToIterate = 0;
+        
+        // Compute
+        System.out.print("Enter the number of students: ");
+        numberToIterate = input.nextInt();
+        int i = 0;
+        do {
+            System.out.print("Enter a student name: ");
+            student = input.next();
+            System.out.print("Enter " + student + "'s score: ");
+            score = input.nextDouble();
+
+            if (score > highScore1) { // New high score detected
+
+                if (highScore1 != 0) {
+                    highScore2 = highScore1; // assign highScore1 to highScore2
+                    bestStudent2 = bestStudent1;
+                }
+                highScore1 = score; // assign current score to high score
+                bestStudent1 = student;
+            }
+            i++;
+        } while (i != numberToIterate);
+        System.out.println("Best score belongs to " + bestStudent1 + ", with a score of " + highScore1);
+        System.out.println("Next best score belongs to " + bestStudent2 + ", with a score of " + highScore2);
+    }
+}
+
+
+ diff --git a/Assignments/MP3_CalebFontenot/FindTwoHighestScoresWhile.html b/Assignments/MP3_CalebFontenot/FindTwoHighestScoresWhile.html new file mode 100644 index 0000000..caac42b --- /dev/null +++ b/Assignments/MP3_CalebFontenot/FindTwoHighestScoresWhile.html @@ -0,0 +1,73 @@ + + + +FindTwoHighestScoresWhile.java + + + + +
/home/caleb/ASDV-Java/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/FindTwoHighestScoresWhile.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package mp3_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class FindTwoHighestScoresWhile {
+
+    public static void main(String[] args) {
+        // Create scanner
+        Scanner input = new Scanner(System.in);
+
+        // Define variables
+        double highScore1 = 0, highScore2 = 0, score;
+        String bestStudent1 = "", bestStudent2 = "", student;
+        int numberToIterate = 0;
+        
+        // Compute
+        System.out.print("Enter the number of students: ");
+        numberToIterate = input.nextInt();
+        int i = 0;
+        while (i != numberToIterate) {
+            System.out.print("Enter a student name: ");
+            student = input.next();
+            System.out.print("Enter " + student + "'s score: ");
+            score = input.nextDouble();
+
+            if (score > highScore1) { // New high score detected
+
+                if (highScore1 != 0) {
+                    highScore2 = highScore1; // assign highScore1 to highScore2
+                    bestStudent2 = bestStudent1;
+                }
+                highScore1 = score; // assign current score to high score
+                bestStudent1 = student;
+            }
+            i++;
+        }
+        System.out.println("Best score belongs to " + bestStudent1 + ", with a score of " + highScore1);
+        System.out.println("Next best score belongs to " + bestStudent2 + ", with a score of " + highScore2);
+    }
+}
+
+
+ diff --git a/Assignments/MP3_CalebFontenot/GCD.html b/Assignments/MP3_CalebFontenot/GCD.html new file mode 100644 index 0000000..036a5f1 --- /dev/null +++ b/Assignments/MP3_CalebFontenot/GCD.html @@ -0,0 +1,50 @@ + + + +GCD.java + + + + +
/home/caleb/ASDV-Java/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/GCD.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package mp3_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class GCD {
+    public static void main(String[] args) {
+        java.util.Scanner input = new java.util.Scanner(System.in);
+        System.out.print("Enter the first number: ");
+        int n1 = input.nextInt();
+        System.out.print("Enter the second number: ");
+        int n2 = input.nextInt();
+        
+        int d = (n1 < n2) ? n1 : n2;
+        for (; d >= 1; d--)
+            if ((n1 % d == 0) && (n2 % d == 0))
+                break;
+        System.out.println("GCD of " + n1 + " and " + n2 + " is " + d);
+    }
+}
+
+
+ diff --git a/Assignments/MP3_CalebFontenot/GCDDoWhile.html b/Assignments/MP3_CalebFontenot/GCDDoWhile.html new file mode 100644 index 0000000..851cdc0 --- /dev/null +++ b/Assignments/MP3_CalebFontenot/GCDDoWhile.html @@ -0,0 +1,54 @@ + + + +GCDDoWhile.java + + + + +
/home/caleb/ASDV-Java/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/GCDDoWhile.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package mp3_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class GCDDoWhile {
+
+    public static void main(String[] args) {
+        java.util.Scanner input = new java.util.Scanner(System.in);
+        System.out.print("Enter the first number: ");
+        int n1 = input.nextInt();
+        System.out.print("Enter the second number: ");
+        int n2 = input.nextInt();
+
+        int d = (n1 < n2) ? n1 : n2;
+        do {
+            if ((n1 % d == 0) && (n2 % d == 0)) {
+                break;
+            }
+            d--;
+        } while (d >= 1);
+        System.out.println("GCD of " + n1 + " and " + n2 + " is " + d);
+    }
+}
+
+
+ diff --git a/Assignments/MP3_CalebFontenot/GCDWhile.html b/Assignments/MP3_CalebFontenot/GCDWhile.html new file mode 100644 index 0000000..5bec5aa --- /dev/null +++ b/Assignments/MP3_CalebFontenot/GCDWhile.html @@ -0,0 +1,54 @@ + + + +GCDWhile.java + + + + +
/home/caleb/ASDV-Java/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/GCDWhile.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package mp3_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class GCDWhile {
+
+    public static void main(String[] args) {
+        java.util.Scanner input = new java.util.Scanner(System.in);
+        System.out.print("Enter the first number: ");
+        int n1 = input.nextInt();
+        System.out.print("Enter the second number: ");
+        int n2 = input.nextInt();
+
+        int d = (n1 < n2) ? n1 : n2;
+        while (d >= 1) {
+            if ((n1 % d == 0) && (n2 % d == 0)) {
+                break;
+            }
+            d--;
+        }
+        System.out.println("GCD of " + n1 + " and " + n2 + " is " + d);
+    }
+}
+
+
+ diff --git a/Assignments/MP3_CalebFontenot/Stats.html b/Assignments/MP3_CalebFontenot/Stats.html new file mode 100644 index 0000000..0cc07b8 --- /dev/null +++ b/Assignments/MP3_CalebFontenot/Stats.html @@ -0,0 +1,96 @@ + + + +Stats.java + + + + +
/home/caleb/ASDV-Java/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/Stats.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package mp3_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class Stats {
+
+    public static void main(String[] args)
+    {
+        // Create scanner
+        Scanner input = new Scanner(System.in);
+        // Define variables
+        double mean = 0; //It's twice as mean
+        double inputSum = 0, numberOfTimesRun = 0, inputPow = 0, deviation = 0;
+        String userInput = "";
+
+        // Prompt for input
+        do {
+            System.out.println("Press Y/y to enter a series of numbers or Q/q to quit.");
+            System.out.println("Current sum: " + inputSum);
+            userInput = input.next();
+                if (userInput.toLowerCase().equals("y")) {
+                    try {
+                        do {
+                            System.out.print("Please enter a series of numbers; Type '-1' to quit (no quotes, you doofus!): ");
+                            userInput = input.next();
+                            if (Double.parseDouble(userInput) != -1) {
+                                inputSum += Double.parseDouble(userInput);
+                                inputPow += Math.pow(Double.parseDouble(userInput), 2);
+                                numberOfTimesRun++; // counter to store number of times we've added to input sum
+                            }
+                            if (numberOfTimesRun == 0) {
+                                System.out.println("No numbers entered!");
+                            }
+                            System.out.println("Current sum: " + inputSum);
+                            System.out.println("Input sum^2: " + inputPow);
+                        } while (Double.parseDouble(userInput) != -1);
+                    } catch (Exception e) {
+                        System.out.println("Invalid input!");
+                    }
+                
+            } else {
+                System.out.println("Invalid input!");
+            }
+                // Calculate mean
+                mean = inputSum / numberOfTimesRun;
+                // Calculate deviation
+                if (numberOfTimesRun == 1) { // if the loop has only run once,  don't bother calculating it, because the deviation is zero.
+                    deviation = 0;
+                } else {
+                    deviation = Math.sqrt((inputPow - (Math.pow(inputSum, 2) / numberOfTimesRun)) / (numberOfTimesRun - 1));
+                }
+                System.out.println();
+                System.out.println("The mean is: " + mean);
+                System.out.println("The deviation is: " + deviation);
+
+            }
+            while (!(userInput.toLowerCase().equals("q")));
+        }
+    }
+
+
+ diff --git a/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/Stats.java b/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/Stats.java index bcb3fae..9ab6bbf 100644 --- a/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/Stats.java +++ b/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/Stats.java @@ -12,7 +12,8 @@ import java.util.Scanner; */ public class Stats { - public static void main(String[] args) { + public static void main(String[] args) + { // Create scanner Scanner input = new Scanner(System.in); // Define variables @@ -25,32 +26,42 @@ public class Stats { System.out.println("Press Y/y to enter a series of numbers or Q/q to quit."); System.out.println("Current sum: " + inputSum); userInput = input.next(); - if (userInput.toLowerCase().equals("y")) { - try { - do { - System.out.print("Please enter a series of numbers; Type '-1' to quit (no quotes, you doofus!): "); - userInput = input.next(); - if (Double.parseDouble(userInput) != -1) { - inputSum += Double.parseDouble(userInput); - inputPow += Math.pow(Double.parseDouble(userInput), 2); - numberOfTimesRun++; // counter to store number of times we've added to input sum - } - System.out.println("Current sum: " + inputSum); - System.out.println("Input sum^2: " + inputPow); - } while (Double.parseDouble(userInput) != -1); - } catch (Exception e) { - System.out.println("Invalid input!"); - } + if (userInput.toLowerCase().equals("y")) { + try { + do { + System.out.print("Please enter a series of numbers; Type '-1' to quit (no quotes, you doofus!): "); + userInput = input.next(); + if (Double.parseDouble(userInput) != -1) { + inputSum += Double.parseDouble(userInput); + inputPow += Math.pow(Double.parseDouble(userInput), 2); + numberOfTimesRun++; // counter to store number of times we've added to input sum + } + if (numberOfTimesRun == 0) { + System.out.println("No numbers entered!"); + } + System.out.println("Current sum: " + inputSum); + System.out.println("Input sum^2: " + inputPow); + } while (Double.parseDouble(userInput) != -1); + } catch (Exception e) { + System.out.println("Invalid input!"); + } + + } else { + System.out.println("Invalid input!"); } - // Calculate mean - mean = inputSum / numberOfTimesRun; - // Calculate deviation - deviation = ((numberOfTimesRun - 1) / (inputPow - (Math.pow(inputSum, 2) / numberOfTimesRun))); - - System.out.println(); - System.out.println("The mean is: " + mean); - System.out.println("The deviation is: " + deviation); + // Calculate mean + mean = inputSum / numberOfTimesRun; + // Calculate deviation + if (numberOfTimesRun == 1) { // if the loop has only run once, don't bother calculating it, because the deviation is zero. + deviation = 0; + } else { + deviation = Math.sqrt((inputPow - (Math.pow(inputSum, 2) / numberOfTimesRun)) / (numberOfTimesRun - 1)); + } + System.out.println(); + System.out.println("The mean is: " + mean); + System.out.println("The deviation is: " + deviation); - } while (!(userInput.toLowerCase().equals("q"))); + } + while (!(userInput.toLowerCase().equals("q"))); + } } -} diff --git a/ZIPs/MP3_CalebFontenot.zip b/ZIPs/MP3_CalebFontenot.zip new file mode 100644 index 0000000..a8bb36f Binary files /dev/null and b/ZIPs/MP3_CalebFontenot.zip differ