thrihyrne: Portland, OR (Starbuck by vilkibot)
Thrihyrne ([personal profile] thrihyrne) wrote2010-09-22 11:00 pm

My first java program

I wanted to weep. This is my first programming assignment. Cut because it's just code, and not even beautiful code at that, but it was the mathematics that made me want to tear out my hair.


import java.util.Scanner;
/**************************************
* Programming Assignment 1
*
* @author - Kristi Lee
* @version - V1 - 09//2010
*************************************/

/*************************************
* References and Acknowledgements:
*
*************************************/

public class ChangeMaker
{
/********************************************
* Change Maker is a program that converts an
* integer to the number of dollars, quarters,
* dimes, nickels and pennies.
********************************************/
public static void main (String args [])
{

// declarations
int input;
int dollar;
int modulusdollar;
int quarter;
int modulusquarter;
int dime;
int modulusdime;
int nickel;
int modulusnickel;
int penny;
int moduluspenny;



Scanner keyboard;

// input the seconds
keyboard = new Scanner(System.in);

System.out.print("Welcome to the Change Maker \n");

System.out.print("Enter the total amount of change:");
input = keyboard.nextInt();


dollar = input / 100;
modulusdollar = input % 100;
quarter = dollar / 25;
modulusquarter = modulusdollar % 25;
dime = quarter / 10;
modulusdime = modulusquarter % 10;
nickel = dime / 5;
modulusnickel = modulusdime % 5;
penny = nickel / 1;
moduluspenny = modulusnickel % 1;


System.out.print("Amount of change for $" + input + " is: \n");

System.out.print("\t Dollars:" + dollar + "\n");
System.out.print("\t Quarters:" + (modulusdollar / 25)) ;
System.out.print("\t Dimes:" + (modulusquarter / 10));
System.out.print("\t Nickels:" + (modulusdime / 5));
System.out.print("\t Pennies:" + (modulusnickel / 1));
}
}


I suck at this. But I think that syntax is my friend. It's the math that isn't.

:P

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting