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

[identity profile] gingerspark.livejournal.com 2010-09-23 06:18 pm (UTC)(link)
You'll do great!
you're already better than me at it! ;)

[identity profile] thrihyrne.livejournal.com 2010-09-23 10:03 pm (UTC)(link)
I don't know how I'll end up, but if nothing else, I'm learning the basics and I have a textbook that's checked out for 18 weeks, so I can continue on and teach myself if it comes to that.