problem figuring out how to carry over and drop values in currency.
I'm in a beginner JAVA class and we're only 5 weeks in. We are using jGrasp to write our code. We haven't gotten into anything particularly fancy, but we have a doozy of an assignment to which we can only use what we have learned so far.
We had a similar problem that asked us to input seconds, and then covert that to DD:HH:MM:SS and I was able to figure that one out, but...
This problem is dealing with converting old British currency to the new decimal system, and then changing it to dollars and then Euros. I get the basic concept, and my code will return basically the right numbers, but the pounds value has a decimal equal to the pence number, and the pence value is also in decimal form. I would like to remove the decimal in pounds value and the pence value. Until my recent compile, I was getting values over 100 for Pence, which is completely wrong, but as an amateur I could not tell you why it stopped doing that.
Am I missing something in if statements?
Here is my code so far (before I enter in the dollar and Euro values). We have not covered BigDecimal or any currency classes. Also, I am pretty sure the conversions we were given aren't 100% accurate, but are for demonstration purposes.
So if I enter in 12 Pounds, 200 Shillings, 100 Pence, I get 14.4 Pounds, 40.0 Pence.
public class OldPounds
public static void main (String  args)
//Input old Pounds
oldPoundInput = JOptionPane.showInputDialog( "Enter Old Pounds amount.");
//Input old Shillings
oldShillingInput = JOptionPane.showInputDialog( "Enter Old Shillings amount.");
//Input old Pence
oldPenceInput = JOptionPane.showInputDialog( "Enter Old Pence amount.");
//Convert Pounds from String to int
oldPound = Integer.parseInt(oldPoundInput);
//Convert Shillings from String to int
oldShilling = Integer.parseInt(oldShillingInput);
//Convert Pence from String to int
oldPence = Integer.parseInt(oldPenceInput);
int newPence; //To convert from shillings to it's current pence value
newPence = .20*(oldShilling);
int halfPence; //to convert from the old pence system to the current value
halfPence = 2*(oldPence);
int newPenceTotal; //to combine both previous pence calculations into one workable pence value
newPenceTotal = (newPence + halfPence);
int penceToPound; //How many Pence in a pound
penceToPound = (newPenceTotal/100);
int penceToPoundRemainder; //remainder
penceToPoundRemainder = (newPenceTotal%100);
newPenceTotal = penceToPoundRemainder; //changing newPenceTotal to the remainder
int poundToPound; //converting the old pound system to the new pound. ratio of 1:1
poundToPound = oldPound;
poundTotal = (poundToPound+penceToPound); //adding both ways of converting to pounds
JOptionPane.showMessageDialog( null, poundTotal + " Pounds, "
+ newPenceTotal + " Pence.");
I also get a minor error saying that
Which I get, because it's an int returning a decimal value, but the other primitives seem like over-kill.
OldPounds.java:37: possible loss of precision
found : double
newPence = .20*(oldShilling);
I know I've rambled on a lot here, but any suggestions would be greatly appreciated. I'm not necessarily looking for somebody to code this for me, but rather some advice and instruction on the proper method of doing so.
Thank you very much.