See the image below for the answer to Week 2's problem. Please email your instructor if you need help or have questions (or put your questions in the check in submission form).
Write a program for a simple calculator.
Sample Output: Enter a number: 4 Enter another number: 2 4 + 2 = 6 4 - 2 = 2 4 * 2 = 8 4 / 2 = 2 4 % 2 = 0 Bonus: Before printing out the results, ask the user to guess what the results will be. Compare their guess to the actual result, and print out true or false to tell them whether they got the answer right or wrong. Write a method called shift. Given an integer array, return another array where each of the numbers is shifted one over to the right. The first number of the shifted array should be 1. In the main method, print out both of the arrays, the original one and the shifted one.
You don't need to ask the user for the integer array, just define it in your main method. Sample Output: The original array is: 2 5 6 1 8 9 7 The shifted array is: 1 2 5 6 1 8 9 Hints:
See the image below for the code and output for the HTML problem. Please contact your instructors if you have any questions.
Write a simple program that will put HTML tags around a word.
HTML tags are used to section off words/phrases on a web page. The tags surround the words like this: <tag> words </tag>
Sample Output: Enter your tag: a Enter a word/phrase to put inside the tags: this is a link <a> this is a link </a> You tutor 3 students in Java, and you just gave them a test. You have the students’ names and their scores out of 20, but you need help calculating their percentage and letter grades.
Write a method that, given the student’s name and their score (out of 20), will print out a statement of the student’s name, their percentage grade, and their letter grade.
Sample Output: Enter Student 1's name: Alice Enter Student 1's score: 19 Alice got 95%, A. Enter Student 2's name: Bob Enter Student 2's score: 17 Bob got 85%, B. Enter Student 3's name: Charlie Enter Student 3's score: 15 Charlie got 75%, C. Create a restaurant simulation using a switch statement! Feel free to adapt this problem for similar stores, like video game stores, bookstores, or movie rental shops.
Bonus: Right after step 3, ask the user if they want to order another dish. Hint: put your switch statement inside a while loop. Use a boolean variable as your loop's condition, and at the end of the loop, ask the user if they want to order again. Sample Output: Welcome to my restaurant! 1. Sandwich ($7) 2. Salad ($8) Choose an item from the menu above: 1 Here's your sandwich! Enjoy! Do you want to order more food (true/false)? true Choose an item from the menu above: 2 One salad just for you! Do you want to order more food (true/false)? false Thanks for visiting my restaurant! Your total cost is: $15 Have fun with this problem - be as creative as you want! Write a program that calculates the factorial of a given number.
Hints: Keep a variable, something like "product," that keeps track of the growing product. You will need to use a multiplication assignment operator in your loop. Sample output: Enter an integer (except 0): 4 Factorial of 4 (using while loop): 24 Factorial of 4 (using for loop): 24 A talking parrot means trouble only if it is talking before 7:00 or after 20:00 (8 pm). The purpose of this program is to tell the user whether or not we are in trouble.
Sample: Is the parrot talking (enter true or false)? true What hour is it (enter an integer from 0-23)? 8 Phew! We are not in trouble! Submit a screenshot of your code and output using the weekly survey link (this is the same link you used for the last two check ins). Check back here on Sunday for the answer! Make a calculator program that prints the results of an operation on two numbers.
Ask the user for two numbers. Add, subtract, multiply, divide, and mod the numbers, and store these results in variables. Then print the results out. Bonus: Ask the user to guess what the results will be. Print out true (if the user's guess equals the answer) or false (if not equal). Hint for the Bonus: When you print out an expression, if the expression is true, "true" will be printed on the screen (same for false). Sample: Enter a number: 4 Enter another number: 2 What is 4 + 2? 6 true 4 + 2 = 6 4 - 2 = 2 4 * 2 = 8 4 / 2 = 2 4 % 2 = 0 Submit a screenshot of your code and output using the weekly survey link! Check back for the answer on Sunday. |