hw02

pdf

School

Georgia Institute Of Technology *

*We aren’t endorsed by this school

Course

1331

Subject

Computer Science

Date

Dec 6, 2023

Type

pdf

Pages

5

Uploaded by MinisterBarracuda3986

Report
Homework 02 - Calculator Problem Description Hello, and welcome! Please make sure to read all parts carefully. For homework 02, you will be creating a calculator that can perform the following operations: add, subtract, multiply, divide, and alphabetize. The operations work as follows: add - takes two integers, adds them together and prints out the result subtract - takes two integers, subtracts the second entered integer from the first and prints out the result multiply - takes two doubles, multiplies them together and prints out the result to two decimal places divide - takes two doubles, divides the first entered double by the second and prints out the result to two decimal places alphabetize - takes two words of only letters, and tells which word comes before the other lexicographically Solution Description Name your program Calculator.java . It should work as follows: 1. Print out the list of operations for the user. 2. Prompt the user to enter an operation. This operation must be processed as case-insensitive. a. If the user enters an invalid operation, the program should print the following error message and terminate gracefully. Invalid input entered. Terminating... 3. Perform the chosen operation and print the correct output. a. If the user is performing an add/subtract operation, prompt the user to enter two integers. b. If the user is performing a multiply/divide operation, prompt the user to enter two doubles. c. If the user is performing an alphabetize operation, prompt the user to enter two words. d. If the user inputs an invalid type (e.g. inputs doubles for add/subtract) for the given operation, print the same error message shown above. 4. The program should terminate gracefully after the result of the operation is printed. Note that 0 must not be the divisor if you are dividing. If a 0 is the divisor, terminate your program. For the multiply and divide operations, format your output using printf . Your program must also have at least one switch statement and one if/else statement. For the alphabetize operation, you will be using a pre-defined String method that compares two strings lexicographically, and returns an integer depending on which String is larger. If a 0 is returned, both Strings are lexicographically equal. A positive integer is returned if the first string is lexicographically greater than the second string, or else the result would be negative. See the example output for how the result should be printed to the user for the cases where Strings are equal. When prompting for integers, doubles, or Strings, spaces will serve as dividers between the two inputs. Remember that when performing multiply/divide operations on doubles, the answer should only include two numbers after the decimal point.
Example Outputs User input is bolded . Please make sure to follow the exact formatting as shown in the pdf. List of operations: add subtract multiply divide alphabetize Enter an operation: add Enter two integers: 3 4 Answer: 7 List of operations: add subtract multiply divide alphabetize Enter an operation: Subtract Enter two integers: 5 8 Answer: -3 List of operations: add subtract multiply divide alphabetize Enter an operation: mulTIply Enter two doubles: 3.561 7.63 Answer: 27.17 List of operations: add subtract multiply divide alphabetize Enter an operation: divide Enter two doubles: 12 3 Answer: 4.00 List of operations: add subtract multiply divide alphabetize Enter an operation: alphabetIZE Enter two words: Zebra apples Answer: apples comes before Zebra alphabetically. List of operations: add subtract multiply divide alphabetize Enter an operation: alpHabEtize Enter two words: hello Hello Answer: Chicken or Egg. List of operations: add subtract multiply divide alphabetize Enter an operation: add Enter two integers: 1.23 2.34 Invalid input entered. Terminating...
List of operations: add subtract multiply divide alphabetize Enter an operation: modulus Invalid input entered. Terminating... Rubric [100] Calculator.java [10] Correctly prompts user to type in an operation [10] Correctly prompts user for two integers for add/subtract operations [10] Correctly prompts user for two doubles for multiply/divide operations [10] Correctly prompts user for two words for alphabetization [10] Uses at least one switch statement and at least one if/else statement [30] Prints calculation results correctly o [10] Prints add and subtract results correctly as an integer o [10] Prints multiplication and division results correctly to two decimal places using printf o [10] Prints alphabetization results correctly [20] Prints required error message and terminates gracefully when incorrect input is provided o [10] When an invalid operation is entered o [10] When 0 is the divisor for the divide operation We reserve the right to adjust the rubric, but this is typically only done for correcting mistakes. Allowed Imports To prevent trivialization of the assignment, you may only import java.util.Scanner. Feature Restrictions There are a few features and methods in Java that overly simplify the concepts we are trying to teach or break our auto grader. For that reason, do not use any of the following in your final submission: var (the reserved keyword) System.exit Collaboration Collaboration Statement To ensure that you acknowledge a collaboration and give credit where credit is due, we require that you place a collaboration statement as a comment at the top of at least one .java file that you submit . That collaboration statement should say either: I worked on the homework assignment alone, using only course materials. or In order to help learn course concepts, I worked on the homework with [give the names of the people you worked with], discussed homework topics and issues with [provide names of people], and/or consulted related material
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
that can be found at [cite any other materials not provided as course materials for CS 1331 that assisted your learning]. Allowed Collaboration When completing homeworks for CS1331 you may talk with other students about: What general strategies or algorithms you used to solve problems in the homeworks Parts of the homework you are unsure of and need more explanation Online resources that helped you find a solution Key course concepts and Java language features used in your solution You may not discuss, show, or share by other means the specifics of your code, including screenshots, file sharing, or showing someone else the code on your computer, or use code shared by others. Examples of approved/disapproved collaboration: approved : "Hey, I'm really confused on how we are supposed to implement this part of the homework. What strategies/resources did you use to solve it?" disapproved : "Hey, it's 10:40 on Thursday... Can I see your code? I won't copy it directly I promise" In addition to the above rules, note that it is not allowed to upload your code to any sort of public repository. This could be considered an Honor Code violation, even if it is after the homework is due. Turn-In Procedure Submission To submit, upload the files listed below to the corresponding assignment on Gradescope: Calculator.java Make sure you see the message stating "HW02 submitted successfully". From this point, Gradescope will run a basic autograder on your submission as discussed in the next section. You can submit as many times as you want before the deadline, so feel free to resubmit as you make substantial progress on the homework. We will only grade your last submission: be sure to submit every file each time you resubmit . Gradescope Autograder For each submission, you will be able to see the results of a few basic test cases on your code. Each test typically corresponds to a rubric item, and the score returned represents the performance of your code on those rubric items only. If you fail a test, you can look at the output to determine what went wrong and resubmit once you have fixed the issue. The Gradescope tests serve two main purposes: Prevent upload mistakes (e.g. non-compiling code) Provide basic formatting and usage validation In other words, the test cases on Gradescope are by no means comprehensive. Be sure to thoroughly test your code by considering edge cases and writing your own test files. You also should avoid using Gradescope to compile, run, or checkstyle your code; you can do that locally on your machine.
Other portions of your assignment can also be graded by a TA once the submission deadline has passed, so the output on Gradescope may not necessarily reflect your grade for the assignment. Important Notes (Don't Skip) Non-compiling files will receive a 0 for all associated rubric items Do not submit .class files Test your code in addition to the basic checks on Gradescope Submit every file each time you resubmit Read the "Allowed Imports" and "Restricted Features" to avoid losing points Check on Piazza for a note containing all official clarifications