Question
Java Problem1: In this problem we will ask the use to enter a value < 1,000 and > 999,999 without a comma and add the
Java Problem1: In this problem we will ask the use to enter a value < 1,000 and > 999,999 without a comma and add the comma.
Part 1:
a. Create a class named Problem1
b. Create an instance value named value.
c. Create a constructor that sets the variable value to an integer argument named v.
d. Create a method named addComma. It will return a String and will not have an argument.
e. Create a String variable named commaNumber;
f. Create an integer named thousands.
g. Create an integer named hundreds.
h. Assign to thousands the result of dividing value by one thousand.
i. Assign to hundreds the result of using the modulus operator to find the remainder of dividing value by one thousand.
j. Assign to commaNumber thousands + a comma + hundreds
k. Return commaNumber.
Part 2:
a. Create a tester class named Problem1Tester (Reminder all tester classes have a main method)
b. Import Scanner
c. Create a Scanner object
d. Prompt for a number between 1,000 and 99,999
e. Get the number from the user and store it in a variable.
f. Create a Problem1 object
g. Print the result from addComma (this can be done directly in the print statement or you can create a new variable and print it)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started