kirbybeam Posted December 3, 2005 Share Posted December 3, 2005 // I'll give each program it's own post import cs1.Keyboard; public class Manipulation // This is the starting one { public static void main(String[] args) { int choice = 0; int calculator = 0;// for exiting the program System.out.println("(^_^)WELCOME TO KIRBY'S CALCULATOR PROGRAM!!!(^_^)"); System.out.println(); System.out.println(); Choices.displayMessage(); //Displays a list of choices choice = Keyboard.readInt(); while (choice < -1 || choice > 5 || choice == 0) // enter a valid number { System.out.println(); System.out.println("Invalid number entered!"); Choices.displayMessage(); choice = Keyboard.readInt(); } while (calculator != -10) { while (choice < -1 || choice > 5 || choice == 0) // enter a valid number { System.out.println(); System.out.println("Try again!"); Choices.displayMessage(); choice = Keyboard.readInt(); } while (choice == 1) { DecimalBinaryOperations.doTheOperations(); Choices.displayMessage(); choice = Keyboard.readInt(); } while (choice == 2) { FractionalBinaryOperations.doTheOperations(); Choices.displayMessage(); choice = Keyboard.readInt(); } while (choice == 3) { Formulas.quadratic(); Choices.displayMessage(); choice = Keyboard.readInt(); } while (choice == 4) { Formulas.cramerRule(); Choices.displayMessage(); choice = Keyboard.readInt(); } while (choice == 5) { Averages.findAverage(); Choices.displayMessage(); choice = Keyboard.readInt(); } while (choice == -1) { System.out.println("Are you sure you want to quit? Type -10 for yes: "); calculator = Keyboard.readInt(); choice = 0; } } System.out.println("(^_^) That was fun. See you again!(^_^)"); } } Link to comment Share on other sites More sharing options...
kirbybeam Posted December 3, 2005 Author Share Posted December 3, 2005 public class Choices { public static void displayMessage() { System.out.println("What would you like to do now?"); System.out.println("Type 1 for Decimal Binary Operations"); System.out.println("Type 2 for Fractional Binary Operations"); System.out.println("Type 3 for the Quadratic Formula"); System.out.println("Type 4 for Cramer's Rule"); System.out.println("Type 5 for Averages"); System.out.println("Type -1 to quit"); } } Link to comment Share on other sites More sharing options...
kirbybeam Posted December 3, 2005 Author Share Posted December 3, 2005 import cs1.Keyboard; import java.util.*; public class DecimalBinaryOperations { public static void doTheOperations() { double answer, digits, addAnswer, subtractAnswer,multiplyAnswer, divideAnswer, powerAnswer; System.out.println("You have selected Decimal Binary Operations"); System.out.println(); System.out.print("Enter your first number: "); answer = Keyboard.readDouble(); System.out.println(); System.out.print("Enter your second number: "); digits = Keyboard.readDouble(); System.out.println(); addAnswer = answer + digits; subtractAnswer = answer - digits; multiplyAnswer = answer * digits; divideAnswer = answer / digits; powerAnswer = Math.pow(answer, digits); System.out.println(answer + " + " + digits + " = " + addAnswer); System.out.println(answer + " - " + digits + " = " + subtractAnswer); System.out.println(answer + " * " + digits + " = " + multiplyAnswer); System.out.println(answer + " / " + digits + " = " + divideAnswer); System.out.println(answer + "^" + digits + " = " + powerAnswer); System.out.println(); } } Link to comment Share on other sites More sharing options...
LP Posted December 3, 2005 Share Posted December 3, 2005 whats the use... :roll: Start>Run>Calc Link to comment Share on other sites More sharing options...
kirbybeam Posted December 3, 2005 Author Share Posted December 3, 2005 import cs1.Keyboard; public class FractionalBinaryOperations { public static void doTheOperations() { System.out.println(); System.out.print("Enter the numerator for the first fraction: "); int numeratorFraction1 = Keyboard.readInt(); System.out.println(); System.out.print("Enter the denominator of the first fraction: "); int denominatorFraction1 = Keyboard.readInt(); System.out.println(); System.out.print("Enter the numerator of the second fraction: "); int numeratorFraction2 = Keyboard.readInt(); System.out.println(); System.out.print("Enter the denominator of the second fraction: "); int denominatorFraction2 = Keyboard.readInt(); Rational r1 = new Rational (numeratorFraction1, denominatorFraction1); Rational r2 = new Rational (numeratorFraction2, denominatorFraction2); Rational r3, r4, r5, r6, r7; // objects that hold fractions System.out.println(); System.out.println("First fraction: " + r1); System.out.println("Second fraction: " + r2); if (r1.equals(r2)) System.out.println ("The fractions are equal."); else System.out.println("The fractions are NOT equal."); r4 = r1.add(r2); r5 = r1.subtract(r2); r6 = r1.multiply(r2); r7 = r1.divide(r2); /* these four things are methods of the Rational Class*/ System.out.println (r1 + " + " + r2 + " = " + r4); System.out.println (r1 + " - " + r2 + " = " + r5); System.out.println (r1 + " * " + r2 + " = " + r6); System.out.println (r1 + " / " + r2 + " = " + r7); } } Link to comment Share on other sites More sharing options...
kirbybeam Posted December 3, 2005 Author Share Posted December 3, 2005 whats the use... :roll: Start>Run>Calc Um.. the reason why I made this calculator is because it is FASTER and BETTER. Enter 2 decimal numbers and it does five operations at once. Enter 2 fractional numbers and it does four operations at once. And, last time I checked, the calculator with windows doesn't have the Quadratic Equation, and it doesn't give you all the possible factors as well. Neither does the windows calculator have Cramer's Rule. And you can't use it to find the mean, median, and mode easily. public class Rational { private int numerator, denominator; public Rational (int numer, int denom) { if (denom == 0) denom = 1; if (denom < 0) { numer = numer * -1; denom = denom * -1; } numerator = numer; denominator = denom; reduce(); } public int getNumerator() { return numerator; } public int getDenominator() { return denominator; } public Rational reciprocal () { return new Rational (denominator, numerator); } public Rational add (Rational op2) { int commonDenominator = denominator * op2.getDenominator(); int numerator1 = numerator * op2.getDenominator(); int numerator2 = op2.getNumerator() * denominator; int sum = numerator1 + numerator2; return new Rational (sum, commonDenominator); } public Rational subtract (Rational op2) { int commonDenominator = denominator * op2.getDenominator(); int numerator1 = numerator * op2.getDenominator(); int numerator2 = op2.getNumerator() * denominator; int difference = numerator1 - numerator2; return new Rational (difference, commonDenominator); } public Rational multiply (Rational op2) { int numer = numerator * op2.getNumerator(); int denom = denominator * op2.getDenominator(); return new Rational (numer, denom); } public Rational divide (Rational op2) { return multiply (op2.reciprocal()); } public boolean equals (Rational op2) { return (numerator == op2.getNumerator() && denominator == op2.getDenominator() ); } public String toString() { String result; if (numerator == 0) result = "0"; else if (denominator == 1) result = numerator + ""; else result = numerator + "/" + denominator; return result; } private void reduce() { if (numerator !=0) { int common = gcd (Math.abs(numerator), denominator); numerator = numerator / common; denominator = denominator / common; } } private int gcd (int num1, int num2) { while (num1 != num2) if (num1 > num2) num1 = num1 - num2; else num2 = num2 - num1; return num1; } } Link to comment Share on other sites More sharing options...
kirbybeam Posted December 3, 2005 Author Share Posted December 3, 2005 import cs1.Keyboard; public class Formulas { public static void quadratic() { double A1, B1, C1, discriminant, root1, root2, factor1, factor2, doublechecker, factors1, factors2, constant1, constant2; int checker, i, intchecker; System.out.println("You have selected the Quadratic Formula"); System.out.println(); System.out.print("Enter a nonzero coefficient of X squared (A): "); A1 = Keyboard.readDouble(); while (A1 == 0) { System.out.println("The coefficient of X squared cannot be zero."); System.out.print("Enter the coefficient of X squared again: "); A1 = Keyboard.readDouble(); } System.out.println(); System.out.print("Enter the coefficient of x (B): "); B1 = Keyboard.readDouble(); System.out.print("Enter the constant ©: "); C1 = Keyboard.readDouble(); discriminant = Math.pow(B1, 2) - (4 * A1 * C1); if (discriminant >= 0) { root1 = ((-1 * B1) + Math.sqrt(discriminant)) / (2 * A1); root2 = ((-1 * B1) - Math.sqrt(discriminant)) / (2 * A1); System.out.println(); System.out.println("A = " + A1); System.out.println("B = " + B1); System.out.println("C = " + C1); System.out.println("X = " + root1 + " or X = " + root2); System.out.println(); factor1 = -1 * root1; factor2 = -1 * root2; intchecker = (int) A1; doublechecker = intchecker; if (doublechecker == A1) { if (factor1 > 0) { if (factor2 > 0) { for (i = 1; i <= A1; i++) { checker = (int) A1 % i; if (checker == 0) { factors1 = (int) A1 / i; factors2 = (int) A1 / factors1; constant1 = factor1 * factors1; constant2 = factor2 * factors2; System.out.println("The 2 factors could be: (" + factors1 + "X + " + constant1 + ") and (" + factors2 + "X + " + constant2 + ")"); } } } else { for (i = 1; i <= A1; i++) { checker = (int) A1 % i; if (checker == 0) { factors1 = (int) A1 / i; factors2 = (int) A1 / factors1; constant1 = factor1 * factors1; constant2 = factor2 * factors2; if (constant2 < 0) { constant2 *= -1; } System.out.println("The 2 factors could be: (" + factors1 + "X + " + constant1 + ") and (" + factors2 + "X - " + constant2 + ")"); } } } } else { if (factor2 > 0) { for (i = 1; i <= A1; i++) { checker = (int) A1 % i; if (checker == 0) { factors1 = (int) A1 / i; factors2 = (int) A1 / factors1; constant1 = factor1 * factors1; constant2 = factor2 * factors2; if (constant1 < 0 ) { constant1 *= -1; } System.out.println("The 2 factors could be: (" + factors1 + "X - " + constant1 + ") and (" + factors2 + "X + " + constant2 + ")"); } } } else { for (i = 1; i <= A1; i++) { checker = (int) A1 % i; if (checker == 0) { factors1 = (int) A1 / i; factors2 = (int) A1 / factors1; constant1 = factor1 * factors1; constant2 = factor2 * factors2; if (constant1 < 0 ) { constant1 *= -1; } if (constant2 < 0) { constant2 *= -1; } System.out.println("The 2 factors could be: (" + factors1 + "X - " + constant1 + ") and (" + factors2 + "X - " + constant2 + ")"); } } } } } System.out.println(); System.out.println("Use the pair of factors that only contains whole numbers!"); } else { System.out.println(); System.out.println("A = " + A1); System.out.println("B = " + B1); System.out.println("C = " + C1); System.out.println("The discriminant was negative!"); } System.out.println(); } public static void cramerRule() { double A1, B1, C1, A2, B2, C2, A3, B3, C3, D1, D2, D3; double term1, term2, term3, term4, term5, term6; double numerator, denominator; double x, y, z; System.out.println("You have selected Cramer's Rule"); System.out.println(); System.out.print("Enter the first coefficient of the first equation: "); A1 = Keyboard.readDouble(); System.out.print("Enter the second coefficient of the first equation: "); B1 = Keyboard.readDouble(); System.out.print("Enter the third coefficient of the first equation: "); C1 = Keyboard.readDouble(); System.out.print("Enter the fourth coefficient of the first equation: "); D1 = Keyboard.readDouble(); System.out.print("Enter the first coefficient of the second equation: "); A2 = Keyboard.readDouble(); System.out.print("Enter the second coefficient of the second equation: "); B2 = Keyboard.readDouble(); System.out.print("Enter the third coefficient of the second equation: "); C2 = Keyboard.readDouble(); System.out.print("Enter the fourth coefficient of the second equation: "); D2 = Keyboard.readDouble(); System.out.print("Enter the first coefficient of the third equation: "); A3 = Keyboard.readDouble(); System.out.print("Enter the second coefficient of the third equation: "); B3 = Keyboard.readDouble(); System.out.print("Enter the third coefficient of the third equation: "); C3 = Keyboard.readDouble(); System.out.print("Enter the fourth coefficient of the third equation: "); D3 = Keyboard.readDouble(); System.out.println(); term1 = A1 * B2 * C3; term2 = B1 * C2 * A3; term3 = C1 * A2 * B3; term4 = A3 * B2 * C1; term5 = B3 * C2 * A1; term6 = C3 * A2 * B1; denominator = (term1 + term2 + term3) - (term4 + term5 + term6); term1 = D1 * B2 * C3; term2 = B1 * C2 * D3; term3 = C1 * D2 * B3; term4 = D3 * B2 * C1; term5 = B3 * C2 * D1; term6 = C3 * D2 * B1; numerator = (term1 + term2 + term3) - (term4 + term5 + term6); x = numerator / denominator; term1 = A1 * D2 * C3; term2 = D1 * C2 * A3; term3 = C1 * A2 * D3; term4 = A3 * D2 * C1; term5 = D3 * C2 * A1; term6 = C3 * A2 * D1; numerator = (term1 + term2 + term3) - (term4 + term5 + term6); y = numerator / denominator; term1 = A1 * B2 * D3; term2 = B1 * D2 * A3; term3 = D1 * A2 * B3; term4 = A3 * B2 * D1; term5 = B3 * D2 * A1; term6 = D3 * A2 * B1; numerator = (term1 + term2 + term3) - (term4 + term5 + term6); z = numerator / denominator; System.out.println("D = " + denominator); System.out.println("x = " + x); System.out.println("y = " + y); System.out.println("z = " + z); System.out.println(); System.out.println(); } } Link to comment Share on other sites More sharing options...
kirbybeam Posted December 3, 2005 Author Share Posted December 3, 2005 Also, it was very rude of you to rate my program when I specifically asked for JAVA PROGRAMMERS. import cs1.Keyboard; public class Averages { public static void findAverage() { double total, sum = 0, mean, median, mode; // right now only the mean can be found... need help with median and mode! int numbers; String order1 = new String("first"); String order2 = new String("second"); String order3 = new String("third"); String order4 = new String("fourth"); String order5 = new String("fifth"); String order6 = new String("sixth"); String order7 = new String("seventh"); String order8 = new String("eighth"); String order9 = new String("ninth"); String order10 = new String("tenth"); String order11 = new String("eleventh"); String order12 = new String("twelfth"); String order13 = new String("thirteenth"); String order14 = new String("fourteenth"); String order15 = new String("fifteenth"); String order16 = new String("sixteenth"); String order17 = new String("seventeenth"); String order18 = new String("eighteenth"); String order19 = new String("nineteenth"); String order20 = new String("twentieth"); String order21 = new String("twenty-" + order1); String order22 = new String("twenty-" + order2); String order23 = new String("twenty-" + order3); String order24 = new String("twenty-" + order4); String order25 = new String("twenty-" + order5); String order26 = new String("twenty-" + order6); String order27 = new String("twenty-" + order7); String order28 = new String("twenty-" + order8); String order29 = new String("twenty-" + order9); String order30 = new String("thirtieth"); String order = order1; System.out.println(); System.out.println("You have selected Averages."); System.out.println(); System.out.print("Enter the number of numbers you wish to enter (maximum is 30): "); numbers = Keyboard.readInt(); System.out.println(); for (int i = 1; i <= numbers; i++) { if (i == 1) { order = order1; } if (i == 2) { order = order2; } if (i == 3) { order = order3; } if (i == 4) { order = order4; } if (i == 5) { order = order5; } if (i == 6) { order = order6; } if (i == 7) { order = order7; } if (i == 8) { order = order8; } if (i == 9) { order = order9; } if (i == 10) { order = order10; } if (i == 11) { order = order11; } if (i == 12) { order = order12; } if (i == 13) { order = order13; } if (i == 14) { order = order14; } if (i == 15) { order = order15; } if (i == 16) { order = order16; } if (i == 17) { order = order17; } if (i == 18) { order = order18; } if (i == 19) { order = order19; } if (i == 20) { order = order20; } if (i == 21) { order = order21; } if (i == 22) { order = order22; } if (i == 23) { order = order23; } if (i == 24) { order = order24; } if (i == 25) { order = order25; } if (i == 26) { order = order26; } if (i == 27) { order = order27; } if (i == 28) { order = order28; } if (i == 29) { order = order29; } if (i == 30) { order = order30; } System.out.print("Enter your " + order + " number: "); total = Keyboard.readDouble(); sum += total; } mean = sum / numbers; System.out.println(); System.out.println("The mean is: " + mean); System.out.println(); } } Ok, that's all of the programs. First, tell me how good it is for a person that's only known Java for 3 months. Then, could you tell me how to implement the median and mode into my Averages Class? Link to comment Share on other sites More sharing options...
spling Posted December 3, 2005 Share Posted December 3, 2005 Why not upload it all into one big .txt document? Put it on nomorepasting.com or something. I cba to put all these into a file and compile it to see your calculator.. Check out RuneScript and RuneTracker! Link to comment Share on other sites More sharing options...
kirbybeam Posted December 3, 2005 Author Share Posted December 3, 2005 Why not upload it all into one big .txt document? Put it on nomorepasting.com or something. I cba to put all these into a file and compile it to see your calculator.. what does "cba" mean? http://www.nomorepasting.com/paste.php?pasteID=53710 Link to comment Share on other sites More sharing options...
kirbybeam Posted December 3, 2005 Author Share Posted December 3, 2005 anyway, here's what my program looks like when run: (^_^)WELCOME TO KIRBY'S CALCULATOR PROGRAM!!!(^_^) What would you like to do now? Type 1 for Decimal Binary Operations Type 2 for Fractional Binary Operations Type 3 for the Quadratic Formula Type 4 for Cramer's Rule Type 5 for Averages Type -1 to quit 1 You have selected Decimal Binary Operations Enter your first number: 1.5 Enter your second number: 2.5 1.5 + 2.5 = 4.0 1.5 - 2.5 = -1.0 1.5 * 2.5 = 3.75 1.5 / 2.5 = 0.6 1.5^2.5 = 2.7556759606310752 What would you like to do now? Type 1 for Decimal Binary Operations Type 2 for Fractional Binary Operations Type 3 for the Quadratic Formula Type 4 for Cramer's Rule Type 5 for Averages Type -1 to quit 2 Enter the numerator for the first fraction: 1 Enter the denominator of the first fraction: 2 Enter the numerator of the second fraction: 1 Enter the denominator of the second fraction: 3 First fraction: 1/2 Second fraction: 1/3 The fractions are NOT equal. 1/2 + 1/3 = 5/6 1/2 - 1/3 = 1/6 1/2 * 1/3 = 1/6 1/2 / 1/3 = 3/2 What would you like to do now? Type 1 for Decimal Binary Operations Type 2 for Fractional Binary Operations Type 3 for the Quadratic Formula Type 4 for Cramer's Rule Type 5 for Averages Type -1 to quit 3 You have selected the Quadratic Formula Enter a nonzero coefficient of X squared (A): 20 Enter the coefficient of x (B): 21 Enter the constant ©: 1 A = 20.0 B = 21.0 C = 1.0 X = -0.05 or X = -1.0 The 2 factors could be: (20.0X + 1.0) and (1.0X + 1.0) The 2 factors could be: (10.0X + 0.5) and (2.0X + 2.0) The 2 factors could be: (5.0X + 0.25) and (4.0X + 4.0) The 2 factors could be: (4.0X + 0.2) and (5.0X + 5.0) The 2 factors could be: (2.0X + 0.1) and (10.0X + 10.0) The 2 factors could be: (1.0X + 0.05) and (20.0X + 20.0) Use the pair of factors that only contains whole numbers! What would you like to do now? Type 1 for Decimal Binary Operations Type 2 for Fractional Binary Operations Type 3 for the Quadratic Formula Type 4 for Cramer's Rule Type 5 for Averages Type -1 to quit 4 You have selected Cramer's Rule Enter the first coefficient of the first equation: 1 Enter the second coefficient of the first equation: 1 Enter the third coefficient of the first equation: 1 Enter the fourth coefficient of the first equation: 3 Enter the first coefficient of the second equation: 1 Enter the second coefficient of the second equation: 1 Enter the third coefficient of the second equation: 1 Enter the fourth coefficient of the second equation: 3 Enter the first coefficient of the third equation: 1 Enter the second coefficient of the third equation: 1 Enter the third coefficient of the third equation: 1 Enter the fourth coefficient of the third equation: 3 D = 0.0 x = NaN y = NaN z = NaN What would you like to do now? Type 1 for Decimal Binary Operations Type 2 for Fractional Binary Operations Type 3 for the Quadratic Formula Type 4 for Cramer's Rule Type 5 for Averages Type -1 to quit 5 You have selected Averages. Enter the number of numbers you wish to enter (maximum is 30): 5 Enter your first number: 1 Enter your second number: 3 Enter your third number: 5 Enter your fourth number: 7 Enter your fifth number: 9 The mean is: 5.0 What would you like to do now? Type 1 for Decimal Binary Operations Type 2 for Fractional Binary Operations Type 3 for the Quadratic Formula Type 4 for Cramer's Rule Type 5 for Averages Type -1 to quit -1 Are you sure you want to quit? Type -10 for yes: -10 (^_^) That was fun. See you again!(^_^) Press any key to continue . . . Link to comment Share on other sites More sharing options...
bum_co Posted December 3, 2005 Share Posted December 3, 2005 thats cool how long did it take u to make? Link to comment Share on other sites More sharing options...
kirbybeam Posted December 3, 2005 Author Share Posted December 3, 2005 um... maybe like one day for each part of the program? So yeah, I'm thinking to add more and more functions to it to make it better and better. Right now it helps so much with my math homework... :D I'm probably going to add geometric figure calculations to it soon... finding the perimeter and area of any plane figure would be nice to implement. Link to comment Share on other sites More sharing options...
Zibl Posted December 4, 2005 Share Posted December 4, 2005 WARNING: Extreme newb question below. If you are going to falme and/or slip into a "oh meh gawd" coma, do not look. . . . . . . . . . . . . . How might one open it :oops: ? If we even can. Or would you have to compile it into an EXE file and us download it? Sorry. I know nothing of Java :? . I'd just like to try it out because it looks interesting. RS Name: Zibl || Click Signature for my RS Life Story![ 87 Combat ] [ 1240 Total ] [ Ex-RSC Professional Merchant ]12.20.01 - 10.5.05 || Status: RetiredTotal losses in 5 years = just over 630 million gp (BILLIONS in today's prices) Link to comment Share on other sites More sharing options...
kirbybeam Posted December 4, 2005 Author Share Posted December 4, 2005 1. Download the Java Runtime Environment http://www.java.com/en/download/windows_xpi.jsp Click the first download button to the right of "Windows (XPI)" 2. Download the Keyboard Class http://duke.csc.villanova.edu/jss1/book ... yboard.jsp Click on cs1jar.zip. 3. Download Textpad http://www.textpad.com/download/index.html Once you download those things, open textpad. Then go to the Configure tab at the top and scroll to preferences. Click on tools and then click on add and then add Java. once you have done that, copy my first program into textpad and save it as Manipulation.java. Then open a new document, and save my second program as Choices.java. Then open a new document, and save my third program as DecimalBinaryOperations.java. new document, 4th program as FractionalBinaryOperations.java. new document, 5th program as Rational.java new document, 6th program as Formulas.java new document, 7th program as Averages.java *note: Java is case sensitive, so save these files as EXACTLY as shown or my program won't run. Now, go back to Manipulation.java and compile it (ctrl + 1) Then run it (ctrl + 2) follow the instructions from there! (Yes, I know this takes a while to make it work, but trust me, you'll love this program for your math homework.) :D Link to comment Share on other sites More sharing options...
bjbj1991 Posted December 4, 2005 Share Posted December 4, 2005 whats the use... :roll: Start>Run>Calc some people like making stuff by themselves. whats the use in making a fansite about a game? whats the use in making a rpg? whats the use in making java you can just use machene language for most the stuff? whats the use in making the internet? whats the use in inventing the wheel? whats the use in making a spear? this line of thinking leads the stone age. Link to comment Share on other sites More sharing options...
kirbybeam Posted December 4, 2005 Author Share Posted December 4, 2005 Um... I made this calculator because the windows one sucks. Like I said, my calculator can do so much more and faster. Link to comment Share on other sites More sharing options...
Hannibal Posted December 4, 2005 Share Posted December 4, 2005 Um... I made this calculator because the windows one sucks. Like I said, my calculator can do so much more and faster. bjbj was actually supporting you, I think :) I don't have the time to read it all at the moment, but I do have one nit: String foo = new String("bar-" + someVariable); Why are you using a string constructor here? You've already set the variable type, isn't java okay with: String foo = "bar-" + someVariable; ? Also, I'm not a native English speaker and have enjoyed my Maths education in Dutch. I'm not familiar with "Cramer's rule", but is your program correct in reporting NaN for 3 out of the 4 result values? :) You could maybe use isNaN to check for it, and display something else instead (maybe that there are no results with these parameters or something). Link to comment Share on other sites More sharing options...
kirbybeam Posted December 5, 2005 Author Share Posted December 5, 2005 Um... I made this calculator because the windows one sucks. Like I said, my calculator can do so much more and faster. bjbj was actually supporting you, I think :) I don't have the time to read it all at the moment, but I do have one nit: String foo = new String("bar-" + someVariable); Why are you using a string constructor here? You've already set the variable type, isn't java okay with: String foo = "bar-" + someVariable; ? Yeah, it is. But I feel more confortable with the String constructor because it helps my Strings stand out when for other variables I only use a quick assignment statement. Also, I'm not a native English speaker and have enjoyed my Maths education in Dutch. I'm not familiar with "Cramer's rule", but is your program correct in reporting NaN for 3 out of the 4 result values? :) You could maybe use isNaN to check for it, and display something else instead (maybe that there are no results with these parameters or something). Oh, that's fine, I was just lazy. See, the reason it came out NaN is because the constants I put in make it so that the solution set for all three variables is all real numbers. Here's a real example of it: Cramer's Rule is to solve 3 equations with 3 variables: 2x + 3y - 2z = 4 3x - 2y + 2z = 16 -x - 12y + 8z = 5 I'll run this, and using Cramer's Rule I can find out all three variables: (^_^)WELCOME TO KIRBY'S CALCULATOR PROGRAM!!!(^_^) What would you like to do now? Type 1 for Decimal Binary Operations Type 2 for Fractional Binary Operations Type 3 for the Quadratic Formula Type 4 for Cramer's Rule Type 5 for Averages Type -1 to quit 4 You have selected Cramer's Rule Enter the first coefficient of the first equation: 2 Enter the second coefficient of the first equation: 3 Enter the third coefficient of the first equation: -2 Enter the fourth coefficient of the first equation: 4 Enter the first coefficient of the second equation: 3 Enter the second coefficient of the second equation: -2 Enter the third coefficient of the second equation: 2 Enter the fourth coefficient of the second equation: 16 Enter the first coefficient of the third equation: -1 Enter the second coefficient of the third equation: -12 Enter the third coefficient of the third equation: 8 Enter the fourth coefficient of the third equation: 5 D = 14.0 x = 3.0 y = 5.0 z = 8.5 What would you like to do now? Type 1 for Decimal Binary Operations Type 2 for Fractional Binary Operations Type 3 for the Quadratic Formula Type 4 for Cramer's Rule Type 5 for Averages Type -1 to quit -1 Are you sure you want to quit? Type -10 for yes: -10 (^_^) That was fun. See you again!(^_^) Press any key to continue . . . Do you get it now? Link to comment Share on other sites More sharing options...
____ Posted December 5, 2005 Share Posted December 5, 2005 You need to learn more tricks :P That entrie program can be easily compressed down into a single class. And instead of using 'while' loops everywhere, just use switch statements (specially for the menu) and you could probably do to use a list for the 'mean / average / etc' thing instead of having 30 or so variables :-? I'd rewrite some parts but since I don't have the sdk and such installed atm I can't do it :P It's not bad but you tend to take the long way to do a lot of things. And is that cs1.Keyboard import universal? I haven't seen it before in my life and I've been coding Java stuff for years :-? Link to comment Share on other sites More sharing options...
kirbybeam Posted December 6, 2005 Author Share Posted December 6, 2005 You need to learn more tricks :P That entrie program can be easily compressed down into a single class. And instead of using 'while' loops everywhere, just use switch statements (specially for the menu) and you could probably do to use a list for the 'mean / average / etc' thing instead of having 30 or so variables :-? I'd rewrite some parts but since I don't have the sdk and such installed atm I can't do it :P It's not bad but you tend to take the long way to do a lot of things. And is that cs1.Keyboard import universal? I haven't seen it before in my life and I've been coding Java stuff for years :-? I've taken Computer Science 1 for just three months now at school. And my class is filled with idiots, so we are moving along pretty slowly... Hell, some kids in my class can't even get the HelloWorld program running yet :roll: So yeah, if I take the long way of things, it's because I simply haven't learned the shortcuts (and believe me, I'm using things in this program that my class won't cover until like next month) Hmm, I would use a switch statement, but I am not sure if that will let me return to the previous functions of my calculator. I still don't know enough about it to utilize it. And yeah, I realize that having like 30 variables for that averages program was taking it a little too far, but the thing is, that's the way that I can do it from what I have learned thus far. And I even wrote a program called "IfStatements.java" that I used to get all those if statements printed out by the computer and then copying and pasting them instead of typing each one by hand. And the cs1.Keyboard import is basicly like the scanner class except better. It was written by Lewis and Loftus, who are the authors of the computer science book my class is using. It's really useful, especially since my school's computers don't have the scanner class. Link to comment Share on other sites More sharing options...
____ Posted December 6, 2005 Share Posted December 6, 2005 If you structure your program correctly a switch statement is generally the best option. Just have a flag to know if the application is running... so you got like (pseudo code so yea..) boolean running = true; while running switch(whatever) case x: ...; case y: ...; case z: ...; generally the case will jump to another function do whatever it is it was suposed to do then just keep running. Then the only time it'll be kill the switch and the while is when you exit. Hard to like, explain without a proper program to show but I hope you get the gist of it. I could pm you some stuff from a project I did for uni if you want? Link to comment Share on other sites More sharing options...
kirbybeam Posted December 6, 2005 Author Share Posted December 6, 2005 //I fixed up the Averages.java a bit! I had to peek at chapter 6 while my //teacher wasn't looking... later on she caught me and I got in trouble :roll: //So... I am using arrays now... so much better! //Now, up to 50 numbers can be entered... import cs1.Keyboard; public class Averages { public static void findAverage() { double sum = 0, mean, median, mode; int numbers; final int NUMBERS_LIMIT = 50; String order; String stringArray[] = new String[NUMBERS_LIMIT + 1]; double doubleArray[] = new double[NUMBERS_LIMIT + 1]; stringArray[0] = null; stringArray[1] = "first"; stringArray[2] = "second"; stringArray[3] = "third"; stringArray[4] = "fourth"; stringArray[5] = "fifth"; stringArray[6] = "sixth"; stringArray[7] = "seventh"; stringArray[8] = "eighth"; stringArray[9] = "ninth"; stringArray[10] = "tenth"; stringArray[11] = "eleventh"; stringArray[12] = "twelfth"; stringArray[13] = "thirteenth"; stringArray[14] = "fourteenth"; stringArray[15] = "fifteenth"; stringArray[16] = "sixteenth"; stringArray[17] = "seventeenth"; stringArray[18] = "eighteenth"; stringArray[19] = "nineteenth"; stringArray[20] = "twentieth"; stringArray[21] = "twenty-" + stringArray[1]; stringArray[22] = "twenty-" + stringArray[2]; stringArray[23] = "twenty-" + stringArray[3]; stringArray[24] = "twenty-" + stringArray[4]; stringArray[25] = "twenty-" + stringArray[5]; stringArray[26] = "twenty-" + stringArray[6]; stringArray[27] = "twenty-" + stringArray[7]; stringArray[28] = "twenty-" + stringArray[8]; stringArray[29] = "twenty-" + stringArray[9]; stringArray[30] = "thirtieth"; stringArray[31] = "thirty-" + stringArray[1]; stringArray[32] = "thirty-" + stringArray[2]; stringArray[33] = "thirty-" + stringArray[3]; stringArray[34] = "thirty-" + stringArray[4]; stringArray[35] = "thirty-" + stringArray[5]; stringArray[36] = "thirty-" + stringArray[6]; stringArray[37] = "thirty-" + stringArray[7]; stringArray[38] = "thirty-" + stringArray[8]; stringArray[39] = "thirty-" + stringArray[9]; stringArray[40] = "fortieth"; stringArray[41] = "forty-" + stringArray[1]; stringArray[42] = "forty-" + stringArray[2]; stringArray[43] = "forty-" + stringArray[3]; stringArray[44] = "forty-" + stringArray[4]; stringArray[45] = "forty-" + stringArray[5]; stringArray[46] = "forty-" + stringArray[6]; stringArray[47] = "forty-" + stringArray[7]; stringArray[48] = "forty-" + stringArray[8]; stringArray[49] = "forty-" + stringArray[9]; stringArray[50] = "fiftieth"; System.out.println("You have selected Averages."); System.out.println(); System.out.print("Enter the number of numbers you wish to enter (maximum is " + NUMBERS_LIMIT + "): "); numbers = Keyboard.readInt(); while (numbers > NUMBERS_LIMIT || numbers < 1) { System.out.print ("Invalid number entered! Try again: "); numbers = Keyboard.readInt(); } System.out.println(); for (int i = 1; i <= numbers; i++) { System.out.print("Enter the " + stringArray + " number: "); doubleArray = Keyboard.readDouble(); sum += doubleArray; } System.out.println("The sum is: " + sum); mean = sum / numbers; System.out.println("The mean is: " + mean); System.out.println(); } } //Now I need to implement the median and the mode... I have no idea // how to do that yet. Link to comment Share on other sites More sharing options...
Blake16 Posted December 7, 2005 Share Posted December 7, 2005 Pretty good is this like one of your firsts or what. j/w :) Try implenting it into a GUI with javax.something i forgot.* and ahh i can't remember the other, it's been so long since I've programmed anything with java i think its java.swing.awt And instead of selection your options either type the number into a JtextFrame (i think thats it) and maybe have some Jbuttons with listeners on them for the numbers and input data and just take the value of the JtextFrame and use the signs + - / * and ^ as seperators and parse each into an Int and depending on the seperator will depend on the operation performed on the two adjacent terms Link to comment Share on other sites More sharing options...
vmser Posted December 7, 2005 Share Posted December 7, 2005 Blake it probably referring to the Swing class. Meh, I dont like it too much. As for your program: You dont need the keyboard class.. Use the standard reader class implemented in java... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now