4 simple tasks for intro to Java
I’m stuck on a Java question and need an explanation.
Task 1 – Multiple choice, string comparison (case insensitive),
Java file: HW3_Faces.java
Write a program that allows the user to print one of 4 possible faces. The options for faces are:
- bo – Bold, Open eyes
- bc – Bold, Closed eyes
- ho – Hat, Open eyes
- hc – Hat, Closed eyes
The program should be
case insensitive, meaning that it will work well with both upper case and lower case letters or a combination of those. E.g.all these are valid choices: bo, BO, bO, Bo.
Hints:
- You may want to use the s.toLowerCase() or s.toUpperCase() where s is a string. Keep in mind that they do not modify s, but they return a new string.
- Do NOT use == to compare strings.
- Develop your program gradually.
------- Sample run 1_x000D_ Enter face choice (bo/bc/ho/hc): ho_x000D_ ________x000D_ __|_______|____x000D_ | o o |_x000D_ | ^ |_x000D_ - /_x000D_ -----_x000D_ Bye_x000D_ _x000D_ ------- Sample run 2 (Note: case insensitive: works for Uppercase letters as well)_x000D_ Enter face choice (bo/bc/ho/hc): Ho_x000D_ ________x000D_ __|_______|____x000D_ | o o |_x000D_ | ^ |_x000D_ - /_x000D_ -----_x000D_ Bye_x000D_ _x000D_ ------- Sample run 3_x000D_ Enter face choice (bo/bc/ho/hc): bo_x000D_ -------_x000D_ / _x000D_ | o o |_x000D_ | ^ |_x000D_ - /_x000D_ -----_x000D_ Bye_x000D_ _x000D_ ------- Sample run 4_x000D_ Enter face choice (bo/bc/ho/hc): BC_x000D_ -------_x000D_ / _x000D_ | - - |_x000D_ | ^ |_x000D_ - /_x000D_ -----_x000D_ Bye_x000D_ _x000D_ ------- Sample run 5_x000D_ Enter face choice (bo/bc/ho/hc): hc_x000D_ ________x000D_ __|_______|___x000D_ | - - |_x000D_ | ^ |_x000D_ - /_x000D_ -----_x000D_ Bye_x000D_
Task 2
File: HW3_Wiki.java
WIkipedia pages have a specific webpage address. Any address starts with
https://en.wikipedia.org/wiki/ and then continues with the topic for that page e.g.
Computer_science,
Java_(programming_language). See examples below:
https://en.wikipedia.org/wiki/Computer_science_x000D_ https://en.wikipedia.org/wiki/Java_(programming_language)_x000D_ https://en.wikipedia.org/wiki/Imagine_Dragons _x000D_
Write a program that reads a string from the user. If it is a valid wikipedia webpage, it extracts and prints the topic for that page. If it is not a valid address it prints the message
Not a valid wikipedia webpage address.
Hint: How can the fact that all valid addresses start with the same text before the topic name help you extract the topic name?
You do NOT need to handle the case where the webpage address is correct, but it is written in uppercase letters. You can assume it is all lowercase.
---- Sample run 1 _x000D_ This program will extract the topic from a valid Wikipedia webpage address._x000D_ Enter a web address: https://en.wikipedia.org/wiki/Computer_science_x000D_ Topic: Computer_science_x000D_ Bye._x000D_ _x000D_ ---- Sample run 2 _x000D_ This program will extract the topic from a valid Wikipedia webpage address._x000D_ Enter a web address: http://vlm1.uta.edu/~alex/courses/1310/homework/hw02.html_x000D_ Not a valid wikipedia webpage address._x000D_ Bye._x000D_ _x000D_ ---- Sample run 3 (note that even though this is a special case, you should NOT need to do anything special about it. The code that works for normal cases will just for this as well.)_x000D_ This program will extract the topic from a valid Wikipedia webpage address._x000D_ Enter a web address: https://en.wikipedia.org/wiki/_x000D_ Topic: _x000D_ Bye._x000D_
Task 3 – complex boolean expression or nested if-statements
Java file: HW3_Aries.java
Write a program that reads the month and the day from the user and prints whether or not someone born on that date is under the Aries astrological sign or not.
Anyone born between and including March 21 and April 19 is Aries.
You can assume that the month and day are given as integer numbers (e.g. do not worry about user enterring March)
Hint: write the condition for an Aries date in March. Write the condition for April. Put these two together.
--- Sample run:_x000D_ Enter the month: 3_x000D_ Enter the day: 21_x000D_ Aries._x000D_ _x000D_ --- Sample run:_x000D_ Enter the month: 4_x000D_ Enter the day: 19_x000D_ Aries._x000D_ _x000D_ --- Sample run:_x000D_ Enter the month: 3_x000D_ Enter the day: 27_x000D_ Aries._x000D_ _x000D_ --- Sample run:_x000D_ Enter the month: 4_x000D_ Enter the day: 6_x000D_ Aries._x000D_ _x000D_ --- Sample run:_x000D_ Enter the month: 3_x000D_ Enter the day: 40_x000D_ Not Aries._x000D_ _x000D_ --- Sample run:_x000D_ Enter the month: 4_x000D_ Enter the day: -5_x000D_ Not Aries._x000D_ _x000D_ --- Sample run:_x000D_ Enter the month: 2_x000D_ Enter the day: 27_x000D_ Not Aries._x000D_
Extra (for practice, not grade): recognize the month in other formats as well: Mar, March, 3, 03, Apr, April, 4, 04.
Task 4 – ‘long’ program, multiple step processing, non-trivial data manipulation, formatted printing, if-statements
Java file name: HW3_Bills.java
Write a program that asks the user for an amount and calculates and print the minimum number of bills of 20,10,5, and 1 needed to pay that amount.
In order to use the minimum number of bills, you must pay as many bills of 20 as possible, and then the largest number of bills of 10 and so on.
Logic/ Processing steps:
- Compute and store the max number of bills of 20. Hint: this is the same as asking how many times can I fit 20 into my amount?
- Compute the remaining amount. Hint: This is the remainder of dividing the amount by 20.
- Compute and store the max number of bills of 10.
- Compute the remaining amount.
- Compute and store the max number of bills of 5.
- Compute the remaining amount. Note that this amount (that could not be payed with 20,10 and 5) can only be payed with bills of 1, so this is how many bills of 1 are needed.
- Print table formatted (aligned) as shown in the sample run. In particular the cells for the number of bills should have a width of 4 spaces. (E.g. see how the number of bills of 20 in sample run 1 (30) and in sample run 2 (3) do not miss align the table cells.)
- Prints the total number of bills given (of any value).
Hints:
- You should save the number of each bills since you need to use it (to print) twice.
- A cell in the last row in the table will have nothing printed when the number of bills is 0 and a number otherwise. What Java instruction allows you to choose to do one action or another based on data?
- To ‘print nothing’ you can print an empty string (“”) or a string with just a space in it (” “).
- You can print a SINGLE line in Java with SEVERAL printf statements. It does not have to be a single printf.
Consider using different printf() for the cell for each bill. So one printf will print ” 2|” and another will print ” 1|”, etc.
Finally, for the last line, note that as you print the cell, you will have either a number or a space to print.
Grading:
- 2 pts – prints message about what program does and gets user input.
- 5 pts – total bills printed at the end: calcuate (4 pts), print (1 pts)
- 4 pts – print table lines: horizontal lines (2 pts), vertical lines (2 pts)
- 4pts – the 2-nd row of the table is formated. It reserves spaces in cells with numbers (especially for bills of 20)
- 1pt – table header row
- 12 pts – calculate and save count of each bill (12 pts: 3 pts per bill)
- 6 points – print the last row with correct spaces instead off 0
- 6 pts – program style: good variable names (2 pts), correct indentation (2pts) , comments (2pts)
--- Sample run 1:_x000D_ This program will calculate the minimum number of bills of 20,10,5, and 1 needed to pay a given amount._x000D_ Enter the integer amount that you need to pay: 619_x000D_ ------------------------------------_x000D_ | Bill value | 20| 10| 5| 1|_x000D_ ------------------------------------_x000D_ | Num of bills | 30| 1| 1| 4|_x000D_ ------------------------------------_x000D_ | Num of bills | 30| 1| 1| 4|_x000D_ ------------------------------------_x000D_ Total bills: 36_x000D_ Bye_x000D_ _x000D_ --- Sample run 2:_x000D_ This program will calculate the minimum number of bills of 20,10,5, and 1 needed to pay a given amount._x000D_ Enter the integer amount that you need to pay: 74_x000D_ ------------------------------------_x000D_ | Bill value | 20| 10| 5| 1|_x000D_ ------------------------------------_x000D_ | Num of bills | 3| 1| 0| 4|_x000D_ ------------------------------------_x000D_ | Num of bills | 3| 1| | 4|_x000D_ ------------------------------------_x000D_ Total bills: 8_x000D_ Bye_x000D_ _x000D_ --- Sample run 3:_x000D_ This program will calculate the minimum number of bills of 20,10,5, and 1 needed to pay a given amount._x000D_ Enter the integer amount that you need to pay: 2_x000D_ ------------------------------------_x000D_ | Bill value | 20| 10| 5| 1|_x000D_ ------------------------------------_x000D_ | Num of bills | 0| 0| 0| 2|_x000D_ ------------------------------------_x000D_ | Num of bills | | | | 2|_x000D_ ------------------------------------_x000D_ Total bills: 2_x000D_ Bye_x000D_ --- Sample run 4:_x000D_ This program will calculate the minimum number of bills of 20,10,5, and 1 needed to pay a given amount._x000D_ Enter the integer amount that you need to pay: 25_x000D_ ------------------------------------_x000D_ | Bill value | 20| 10| 5| 1|_x000D_ ------------------------------------_x000D_ | Num of bills | 1| 0| 1| 0|_x000D_ ------------------------------------_x000D_ | Num of bills | 1| | 1| |_x000D_ ------------------------------------_x000D_ Total bills: 2_x000D_ Bye
Try and do the final task first. All program output should match the sample runs exactly.
Need your ASSIGNMENT done? Use our paper writing service to score good grades and meet your deadlines.
Order a Similar Paper Order a Different Paper