Write a method that reads a number between 1,000 and 999,999 from the user and prints it with a comma separating the thousands.
When you print the number, useprintinstead ofprintln(this will make testing/grading easier, since the newline separator that gets inserted usingprintlnvaries per platform).
You can assume all user inputs will be valid integers between 1,000 and 999,999 (inclusive).
Example:Please enter an integer between 1000 and 999999: 892302
892,302For this problem, consider a sticker store in which all stickers are the same price. Write a method that computes the total of a sticker order based on the following inputs, which are prompted for from the user:
1. The price per sticker
2. The number of stickers in the order
Print the price of the order, formatted as money, with a dollar sign and two digits after the decimal point. Assume the user will always input a valid price per sticker (a valid floating point number >= 0), and a valid number of stickers (an integer >= 1).
problem4_compoundInterest(10 pts)
Write a method that computes the value of an investment compounded over time. The program must ask for the starting amount, the number of years to invest, the interest rate, and the number of periods per year to compound. The formula you'll use for this is:
A=P(1+rn)nt" role="presentation" style="display: inline-block; line-height: normal; font-size: 16px; text-align: left; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;">
where
Pis the principal amount (double)
ris the annual rate of interest (double)
tis the number of years the amount is invested (int)
nis the number of times the interest is compounded per year (int)
Ais the amount at the end of the investment
Your program must work like the following example. When you print the result, format/round all monetary amounts to two decimal places after the decimal point. Assume all user input will be of valid type and value (>= 0).
When you print the number, useprintinstead ofprintln(this will make testing/grading easier, since the newline separator that gets inserted usingprintlnvaries per platform).
Example:
Enter principal amount: 1500
Enter the annual rate of interest: 4.3
Enter the number of years the amount is invested: 6
Enter the number of times the interest is compounded per year: 4
$1500.00 invested at 4.3% for 6 years compounded 4 times annually is $1938.84.
problem5_creditCardPayoff(10 pts)
Write a method that will help you figure out how many months it will take to pay off a credit card balance. The program must ask the user to enter the balance of a credit card the the APR for the card. The method will return the number of months required to pay off the card (if the result is a fractional amount, round up to the nearest int).
The formula you'll use for this is:
n=−130∗ln(1+bp(1−(1+i)30))ln(1+i)" role="presentation" style="display: inline-block; line-height: normal; font-size: 16px; text-align: left; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;">
where
nis the number of months
iis the daily rate (APR divided by 365)
- Accept the APR input as a percentage, not a decimal, then do the division internally
- Assume APR will always be > 0 and <>
bis the balance
- Assume balance will always be >= 0
pis the monthly payment
- Assume monthly payment will always be > 0
Your program must work like the following example.
When you print the number, useprintinstead ofprintln(this will make testing/grading easier, since the newline separator that gets inserted usingprintlnvaries per platform).
Example:
What is your balance? 21394.88
What is the APR on the card? 5.9
What is the monthly payment you can make? 2000
It will take you 12 months to pay off this card.
Part B:
problem6_troubleshootCarIssues (10 pts)
Anexpert systemis a type of artificial intelligence program that uses a knowledge base and a set of rules to perform a task that a human expert might do. Often, these are implemented usingchat bots, which can conduct on-line chat conversations via text or text-to-speech, in lieu of providing direct contact with a live human agent.
Create a simple chat bot expert system that walks the user through troubleshooting issues with a car. Use the following decision tree to build the system:
Your program must work like the following example. Accept any input that starts with 'y' or 'Y' as a "yes", and any input that starts with 'n' or 'N' as a "no." Any other input should cause the program to print "Invalid input. Exiting." and end the program.
When you print the number, useprintinstead ofprintln(this will make testing/grading easier, since the newline separator that gets inserted usingprintlnvaries per platform).
Example:
Is the car silent when you turn the key? y
Are the battery terminals corroded? NO SIR
Replace cables and try again.
problem7_assessPasswordStrength (10 pts)
Create a method that determines the strength of a given password based on these rules:
- A very weak password contains only digits and is fewer than eight characters
- A weak password contains only letters and is fewer than eight characters
- A strong password contains at least one letter and at least one digit and is at least eight characters
- A very strong password contains at least one letter, at least one digit, and at least one special character (non letter or digit) and is at least eight characters
- All other passwords are medium strength
You can assume all input strings will have a length >= 1.
Examples:
problem7_assessPasswordStrength("12345"); // returns "very weak"
problem7_assessPasswordStrength("abcdef"); // returns "weak"
problem7_assessPasswordStrength("abc123xyz"); // returns "strong"
problem7_assessPasswordStrength("1337h@xor"); // returns "very strong"
problem7_assessPasswordStrength("1337h xor"); // returns "very strong"
problem7_assessPasswordStrength("123abc"); // returns "medium"
problem8_getNumericGrade and problem8_getLetterGrade (10 pts)
Implement two methods:
problem8_getNumericGrade and problem8_getLetterGrade.
problem8_getNumericGradetranslates a letter grade into a number grade. Letter grades are A, B, C, D, and F (case insensitive), possibly followed by + or -. Their numeric values are 4, 3, 2, 1, and 0. There is no F+ or F-. A plus sign increases the numeric value by 0.3, and a minus sign decreases it by 0.3. However, an A+ has value 4.0. If the input is not a valid letter grade, return -1.
problem8_getLetterGradetranslates a numeric grade (a number between 0 and 4, inclusive, that means this range includes the number 0 and the number 4) into the closest letter grade. For example, the number 2.8 (which might have been the average of several grades) would be converted to B-. Break ties in favor of the better grade; for example 2.85 should be a B. If the input is not a valid number between 0 and 4, return the string "Error."
Conversion table from input to output forproblem8_getLetterGrade:
Input |
Output |
>=0 and <> |
F |
>= 0.5 and <> |
D- |
>= 0.85 and <> |
D |
>= 1.15 and <> |
D+ |
>= 1.5 and <> |
C- |
>= 1.85 and <> |
C |
>= 2.15 and <> |
C+ |
>= 2.5 and <> |
B- |
>= 2.85 and <> |
B |
>= 3.15 and <> |
B+ |
>= 3.5 and <> |
A- |
>= 3.85 and <> |
A |
4.0 |
A+ |
Anything else |
Error |
Examples:
problem8_getNumericGrade("G") // returns -1.0
problem8_getNumericGrade("a-") // returns 3.7
problem8_getNumericGrade("C+") // returns 2.3
problem8_getNumericGrade("B") // returns 3.0
problem8_getLetterGrade(2.85) // returns "B"
problem8_getLetterGrade(0.51) // returns "D-"
problem8_getLetterGrade(4.0) // returns "A+"
problem8_getLetterGrade(8.3) // returns "Error"
Problem 9: Rectangle (10 pts)
Implement a classRectangle. ARectangleis defined by its x- and y-coordinates of its upper-left and lower-right corners.
Your job is to determine whether the rectangle is a square, or is in "portrait" (vertically-oriented) or "landscape" (horizontally-oriented) orientation, and return the result in thegetOrientationmethod. Assume all coordinates will be validdoublevalues. Implement theRectangleclass using the template provided here:
Rectangle.java
Download Rectangle.java
Examples:
Rectangle r1 = new Rectangle(10.5, 22.5, 20.5, 12.5);
r1.getOrientation(); // returns "square"
Rectangle r2 = new Rectangle(10.5, 32.5, 21.5, 12.5);
r2.getOrientation(); // returns "portrait"
Rectangle r3 = new Rectangle(-10.5, 22.5, 21.5, 12.5);
r3.getOrientation(); // returns "landscape"
problem10_withoutX2 (10 pts)
Write a method that accepts aStringof any length as a parameter. If one or both of the first 2 chars in the string is the char 'x' (lower case only), return the string without those 'x' chars. Otherwise, return the string unchanged.
Examples:
problem10_withoutX2("xHi") // returns "Hi"
problem10_withoutX2("Hxi") // returns "Hi"
problem10_withoutX2("Hi") // returns "Hi"
problem10_withoutX2("XHi") // returns "XHi"