Exercise Overview Implement a Java program that creates math flashcards for elementary grade students. User will enter h
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Exercise Overview Implement a Java program that creates math flashcards for elementary grade students. User will enter h
Cards class - Cards class should be appended to your driver class so you only need to send one.java file O Instantiate objects - Random, Scanner O Declare variables - all variables have private visibility modifier ▪ int loFactor: int hiFactor; int factor1; int factor2; int answer; int response; int a = 0, b = 0, c = 0; String corinc = "Incorrect"; O Define constructors - use default constructor only O Define methods setLoFactorRange(int lo) setHiFactorRange(int hi) setFactors() setFactor1() // For problems with division by zero to set only 1 factor getFactor1() getFactor2() setProb(Session s) // Includes switch and the cases for the probTypes setResponse(Session s) getA() getB() getc) getResponse() getCorinc()
Class Session - Session class should be appended to your driver class so you only need to send one.java file o Instantiate objects - Scanner Declare variables String name String prob Type String longProbType String oper int numProb int score double scorePct wwwwwwwww String[] history o Define constructors - use default constructor only o Define methods ▪ ▪ setinputs() // Prompt for and read-in all inputs in one method getName() getProbType() getLongProbType() getOper() getNumProb() prtintro(Cards c) incScore() setHistory(Cards c, int i) setScorePct() getScorePct() getScore() prtSummary() prtHistoryAndOutro() // Print history and outro message in one method • Code-specific technical requirements o Suggested algorithms or code sections factor1 or factor2 = random.nextInt(hiFactor-loFactor + 1) + loFactor; probType = probType.toUpperCase(); so you need only switch on the uppercase value Use switch(probType) to set the longProb Type Use a second switch (probType) to create the problems for the different problem types
a Clean-up from Project 1 All inputs to printed prompt on the console should be on the same line as the prompt with 1 blank after the prompt ends. For example, prompt would be System.out.print("Enter name: ") using print (not printin) There should be a space between the elements of the printed problem. System.out.print(factor1 +"+"+factor2+" =") Example output (from the Eclipse console) Enter your name: Kevin What is the type of problem you wish to work? Enter A, S, M, or D: d Enter the lowest factor value for your flashcard problems: 0 Enter the highest factor value for your flashcard problems: 9 Enter the number of problems you wish to work: 3 24/8 = 3 Correct! www Hi Kevin, and welcome to the 3312 FlashCard System! You have chosen the operation Division. The range of factors you have chosen is from 0 to 9, inclusive. 9 / 3 = 3 Correct! There should be 2 blank lines after the intro is printed and before the first problem is displayed. There should be a blank line before each new problem is displayed. Use System.out.println(); There should be 2 blank lines before the session summary is printed. There should be 1 blank line between the session summary and the print out of the history. There should be 2 blank lines between the last line of the history and the first line of the outro. You have chosen to work 3 problems. Press any character key and then Enter to begin. 30 / 6 = 4 Incorrect! Correct answer is 5 Session Summary 3 problems, 2 correct score is 66.7 oblem types Problems 24 / 8 = 3, Correct, correct answer is 3 9/33, Correct, correct answer is 3 30/6= 4, Incorrect, correct answer is 5 Thank you for using the 3312 FlashCard System, Kevin. Come back and play again real soon!
Hints and Suggestons. To create your problems, code the addition case first for just one problem (no loop yet). Then replicate and edit for the problem types using switch(probType) for the selection process. Then add the loop for the number of problems. For the subtraction case, generate the factors, add them together so the sum becomes the minuend (the bigger number), one of the factors is the subtrahend (number subtracted from the bigger number), and the other factor is the difference (the answer). For the division case, use the product of the factors for the dividend (the bigger number), one factors becomes the divisor (the smaller number), and the other factor is the quotient (the answer). . . Add logic to prevent division-by-zero. Approach options: Use if statement to check for zero, then add a 1 to the factor Use a while loop with the test (factor == 0) and with the body of the if statement generate a new factor until it is non-zero (this is the best approach) To maximize reusable code, try to minimize the amount of code within the switch cases. The project requires refactoring code from Project 1. You may use either your Project 1 submission or the Project 1 solution provided in eLearning as your starting point. Non-Coding Submission and Scoring Research and Analysis. Describe your analysis of specific issues within the overall coding problem including input, processing, primary calculations, and output in your own words. List any websites or other resources you consulted in doing your analysis. (5 pts) Suggested areas for analysis: Generating a random int within a range Creating a String value for each problem that can be an element in the history array Calculating the scorect using type casting Using the System.out.printf() method for printing the scorect value ▪ Passing an object to a method Type your analysis topics and descriptions here. Remember to list resources consulted. Design. Describe the major steps for solving the problem. (5 pts) I Describe the major sections of the code, and include important subsections within the major sections Type your design description here. Coding. Code submission. (20 pts) See rubric for point calculations. You do not need to enter anything in this section - your code submission covers this Coding section. Testing. Describe how you tested this program. (5 pts) Suggested areas for explicit testing: Generating the random integers to be sure they are within the user-entered range Ensuring that division-by-zero prevention logic is working correctly Did you use the debugger for any sections? Did you do interim testing by printing extra variables to the console and then comment them out before submitting your final version of code? Enter your testing description here