View Single Post
  #9 (permalink)  
Old 11-14-2007, 11:22 AM
Phobos0001 Phobos0001 is offline
Member
 
Join Date: Nov 2007
Posts: 20
Phobos0001 is on a distinguished road
first off, sorry for pasting in the wrong code above here, i tried to edit it however i dont have permissions, no matter though.

ok now ive got the loop sorted out and the rest of the code is pretty solid, no compile errors, but i may have missed some "logical" errors, but the program works, so im happy.

i do have one final thing to do, and i cant figure out why i cant get it to work..
i want to build a report of the acumulated totals, such as total tax, total including tax, ect, ect.

for that i need to write something like
Code:
ftax=tax++ ftotal=total++
is that right? if ftax and total are double data types and not intergers?

also i want to work out the average age, would i go about that by doing something like this..
Code:
int counter,age counter=0; { my input loop here tage=age++ counter ++ } average=tage/counter
is this a bad approach to do it?..
this is the program as it stands now, completed but the 2nd to last information_message does not accumulate the totals

Code:
import javax.swing.*; //impors java gui for dialog boxes ect import java.text.*; //imports java texts for text formatting import java.io.*; //imports input output detection and information (i think i need this) public class test //defines class name and access { public static void main(String[] args) //begins body { String agebox, namebox; //assigning variables names and datatypes double fee, age, tax, total, ffee, fage, ftax, ftotal; fee = 20.50; //initialising variables that require manual initialisation ffee = 0; fage = 0; ftax = 0; ftotal = 0; DecimalFormat num = new DecimalFormat(",##.00"); //formatting the text namebox =JOptionPane.showInputDialog("Enter Member's Name, leave blank to exit member entry "); // user input for name int len=namebox.length(); //declaring len as lenght of the namebox string while (len !=0) { agebox =JOptionPane.showInputDialog("Enter Member's Age: "); //user input for age age = Double.parseDouble(agebox); // assign age as a double for if-else chain if (age <= 7 ) //if-else chain for the member's fee {JOptionPane.showMessageDialog(null,"Warning Member's age is too low to leave unsurpervised", "WARNING!", JOptionPane.WARNING_MESSAGE);} //warn operater of young age else if (age <=17) { fee = 20.50;} else if (age <=21) { fee = 32.25;} else { fee = 45.75;} //end of if else chain tax = fee*10/100; //calculating tax and assigining it to a variable total = tax + fee; // adding fee and tax and assiginging it to a variable JOptionPane.showMessageDialog(null, "The member's name is " + namebox + "\nThe Member's age is " + agebox + "\nMember's fee is " + fee + "\nMember's tax is " + tax + "\nMember's fee including tax is " + total, "Gym Program", JOptionPane.INFORMATION_MESSAGE); //display's information of the current member namebox =JOptionPane.showInputDialog("Enter Member's Name, leave blank to exit member entry "); // user input for name len=namebox.length(); //declaring len as length of the namebox string fage=age++; ffee=fee++; ftax=tax++; ftotal=total++; } JOptionPane.showMessageDialog(null, "Today's totals are..." + "\ntotal age is: " + fage + "\ntotal fee is " + ffee + "\ntotal tax is: " + ftax + "\ntotal including tax is: " + ftotal, "Gym Program", JOptionPane.INFORMATION_MESSAGE); //display's information of the current member JOptionPane.showMessageDialog(null,"Thanks for using the program","beyatch",JOptionPane.INFORMATION_MESSAGE); System.exit(0); } }
thanks again everyone
Reply With Quote