java - What is the most stylistically correct way to declare these variables? -
i new computer science , have written project uses lot of variables. have code in main method , @ beginning of main method, have of variables declared. think pretty ugly. don't want change around whole code , mess scope. there way declare these same variables , have more efficient/professional?
int numplain; int numpepperoni; int pizzasordered = 0; int slicesordered = 0; int charmsordered = 0; int totalslices = 0; int totalcharms = 0; int totalplain = 0; int totalpepperoni = 0; double plaincost = 0.0; double pepperonicost = 0.0; double slicecost = 0.0; double piecost = 0.0; double charmcost = 0.0; boolean flag = true; double totalcost = 0.00; double paymentamt = 0.0; int numpies = 0;
you could try inline of variable declarations/initializations this:
int numplain, numpepperoni; int pizzasordered = 0, slicesordered = 0, charmsordered = 0; int totalslices = 0, totalcharms = 0, totalplain = 0, totalpepperoni = 0; double plaincost = 0.0, pepperonicost = 0.0, slicecost = 0.0, piecost = 0.0, charmcost = 0.0; boolean flag = true; double totalcost = 0.00; double paymentamt = 0.0; int numpies = 0;
this make code appear bit less verbose , groups variables related each other.
Comments
Post a Comment