Mist Posted October 9, 2003 Posted October 9, 2003 Down to 4 errors Fixed the math but no matter what i do dataIn.readline(); refuses to do its stuff import java.io.*; public class Change { public static void main(String[]args) throws IOException { BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in)); //Declaring Variables double quarters; double dimes; double nickels; double pennies; double total; //Taking it straight from the horses mouth System.out.println("How many Quarters do you have?"); quarters = dataIn.readline(); System.out.println("How many Dimes do you have?"); dimes = dataIn.readline(); System.out.println("How many Nickels do you have?"); nickels = dataIn.readline(); System.out.println("How many Pennies do you have?"); pennies = dataIn.readline(); //Adding up the cash quarters = (quarters*0.25); dimes = (dimes*0.10); nickels = (nickels*0.05); pennies = (pennies*0.01); total = quarters + dimes + nickels + pennies; //Projecting it to the world System.out.println("You have" + "$" + total); }// public static void main }//public class Change Share this post Link to post Share on other sites More sharing options...
syneze Posted October 9, 2003 Posted October 9, 2003 because readLine is for strings you need readInt() or readDouble() Share this post Link to post Share on other sites More sharing options...
Mist Posted October 9, 2003 Posted October 9, 2003 thx lol comp teacher is a good teacher but believes we need to figure this out on our own (too much of a noob to know and we dont have books as this is a transition year) Edit didnt work Im using doubles but it gives the same error Lets see best guess it should be dataIn.readline(); becuase it is taking info from the users input but it doesnt wok. Then i tried readln instead of using the full line and still nothing. Made it so that it would read the lines and convert them back to doubles but no such luck. /* Project: Calculates the ammount of money a person's change is worth ProjectName: Change Mailbox: Change */ import java.io.*; public class Change { public static void main(String[]args) throws IOException { BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in)); //Declaring Variables double coins1; //quarters double coins2;//dimes double coins3;//nickels double coins4;//pennies double allCoins;//sum of coins String strCoins1; String strCoins2; String strCoins3; String strCoins4; String strAllCoins; //Taking it straight from the horses mouth System.out.println("How many Quarters do you have?"); strCoins1= dataIn.readline(); //gets ammount of quarters System.out.println("How many Dimes do you have?"); strCoins2= dataIn.readline(); //gets ammount of dimes System.out.println("How many Nickels do you have?"); strCoins3= dataIn.readline(); //gets ammount of nickels System.out.println("How many Pennies do you have?"); strCoins4= dataIn.readline(); //gets ammount of pennies //Converting coins1 = Double.parseDouble(strCoins1); coins2 = Double.parseDouble(strCoins2); coins3 = Double.parseDouble(strCoins3); coins4 = Double.parseDouble(strCoins4); //Adding up the cash coins1 = (coins1*0.25); //multiplying by to get value of quarters coins2 = (coins2*0.10);//multiplying to get value of dimes coins3 = (coins3*0.05);//multiplying to get value of nickels coins4 = (coins4*0.01);//multiplying to get value of pennies allCoins = coins1 + coins2 + coins3 + coins4; // adds up all the values to get the total //Projecting it to the world System.out.println("You have" + "$" + allCoins); //displays users money }// public static void main }//public class Change Share this post Link to post Share on other sites More sharing options...
slugbug3311 Posted October 10, 2003 Posted October 10, 2003 This should work for you i got it to work you just needed some things fixxed up //Project: Calculates the ammount of money a persons change is worth //ProjectName: Change //Mailbox: Change import java.io.*; public class Change { public static void main(String[]args) throws IOException { BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in)); //Declaring Variables double coins1; //quarters double coins2;//dimes double coins3;//nickels double coins4;//pennies double allCoins;//sum of coins String strCoins1; String strCoins2; String strCoins3; String strCoins4; String strAllCoins; //Taking it straight from the horses mouth System.out.println("How many Quarters do you have?"); strCoins1= dataIn.readLine(); //gets ammount of quarters System.out.println("How many Dimes do you have?"); strCoins2= dataIn.readLine(); //gets ammount of dimes System.out.println("How many Nickels do you have?"); strCoins3= dataIn.readLine(); //gets ammount of nickels System.out.println("How many Pennies do you have?"); strCoins4= dataIn.readLine(); //gets ammount of pennies //Converting coins1 = Double.parseDouble(strCoins1); coins2 = Double.parseDouble(strCoins2); coins3 = Double.parseDouble(strCoins3); coins4 = Double.parseDouble(strCoins4); //Adding up the cash coins1 = (coins1*0.25); //multiplying by to get value of quarters coins2 = (coins2*0.10);//multiplying to get value of dimes coins3 = (coins3*0.05);//multiplying to get value of nickels coins4 = (coins4*0.01);//multiplying to get value of pennies allCoins = coins1 + coins2 + coins3 + coins4; // adds up all the values to get the total //Projecting it to the world System.out.println("You have" + "$" + allCoins); //displays users money }// public static void main }//public class Change Share this post Link to post Share on other sites More sharing options...
Mist Posted October 10, 2003 Posted October 10, 2003 thx xlug but i figured it out yesterday. I made an applet version and still ran into trouble so went back to what i was doing and figured it out. Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now