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
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 17 Programmer: 7/ Course: Semester 71. Assignment 7/ Due Date: your name here> COSC 1437 Section
Semester and year here assignment number heres due date here import javax.swing. import java.text. NuberFormat; 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; 17 declare format for numbers to be printed static NumberFormat futi - Number Format.getCurrency Instance(); static NumberFormat fmt2 - NumberFormat.getPercentInstance(); E l instantiate object from Random class // declare enumeration of types of ice cream public static void main(String[] args) { // declare variables to be used in program int oddCount - evenCount - @, zeroCount = 0; int value, digit, i, n, num, answer; double earnings, hours; String valueText; String name - "NO TAME"; // 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 11 get magnitude of the number // go through all digits of this numbers // and determine what kind of digit it is e t results // print out results 11 get length of number as it // came in as a string // convert to integer // one by one, print out each digit of number // starting with least significant digit System.out.println(); // obtain the amount of hours user has entered 17 and then print it out // calculate full earnings for user // print out earnings in in a nice format 7/ obtain answer to whether user will // contribute to charity // calculate new earnings with deduction of charity JOptionPane.showMessageDialog(null, " This program was written by + name + " End of program.", " Good bye!", OptionPane. INFORMATION MESSAGE); // end method main } static int getLastDigit(int value) int result; // extract least significant digit return -1; // end method next Digit ) static int truncateDigit(int value) int result; W truncate number } return -1; // end method truncateDigit } return -1; // end method truncateDigit static double getHours() String hoursText; double hours; // prompt and read in the amount // 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 JOptionPane.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; // user will contribute to a charity if (answer = YES) // determine what kind of ice cream // 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 // an error occurred here JOptionPane.showMessageDialog(null, "Error! Invalid value.", "Invalid input", JOptionPane. showMessageDialog(null, "Error! Invalid value. "Invalid input JOptionPane. ERROR_MESSAGE); // end method determinePay } // 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

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

9. Mohawk Industries Inc.

Answered: 1 week ago

Question

8. Satyam Computer Services Limited

Answered: 1 week ago

Question

2. Explain how the role of training is changing.

Answered: 1 week ago