Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Within Eclipse, create a project in called Assignment01. Call this program PlayWithNumbers. You are to use Guls for your input into the program. Your program

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Within Eclipse, create a project in called Assignment01. Call this program PlayWithNumbers. You are to use Guls for your input into the program. Your program may print to console however. Specifically you are to use option panes from the swing class, so you will have to import the javax.swing package into your program to do this. You should also format the numbers when dealing with money so that the are only two numbers behind the decimal point. You should use the NumberFormat class to do this. First thing you should do, open the file called PlayWithNumbers from Files/AssignmentDataFiles and copy it into the program you created above (i.e. you will overwrite it). You are to write a program that will do the following: Have the user enter an integer number (not a zero) and then determine how many odd numbers, even numbers, and zeros exist within this number, then print them out Print out this number digit by digit starting with the least significant digit first Have the user enter the amount of hours they worked this week, then calculate their earnings and print it out formatted using getCurrency Instance() from Number Format Ask the user if they wish to contribute to charity and obtain this answer Using this answer, recalculate the new earnings with the charity deduction and print it out. If the user does contribute to charity, print out that they are to get some ice cream. Randomly choose a flavor of ice cream and print this out In the end, print out "This program was written by Dr. Castaneda" (actually your name will be here) and "End of program" in a JOptionPane on two separate lines. You are to use the following methods in your program: int getLastDigit(int value) - extracts the least significant digit of value and returns it int truncateDigit(int value) - returns the value of value with the last digit truncated double getHours () - prompts the user and returns the amount of hours the user worked this week int contributeToCharity () - returns back the answer to whether the user contributes to charity or not void determine Pay (int answer, double earnings) - re- calculates the earnings with the deduction of contribution to charity and prints out whether they get ice cream or not In the end, your program will look similar to what is below but of course there can be many different kinds of runs based upon input from the user: Your Banner number is: 103245571 Zero digits: 1 Even digits: 2 Odd digits: 6 Here is your Banner number backwards: 175542301 mint f abeauty groove.wav You worked 32.5 hours this week. Your earnings are: $820. 62 With 3% charity deductions, your earnings are: $796.01 For your generosity, you will get chocolate ice cream! At the end of the program don't forget to display your name stating that you wrote this program and that it is the end of program. For this program, you are to turn in only the source code. You will copy it into the folder called Assignment01, thus your Assignment01 folder will contain only one document for this assignment. Finally, submit the PlayWith Numbers java file via Canvas for this assignment. import javax.swing.; import java.text.NumberFormat; import java.util. Random; public class PlayWithNumbers { * @param args 17 declare constants to be used in program final static double PAY_RATE - 25.25; final static double CHARITY = 0.03; final static int YES - ; final static int NO - 1 // declare format for numbers to be printed static NumberFormat fmt1 = NumberFormat.getCurrency Instance(); static NumberFormat fm2 - NumberFormat.getPercentInstance // instantiate object from Randon class // declare enumeration of types of ice cream public static void main(String[] args) { // declare variables to be used in program int oddCount - @, evenCount = 0, zeroCount - @; int value, digit, i, n, num, answer; double earnings, hours; String valueText; String nane - "NO NAME"; // replace with your name Boolean invalid = true; // prompt and read in an integer number // convert to integer // iterate through loop until user has entered // an integer value that is not zero get magnitude of the number // go through all digits of this numbers 77 and determine what kind of digit it is W print out results // get length of number as it // cane in as a string // convert to integer 1/ convert to integer // iterate through loop until user has entered // an integer value that is not zero // get magnitude of the number // go through all digits of this numbers // and determine what kind of digit it is 7/ print out results // get length of number as it // came in as a string 1/ convert to integer eger // one by one, print out each digit of number // starting with least significant digit System.out.println(); m.out.printlns. Il obtain the amount of hour's user has entered // and then print it out // calculate full earnings for user // print out earnings in in a nice format // obtain answer to whether user will // contribute to charity 11 calculate new earnings with deduction of cha OptionPane.showMessageDialog(null, "In This program was written by + name "In End of program , " Good bye!", OptionPane. INFORMATION MESSAGE); ) 17 end method main method main static int getLastDigit(int value) { int result; Wend method main static int getLastDigit(int value) int result; 11 extract least significant dig } return -1; // end method nextDigit static int truncateDigit(int value) int result; 1/ truncate number } return -1; // end method truncateDigit static double getHours() String hours Text; double hours; 1/ prompt and read in the amount 1/ of hours the user has worked hours Text - JOptionPane.showInput Dialog(null, "Please enter the amount of hours you worked this week " + "Assume you will earn $25.25 per hour and there is " + "no overtime."); // convert to double hours = Double.parseDouble(hoursText); } return hours; // end method getHours; static int contribute ToCharity int answer; // obtain the answer on whether the // user will contribute to a charity answer OptionPane.showConfirmDialog(null, "Would you like to donate 3% of your earnings to a charity?", "Charity question", JOptionPane . YES_NO_OPTION); } return answer // end method contribute ToCharity static void determinePay(int answer, double earnings) int type; 1 user will contribute to a charity if (answer -- YES) // user will contribute to a charity if (answer == YES) // determine what kind of ice cream 77 the user may get // user will NOT contribute to a charity else if (answer == NO) System.out.println("With *no* charity deductions your earnings are: " + fmt1.format(earnings) + ", no ice cream for you! :("); else H an error occurred here JOptionPane.showMessageDialog(null, "Error! Invalid value." "Invalid input", JOptionPane. ERROR_MESSAGE); 1/ end method determinePay 5} I/ end class PlayWithNumbers

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions