java - Weird error on driver class -
i'm writing driver class piggy bank class created. idea is supposed add different types of coins (user input) , total cents , display them until "x" input user. think have code right, there weird issue if use "countmoney" accessor code, tells me of variables in driver class uninitialized. if remove it, there no errors shown eclipse. i've printed source , driver class below:
package piggy; /** * @author kevin * */ import java.util.scanner; import piggy.piggybank; public class piggybanktester { /** * @param args */ public static void main(string[] args) { string num = "str", num1; int count = 0; int money; scanner scan = new scanner(system.in); scanner scan2 = new scanner(system.in); piggybank total = new piggybank(); system.out.println("welcome piggy bank tester"); system.out.println("what type of coin add (q, h, d or x exit)?"); num1 = scan.nextline(); num = num1.touppercase(); { if (num.equals("x")) system.out.println("goodbye."); else if (num != "x") { system.out.println("how many wish add?"); count = scan.nextint(); if (num.equals("q")) total.addquarters(count); else if (num.equals("h")) total.addhalfdollars(count); else if (num.equals("d")) total.adddollars(count); else if (num.equals("x")) system.out.println("goodbye."); } } { total.calculate(); money = total.countmoney(); system.out.println("the piggy bank contains " + money + " cents."); } } }
you don't need (string q,d,h,x) . have declared variables without give them value name. way can change if-else statements , set , example if want num equal q ---> if (num.equals("q") ) <---
Comments
Post a Comment