import java.util.Scanner; /** * Ask User For Dollars and Cents, * Outputs Number Of Pinball Games Can Play and cHANGE Left Over * * @author William McDaniel Albritton */ public class PinballGames { /** * The main() Method Is Needed To STart The Program.. * * @param args The commandline arguments are not used. */ public static void main(String[] args) { //Initializing Scanner Variable for input.. Scanner keyboard = new Scanner(System.in); //Initialize String variables to store String input String dollarWord = new String("blank"); String centWord = new String("blank"); //Initialize Integer (Whole Number) Variables All To Zero (0). Integer dollars = new Integer(0); Integer cents = new Integer(0); Integer totalCents = new Integer(0); Integer gameCount = new Integer(0); Integer leftoverChange = new Integer(0); //Use This VAriable To Store The Cost Of 1 Game.. //"final" Means That The Value CANNOT Be Changed. //We Call This Kind Of Variable A "constant". //by convention, a constant variable is written in all uppercase letters final Integer GAME_PRICE = new Integer(25); //Prompt tHE User For TO Input Dollars. System.out.print("Please enter the number of dollars you have: "); //Method "nextLine()" Will Return one line From The Input Stream (What The User Types). dollarWord = keyboard.nextLine(); //Prompt tHE User For TO Input Cents. System.out.print("Please enter the number of cents you have: "); centWord = keyboard.nextLine(); //convert String-formatted data to Integer-formatted data dollars = Integer.parseInt(dollarWord); cents = Integer.parseInt(centWord); //Make Some Calculations. totalCents = dollars * 100 + cents; //Integer Division CUTS OFF (DOES NOT Round UP!) THE Decimal Point. gameCount = totalCents / GAME_PRICE; //Modulus (%) Is The Remainder Of INteger Division. leftoverChange = totalCents % GAME_PRICE; //Output To The Screen Using "\n" To Do The Newline.. System.out.print("You have a total of " + totalCents); System.out.print(" cents.\nThe price of a pinball game is "); System.out.print(GAME_PRICE+" cents.\n"); System.out.print("You can plan " + gameCount); System.out.print(" pinball games with leftover change of "); System.out.print(leftoverChange + " cents.\n"); }//end of main() }//end of class