Integers , Floats & Doubles

OliverE

Power member.
Reputation
0
eclipse.png


Integers & Variables


Ok so this project calculates what notes you require to make a certain value.
For example, what notes do I need to make £75, the answer is one £50 note, a £20 note and a £5 note.

  • Create a new project and class with the names of BankTeller
  • Paste the code below into the code view
  • Edit the "int sterling" value to something of your choice
  • Run the application
  • The console will tell you what notes are required to make that certain value

Bank Teller Code
[java]class BankTeller
{
public static void main ( String args [ ] )
{

//declare and initialise variables
int sterling = 189;
String indent = " " ;
int fifties, twenties, tens, ones ;
ones = sterling;

//perform calculations
fifties = ones / 50 ;
ones = ones % 50 ;
twenties = ones / 20;
ones = ones % 20 ;
tens = ones / 10 ;
ones = ones % 10 ;

//output results
System.out.println( "The notes are: " ) ;
System.out.println( ) ;
System.out.println( indent + "Fifties: " + fifties ) ;
System.out.println( indent + "Twenties: " + twenties ) ;
System.out.println( indent + "Tens: " + tens ) ;
System.out.println( indent + "One pound coins : " + ones ) ;
System.out.println( ) ;
System.out.println( "Total amount: " + sterling + " pounds" ) ;
}
}[/java]
Explaination
This snippet once again makes use of the print line function. I dont think i need to explain this one again. The calculations may need some explaining though.

Basically to work out how many fifties you require, it does the sterling value (189) divided by 50. Which is 3.78, but its a integer value so its actually 3 (3 fifties are required)

It then works out what the remainder is from that last calculation by using the % which I explained in the last tutorial. 39 is the remainder.

The calculations work on from there, so how many twenties go into 39? 1 twenty, 19 is the remainder. How many tens go into 19? 1 ten, 9 is the remainder etc etc.


Challenge
Ok so the BankTeller code tells the BankTeller what notes he requires to make a certain value.
The current code is missing the GBP currency note of Five pounds.

So just look at the code and see if you can modify the code so that it includes five pounds, aswell as the rest already there.
(There should be £50, £20, £10, £5, £1)

Everyone who PMs me the correct working code earns themselves 500 bytes


Thats It! More Tutorials to Come
 
RE: BankTeller

Obviously Carolus is going to win this.



Just a suggestion, in addition to posting source code, could you explain what everything does?
 
RE: BankTeller

Its pritty simple and ive added comments to the code so you know whats going on, but ill add that if you want me to :)
 
RE: BankTeller

Comeone guys I want to see you guys following tutorials :p
 
RE: BankTeller

I would do this, and I wish I knew Java, but I just cannot get into it.
 
RE: BankTeller

BleepyEvans said:
Why, whats up?

It just takes too long.

Why do I have to write 75 million lines of code to print "Hello World!"

Makes me wonder how many millions of lines of code go into real programs that actually do something.
 
RE: BankTeller

Lol its 1 line :p
System.out.println("HelloWorld");

The other 2 lines are just the class name and identifying which is the main.
 
RE: BankTeller

public class HelloWorld! {
public static void main ( System args [] ){
System.out.println("Hello World!");
}
}

Holy shit I actually remembered all that.
 
RE: BankTeller

not actually correct but you got the most of it right :p
But you'd still get a compile error :p

2nd line: public static void main ( String args [ ] ){

Still missing 74,999,997 lines of code though (apparently :p)
 
RE: BankTeller

Yeah I just realized I forgot that part.

How about 7000ß for the effort?
 
RE: BankTeller

BleepyEvans said:
If it was spot on,,,maybe :p

[offtopic]Give me something to write in PHP.[/offtopic]
 
RE: BankTeller

The challenge is learn2read.

Bottom of the OP has the challenge mate. ;)
 
RE: BankTeller

Ok so the BankTeller code tells the BankTeller what notes he requires to make a certain value.
The current code is missing the GBP currency note of Five pounds.
So it works out what notes you need from £50 notes £20 notes, £10 notes, and £1 coin.

So just look at the code and see if you can modify the code so that it includes £5, aswell as the rest already there.
(There should be £50, £20, £10, £5, £1)
 
Back
Top