Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: need help with my code!

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default need help with my code!

    a sales application that should that sells variety of items it should: capture individual sale information, calculate and display total without and with tax and any discount if applicable. (From time to time the manager provides discounts on sales that go beyond a specific amount).
    a. To complete a sale the following information must be captured for each item: Date, ItemCode, Item Name, Unit Cost, Quantity
    i have trouble with getting to 2. Provides the details of the highest sale for the day.
    3. Display the name and quantity of the item which was sold the most, thus far
    4. Provides display of details for all sales made along with the overall total for a particular day and if you had written to file the option to display all Sales for the store.


    import java.awt.Frame;
    import java.io.*;
    import java.text.DecimalFormat;
    import java.text.NumberFormat;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.List;
    import java.util.TreeMap;


    import java.awt.*;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JOptionPane;
    import javax.swing.JSeparator;

    public class Gunstore{


    public static void main(String[] args) throws IOException {
    int maincontrol=0;
    double discount=0.1;//currently 10% discount per purchase
    double tax=0.17;//current 17% tax oer purchase
    int quantity=0;
    String highitem = null;
    double hq = 0;
    String shq=null;
    int[] count = null;

    String accessboss="admin";
    String accessclerk="clerk";
    String passboss="admin";
    String passclerk="clerk";
    String user;
    String pass="";
    JOptionPane.showMessageDialog(null, "D. S. C. D ™ "
    +"\n\n\n" +"Please Login for Access.");
    // user=JOptionPane.showInputDialog(null,"UserName: ");//admin+user
    //pass=JOptionPane.showInputDialog(null,"Password: ");//admin
    //if(user.equals(accessboss) && pass.equals(passboss)){
    while(maincontrol==0){
    String salesinfo="Sales Information.txt";
    File salesfile= new File(salesinfo);
    Calendar currentDate = Calendar.getInstance();
    String squantity = null;
    SimpleDateFormat formatter= new SimpleDateFormat("yyyy/MMM/dd");
    String dateNow = formatter.format(currentDate.getTime());
    double total=0;
    String allstoresale = null;
    //int item = 0;
    //String pc = null;
    String itemname = null;
    double unitcost=0;
    //int sales = 0;
    //String prodcode=null;
    String[] itemName = { "Desert eagle","Colt 1911 ", "Revolver", "Smith & Wesson 357","Sig p226","Beretta M9","Glock 18","HK Mp5","Bushmaster Carbon 15", "IMI mini","Kalashnikov AK-12","M1 Thompson" };
    //JOptionPane.showMessageDialog(null, "Receive a 10% on purchases more than $3000 ");

    //String buy = null;
    String sunitcost;
    //int imi=0,kal=0,tom=0,bus=0,g18=0,sw=0,ber=0,col=0,rev =0,des=0,mp5=0,c15=0;


    String stotal = null;
    String itemcode = null;

    int menu=(Integer.parseInt(JOptionPane.showInputDialog ("\t Logged in as: Manager" +"\n\n\n(1) \t to make a purchase\n" +"(2) \t Highest Sale for the day \n"
    +"(3)\t Item that sold the most \n"
    +"(4)\t All Sales for day \n"+"(5)\t Display all Sales for the Store \n"
    +"(6)\t Manage discount or GCT \n" +"(0)\tExit \n")));


    switch(menu){

    case 0: System.exit(menu);

    case 1:main1(salesfile,discount,tax,shq,highitem,hq);
    maincontrol=0;
    break;

    case 2: highsale(total);
    maincontrol=0;
    break;

    case 3:
    int maxIndex = maxsold( count );
    System.out.println( "Weapon that sold the most is: " +itemName[maxIndex] );
    maincontrol=0;
    break;


    case 4:


    case 5: allstoresale(salesfile);
    maincontrol=0;
    break;

    case 6: discount=setdiscount( discount,tax );
    maincontrol=0;
    break;


    }
    }//}
    //else if(user.equals(accessclerk) && pass.equals(passclerk)){

    while(maincontrol==0){
    String salesinfo="Sales Information.txt";
    File salesfile= new File(salesinfo);
    Calendar currentDate = Calendar.getInstance();
    String squantity = null;
    SimpleDateFormat formatter= new SimpleDateFormat("yyyy/MMM/dd");
    String dateNow = formatter.format(currentDate.getTime());
    double total=0;
    //int item = 0;
    //String pc = null;
    String itemname = null;
    double unitcost=0;
    //int sales = 0;
    //String prodcode=null;


    //JOptionPane.showMessageDialog(null, "Receive a 10% on purchases more than $3000 ");

    //String buy = null;
    String sunitcost;



    String stotal = null;
    String itemcode = null;
    int imi=0,kal=0,tom=0,bus=0,g18=0,sw=0,ber=0,col=0,rev =0,des=0,mp5=0,c15=0;
    int menu=(Integer.parseInt(JOptionPane.showInputDialog ("\t Logged in: Sales Clerk" +"\n\n\n(1) \t to make a purchase\n" +"(0)\tExit \n")));

    switch(menu){

    case 0: System.exit(menu);

    case 1:main1(salesfile,discount,tax,shq,highitem,hq);
    maincontrol=0;
    break;

    default:
    JOptionPane.showMessageDialog(null, "You donot have Access Loser!");
    maincontrol=0;
    break;
    }


    }
    }


    public static void highsale(double total){
    double temp=0;
    double high = 0;
    NumberFormat formatterx = new DecimalFormat("#0.00");
    if(total>temp){
    high=total;
    }
    else{
    JOptionPane.showMessageDialog(null, "There has not been a Sale as yet!");
    }

    JOptionPane.showMessageDialog(null, "Highest Sale for Today is: " +formatterx.format(high));

    }



    private static void allstoresale(File salesfile) throws IOException {
    String displaysales;
    try{
    FileReader fr = new FileReader(salesfile);
    BufferedReader br = new BufferedReader(fr);

    while((displaysales = br.readLine()) != null){
    System.out.println(displaysales);

    }

    }catch(IOException ioe){
    System.out.println(ioe);
    }
    }

    //method maxsold() returns the index of the maximum value in the array
    public static int maxsold(int[] count)
    {
    int maxValue = count[0];
    int maxIndex = 0;
    for(int i=1;i < count.length;i++)

    {

    if(count[i] > maxValue){

    maxValue = count[i];

    maxIndex = i;

    JOptionPane.showMessageDialog( null, +maxValue );

    }
    }

    // return the index corresponding to the maximum value in the array

    // which contains the most weapons sold
    return maxIndex;
    }
    public static double setdiscount(double discount, double tax){
    int ans=0;
    double xdis;
    double xtax;
    int ans1=0;
    JOptionPane.showMessageDialog(null,"The Current Discount is at: " +discount+"% per total purchase totaling more than $3000 ");

    ans=JOptionPane.showConfirmDialog(null, "Do you want to change Discount rate? ");
    if(ans==JOptionPane.YES_OPTION){
    xdis=Double.parseDouble(JOptionPane.showInputDialo g("Enter new Discount in '%' "));
    xdis=(xdis*0.01);
    discount=xdis;
    JOptionPane.showMessageDialog(null,"The New discount is set @ " +discount+"% per total purchase totaling more than $3000 ");

    }else if(ans==JOptionPane.NO_OPTION)
    {
    JOptionPane.showMessageDialog(null,"The Current Tax is at: " +tax +"% per purchase ");
    ans1=JOptionPane.showConfirmDialog(null, "Do you want to change Tax rate? ");
    if(ans==JOptionPane.YES_OPTION){
    xtax=Double.parseDouble(JOptionPane.showInputDialo g("Enter new Tax in '%' "));
    xtax=(xtax*0.01);
    tax=xtax;
    JOptionPane.showMessageDialog(null,"The New discount is set @ " +xtax+"% per total purchase totaling more than $3000 ");
    }else if(ans1==JOptionPane.NO_OPTION)
    {

    JOptionPane.showMessageDialog(null,"\n New Discount= " +discount +"\n New Tax(GCT)= " +tax);
    }
    }
    return discount;
    //}

    //return discount;

    }
    public static double main1(File salesfile,double discount,double tax,String shq,String highitem,double hq){//int sig,int imi,int kal,int tom,int g18,int sw,int ber,int c19,int rev,int des,int mp5,int c15){
    Calendar currentDate = Calendar.getInstance();
    String squantity = null;
    SimpleDateFormat formatter= new SimpleDateFormat("yyyy/MMM/dd");
    String dateNow = formatter.format(currentDate.getTime());
    //String highitem = null;
    double total=0;
    //double discount=0.1;//customers receive a 10% discounts on purchases totaling to more than $3000

    String itemname = null;
    double unitcost=0;

    int quantity=0;

    //JOptionPane.showMessageDialog(null, "Receive a 10% on purchases more than $3000 ");

    NumberFormat formatterx = new DecimalFormat("#0.00");
    String sunitcost;



    String itemcode = null;

    int c =0;
    while(c==0){
    int value=(Integer.parseInt(JOptionPane.showInputDialo g(
    "`````^^Handguns^^`````\n\n"
    +"(1) Desert eagle -price: $1300.00 \n\n"
    +"(2) Revolver - price: $424.99 \n\n"
    +"(3) Colt 1911 - price: $1229.99 \n\n"
    +"(4) Smith & Wesson - price: $699.99 \n\n"
    +"(5) Sig p226 - price: 568.00 \n\n"
    +"(6) Beretta M9 9mm-code: price:$ 580.00 \n\n"
    +"(7) Glock 18 -price: $779.99 \n\n"
    +" \n`````^^Sub-Machine Guns^^````` \n\n"
    +"(8) HK Mp5 - price: $1300.00 \n\n"
    +"(9) Bushmaster Carbon 15 -price :$1880.95 \n\n"
    +"(10) IMI mini-UZI price:$899.99 \n\n"
    +"(11) Kalashnikov AK-12 fff -price $6100.00 \n\n"
    +"(12) M1 Thompson(Tommy Gun) -price: $15000.00 \n\n"
    +"\n"
    +"(0)\t Return to Main Menu")));

    int count[]=new int[11];


    switch(value){

    case 1: itemname="Desert eagle";
    itemcode="deag";
    unitcost=1300.00;
    quantity = (Integer.parseInt(JOptionPane.showInputDialog(null , "How many Units of: " +itemname)));
    squantity=""+quantity;
    JOptionPane.showMessageDialog(null, "You've purchased: "+itemname);
    //des++;
    count[0]=count[0]+1;

    c=1;

    break;

    case 2:
    itemname="Revolver";
    unitcost=429.99;
    itemcode="revl";
    quantity = (Integer.parseInt(JOptionPane.showInputDialog(null , "How many Units of: " +itemname)));
    squantity=""+quantity;
    JOptionPane.showMessageDialog(null, "You've purchased: "+itemname);
    //rev++;
    count[1]=count[1]+1;
    c=1;
    break;
    case 3:
    itemname="Colt 1911";
    unitcost=1229.99;
    itemcode="c191";
    quantity = (Integer.parseInt(JOptionPane.showInputDialog(null , "How many Units of: " +itemname)));
    squantity=""+quantity;
    count[2]=count[2]+1;
    JOptionPane.showMessageDialog(null, "You've purchased: "+itemname);
    c=1;
    //c19++;
    break;
    case 4:
    itemname="Smith & Wesson";
    unitcost=699.99;
    itemcode="swes";
    quantity = (Integer.parseInt(JOptionPane.showInputDialog(null , "How many Units of: " +itemname)));
    squantity=""+quantity;
    JOptionPane.showMessageDialog(null, "You've purchased: "+itemname);
    count[3]=count[3]+1;
    //sw++;
    break;
    case 5:
    itemname="Sig p226 ";
    unitcost=1300.00;
    itemcode="sp22";
    quantity = (Integer.parseInt(JOptionPane.showInputDialog(null , "How many Units of: " +itemname)));
    squantity=""+quantity;
    JOptionPane.showMessageDialog(null, "You've purchased: "+itemname);
    count[4]=count[4]+1;
    //sig++;
    break;
    case 6:
    itemname="Beretta M9 9mm";
    unitcost=580.00;
    itemcode="bm9";
    quantity = (Integer.parseInt(JOptionPane.showInputDialog(null , "How many Units of: " +itemname)));
    squantity=""+quantity;
    JOptionPane.showMessageDialog(null, "You've purchased: "+itemname);
    //ber++;
    c=1;
    count[5]=count[5]+1;
    break;
    case 7:
    itemname="Glock 18";
    unitcost=779.99;
    itemcode="G18";
    quantity = (Integer.parseInt(JOptionPane.showInputDialog(null , "How many Units of: " +itemname)));
    squantity=""+quantity;
    JOptionPane.showMessageDialog(null,"You've purchased: "+itemname);
    //g18++;
    c=1;
    count[6]=count[6]+1;
    break;
    case 8:
    itemname="HK Mp5";
    unitcost=1300.00;
    itemcode="Hmp5";
    quantity = (Integer.parseInt(JOptionPane.showInputDialog(null , "How many Units of: " +itemname)));
    squantity=""+quantity;
    JOptionPane.showMessageDialog(null, "You've purchased: "+itemname);
    //mp5++;
    c=1;
    count[7]=count[7]+1;
    break;
    case 9:
    itemname="Bushmaster Carbon 15";
    unitcost=1880.95;
    itemcode="Bc15";
    quantity = (Integer.parseInt(JOptionPane.showInputDialog(null , "How many Units of: " +itemname)));
    squantity=""+quantity;
    JOptionPane.showMessageDialog(null, "You've purchased: "+itemname);
    //c15++;
    c=1;
    count[8]=count[8]+1;
    break;
    case 10:
    itemname="IMI mini-UZI";
    unitcost=899.99;
    itemcode="Iuzi";
    quantity = (Integer.parseInt(JOptionPane.showInputDialog(null , "How many Units of: " +itemname)));
    squantity=""+quantity;
    JOptionPane.showMessageDialog(null, "You've purchased: "+itemname);
    //imi++;
    c=1;
    count[9]=count[9]+1;
    break;
    case 11:
    itemname="Kalashnikov AK-12";
    unitcost=1880.95;
    itemcode="Ak12";
    quantity = (Integer.parseInt(JOptionPane.showInputDialog(null , "How many Units of: " +itemname)));
    squantity=""+quantity;
    JOptionPane.showMessageDialog(null, "You've purchased: "+itemname);
    //kal++;
    c=1;
    count[10]=count[10]+1;
    break;

    case 12: itemname="M1 Thompson (Tommy Gun)";
    unitcost=1880.95;
    itemcode="Tgun";
    quantity = (Integer.parseInt(JOptionPane.showInputDialog(null , "How many Units of: " +itemname)));
    squantity=""+quantity;
    JOptionPane.showMessageDialog(null, "You've purchased: "+itemname);
    //tom++;
    c=1;
    count[11]=count[11]+1;
    break;

    case 0: c=1;
    //maincontrol=0;
    break;


    default:
    JOptionPane.showMessageDialog(null,"Invalid please retry");
    //System.exit(c);
    c=0;
    break;
    }

    double untaxed;

    unitcost=(unitcost+(unitcost*tax));
    total=(unitcost*quantity);
    total=(total-(total*discount));
    untaxed=(total+(total*tax));
    String stotal = ""+total;
    sunitcost=""+unitcost;
    JOptionPane.showMessageDialog(null, "Your Current Untaxed Balance: $"+formatterx.format(untaxed));
    JOptionPane.showMessageDialog(null, "Your Total Balance(including a " +tax +"% in payable GCT" +"$"+formatterx.format(total));


    try{

    FileWriter fw = new FileWriter(salesfile,true);
    BufferedWriter bw = new BufferedWriter(fw);
    fw.write(" Product: "+itemname+"\t");
    fw.write("\t\t");
    fw.write("ItemCode: "+itemcode+"\t");
    fw.write("\t\t");
    fw.write("Unitcost: " +sunitcost+"\t");
    fw.write("\t\t\t");
    fw.write("Quantity: " +squantity+"\t");
    fw.write("\t\t");
    fw.write("Date of Purchase:" +dateNow);

    fw.write("\n");
    fw.write("\n");
    bw.close();
    fw.close();

    }catch(IOException ioe){
    System.out.println(ioe);
    }

    int record=JOptionPane.showConfirmDialog(null, "Do you want to make another purchase ");
    if(record==JOptionPane.YES_OPTION){
    c=0;
    }
    else if(record==JOptionPane.NO_OPTION)
    {c=1;
    JOptionPane.showMessageDialog(null,"Thanks for purchasing a: " +itemname);
    }
    else System.exit(c);
    }

    //return new int[12];
    return total;
    }

    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: need help with my code!

    i have trouble with getting to 2. Provides the details of the highest sale for the day.
    That looks like you have to search a list for the highest sale amount.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: need help with my code!

    import java.awt.Frame;
    import java.io.*;
    import java.text.DecimalFormat;
    import java.text.NumberFormat;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.List;
    import java.util.TreeMap;
     
     
    import java.awt.*;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JOptionPane;
    import javax.swing.JSeparator;
     
    public class Gunstore{
     
     
    	public static void main(String[] args) throws IOException {
    		int maincontrol=0;
    		double discount=0.1;//currently 10% discount per purchase
    		double tax=0.17;//current 17% tax oer purchase
    		 int quantity=0;
    		String highitem = null;
    		 double hq = 0;
    		 String shq=null;
    		 int[] count = null;
     
    		String accessboss="admin";
    		String accessclerk="clerk";
    		String passboss="admin";
    		String passclerk="clerk";
    		 String user;
    		 String pass="";
    		 JOptionPane.showMessageDialog(null, "D. S. C. D ™ "
    				 +"\n\n\n" +"Please Login for Access.");
    		//  user=JOptionPane.showInputDialog(null,"UserName: ");//admin+user
    		 //pass=JOptionPane.showInputDialog(null,"Password: ");//admin
    		//if(user.equals(accessboss)  && pass.equals(passboss)){
    		while(maincontrol==0){
    		String salesinfo="Sales Information.txt";
    		File salesfile= new File(salesinfo);
    		Calendar currentDate = Calendar.getInstance();
    		String squantity = null;
    		SimpleDateFormat formatter=  new SimpleDateFormat("yyyy/MMM/dd");
    		String dateNow = formatter.format(currentDate.getTime());
    		double total=0;
    		String allstoresale = null;
    		//int item = 0;
    		//String pc = null;
    		String itemname = null;
    		double unitcost=0;
    		//int sales = 0;
    		//String prodcode=null;
    		String[] itemName = { "Desert eagle","Colt 1911 ", "Revolver", "Smith & Wesson 357","Sig p226","Beretta M9","Glock 18","HK Mp5","Bushmaster Carbon 15", "IMI mini","Kalashnikov AK-12","M1 Thompson" };		
    		//JOptionPane.showMessageDialog(null, "Receive a 10% on purchases more than $3000 ");
     
    		//String buy = null;
    		String sunitcost;
    		//int imi=0,kal=0,tom=0,bus=0,g18=0,sw=0,ber=0,col=0,rev=0,des=0,mp5=0,c15=0;
     
     
    		String stotal = null;
    String itemcode = null;
     
    int menu=(Integer.parseInt(JOptionPane.showInputDialog("\t Logged in as: Manager" +"\n\n\n(1) \t to make a purchase\n" +"(2) \t Highest Sale for the day \n"
    +"(3)\t Item that sold the most \n" 
    +"(4)\t All Sales for day \n"+"(5)\t Display all Sales for the Store \n" 
    +"(6)\t Manage discount or GCT \n" +"(0)\tExit \n")));
     
     
    switch(menu){
     
    case 0: System.exit(menu);
     
    case 1:main1(salesfile,discount,tax,shq,highitem,hq);
    	maincontrol=0;
    	break;
     
    case 2:   highsale(total);
    	maincontrol=0;
    	break;
     
    case 3:
    	int maxIndex = maxsold( count );
    	    System.out.println( "Weapon that sold the most is: " +itemName[maxIndex] );
    	    maincontrol=0;
    	    break;
     
     
    case 4: 
     
     
    case 5: allstoresale(salesfile);
    maincontrol=0;
    break;
     
    case 6: discount=setdiscount( discount,tax );
    		maincontrol=0;
    		break;
     
     
    }
    		}//}
    		//else if(user.equals(accessclerk) && pass.equals(passclerk)){
     
    			while(maincontrol==0){
    				String salesinfo="Sales Information.txt";
    				File salesfile= new File(salesinfo);
    				Calendar currentDate = Calendar.getInstance();
    				String squantity = null;
    				SimpleDateFormat formatter=  new SimpleDateFormat("yyyy/MMM/dd");
    				String dateNow = formatter.format(currentDate.getTime());
    				double total=0;
    				//int item = 0;
    				//String pc = null;
    				String itemname = null;
    				double unitcost=0;
    				//int sales = 0;
    				//String prodcode=null;
     
     
    			//JOptionPane.showMessageDialog(null, "Receive a 10% on purchases more than $3000 ");
     
    				//String buy = null;
    				String sunitcost;
     
     
     
    				String stotal = null;
    		String itemcode = null;
    		int imi=0,kal=0,tom=0,bus=0,g18=0,sw=0,ber=0,col=0,rev=0,des=0,mp5=0,c15=0;
    		int menu=(Integer.parseInt(JOptionPane.showInputDialog("\t Logged in: Sales Clerk" +"\n\n\n(1) \t to make a purchase\n"  +"(0)\tExit \n")));
     
    		switch(menu){
     
    		case 0: System.exit(menu);
     
    		case 1:main1(salesfile,discount,tax,shq,highitem,hq);
    			maincontrol=0;
    			break;
     
    		default:
    				JOptionPane.showMessageDialog(null, "You donot have Access Loser!");
    				maincontrol=0;
    				break;
    		}
     
     
    			}
    		}
     
     
    public static void highsale(double total){
    	double temp=0;
    	double high = 0;
    	  NumberFormat formatterx = new DecimalFormat("#0.00");
    	if(total>temp){
    		high=total;
    	}
    	else{
    		JOptionPane.showMessageDialog(null, "There has not been a Sale as yet!");
    	}
     
    	JOptionPane.showMessageDialog(null, "Highest Sale for Today is: " +formatterx.format(high));
     
    }
     
     
     
    private static void allstoresale(File salesfile) throws IOException {
    	String displaysales;
    	try{
    		FileReader fr = new FileReader(salesfile);
    		BufferedReader br = new BufferedReader(fr);
     
    		while((displaysales = br.readLine()) != null){
    		System.out.println(displaysales);
     
    		}
     
    	}catch(IOException ioe){
    		System.out.println(ioe);
    	}
    }
     
    //method maxsold() returns the index of the maximum value in the array
    public static int maxsold(int[] count)
    {
     int maxValue = count[0];
     int maxIndex = 0;
     for(int i=1;i < count.length;i++)
     
     { 
     
         if(count[i] > maxValue){ 
     
             maxValue = count[i];
     
             maxIndex = i;
     
             JOptionPane.showMessageDialog( null, +maxValue );
     
         } 
     }
     
     // return the index corresponding to the maximum value in the array
     
     // which contains the most weapons sold
     return maxIndex; 
    }
    public static double setdiscount(double discount, double tax){
    	int ans=0;
    	double xdis;
    	double xtax;
    	int ans1=0;
    	JOptionPane.showMessageDialog(null,"The Current Discount is at:   "  +discount+"%   per total purchase totaling more than $3000 ");
     
    	ans=JOptionPane.showConfirmDialog(null, "Do you  want to change Discount rate? ");
    	if(ans==JOptionPane.YES_OPTION){
    		xdis=Double.parseDouble(JOptionPane.showInputDialog("Enter new Discount in '%' "));
    		xdis=(xdis*0.01);
    		discount=xdis;
    		JOptionPane.showMessageDialog(null,"The New discount is set @  "  +discount+"%   per total purchase totaling more than $3000 ");
     
    }else if(ans==JOptionPane.NO_OPTION)
    {
    	JOptionPane.showMessageDialog(null,"The Current Tax is at:   "  +tax +"%   per purchase ");
    		ans1=JOptionPane.showConfirmDialog(null, "Do you  want to change  Tax rate? ");
    		if(ans==JOptionPane.YES_OPTION){
    			xtax=Double.parseDouble(JOptionPane.showInputDialog("Enter new Tax in '%'  "));
    			xtax=(xtax*0.01);
    			tax=xtax;
    			JOptionPane.showMessageDialog(null,"The New discount is set @  "  +xtax+"%   per total purchase totaling more than $3000 ");
    		}else if(ans1==JOptionPane.NO_OPTION)
    		{		
     
    		JOptionPane.showMessageDialog(null,"\n New Discount= " +discount  +"\n New Tax(GCT)= " +tax);
    }
    }
    		return discount;
    	//}
     
    	//return discount;
     
    }
    public static double main1(File salesfile,double discount,double tax,String shq,String highitem,double hq){//int sig,int imi,int kal,int tom,int g18,int sw,int ber,int c19,int rev,int des,int mp5,int c15){
    	Calendar currentDate = Calendar.getInstance();
    	String squantity = null;
    	SimpleDateFormat formatter=  new SimpleDateFormat("yyyy/MMM/dd");
    	String dateNow = formatter.format(currentDate.getTime());
    	//String highitem = null;
    	double total=0;
    	//double discount=0.1;//customers receive a 10% discounts on purchases totaling to more than $3000
     
    	String itemname = null;
    	double unitcost=0;
     
        int quantity=0;
     
    //JOptionPane.showMessageDialog(null, "Receive a 10% on purchases more than $3000 ");
     
        NumberFormat formatterx = new DecimalFormat("#0.00");
    	String sunitcost;
     
     
     
    String itemcode = null;
     
    int c =0;
    while(c==0){
    	 int value=(Integer.parseInt(JOptionPane.showInputDialog( 
    	"`````^^Handguns^^`````\n\n"
    	+"(1)   Desert eagle -price: $1300.00 \n\n"
    	+"(2)   Revolver - price: $424.99 \n\n"
    	+"(3)   Colt 1911 - price: $1229.99 \n\n"
    	+"(4)   Smith & Wesson - price: $699.99 \n\n"
    	+"(5)	Sig p226 - price: 568.00  \n\n"
    	+"(6)	Beretta M9 9mm-code: price:$ 580.00 \n\n"
    	+"(7)	Glock 18  -price: $779.99 \n\n"
    	+"	\n`````^^Sub-Machine Guns^^````` \n\n"  
    	+"(8)	HK Mp5 - price: $1300.00 \n\n"
    	+"(9)	Bushmaster Carbon 15  -price :$1880.95  \n\n"
    	+"(10)	IMI mini-UZI  price:$899.99   \n\n"	
    	+"(11)	Kalashnikov AK-12 fff -price $6100.00   \n\n"
    	+"(12)	M1 Thompson(Tommy Gun) -price: $15000.00  \n\n"
    	+"\n"
    	+"(0)\t Return to Main Menu")));  
     
    	 int count[]=new int[11];
     
     
    	switch(value){ 
     
    	case 1:		itemname="Desert eagle";
    				itemcode="deag";
    				unitcost=1300.00;
    				quantity = (Integer.parseInt(JOptionPane.showInputDialog(null, "How many Units of:  " +itemname)));
    				squantity=""+quantity;
    				JOptionPane.showMessageDialog(null, "You've purchased:   "+itemname);
    				//des++;
    				count[0]=count[0]+1;
     
    				c=1;
     
    				break;
     
    	case 2:		
    				itemname="Revolver";
    				unitcost=429.99;
    				itemcode="revl";
    				quantity = (Integer.parseInt(JOptionPane.showInputDialog(null, "How many Units of:  " +itemname)));
    				squantity=""+quantity;
    				JOptionPane.showMessageDialog(null, "You've purchased:   "+itemname);
    				//rev++;
    				count[1]=count[1]+1;
    				c=1;
    				break;
    	case 3:
    					itemname="Colt 1911";
    					unitcost=1229.99;
    					itemcode="c191";
    					quantity = (Integer.parseInt(JOptionPane.showInputDialog(null, "How many Units of:  " +itemname)));
    					squantity=""+quantity;
    					count[2]=count[2]+1;
    					JOptionPane.showMessageDialog(null, "You've purchased:   "+itemname);
    					c=1;
    					//c19++;
    					break;
    	case 4:	
    				itemname="Smith & Wesson";
    				unitcost=699.99;
    				itemcode="swes";
    				quantity = (Integer.parseInt(JOptionPane.showInputDialog(null, "How many Units of:  " +itemname)));
    				squantity=""+quantity;
    				JOptionPane.showMessageDialog(null, "You've purchased:   "+itemname);	
    				count[3]=count[3]+1;
    				//sw++;
    				break;
    	case 5:
    					itemname="Sig p226 ";
    					unitcost=1300.00;
    					itemcode="sp22";
    					quantity = (Integer.parseInt(JOptionPane.showInputDialog(null, "How many Units of:  " +itemname)));
    					squantity=""+quantity;
    					JOptionPane.showMessageDialog(null, "You've purchased:   "+itemname);	
    					count[4]=count[4]+1;
    					//sig++;
    					break;
    	case 6:
    							itemname="Beretta M9 9mm";
    							unitcost=580.00;
    							itemcode="bm9";
    							quantity = (Integer.parseInt(JOptionPane.showInputDialog(null, "How many Units of:  " +itemname)));
    							squantity=""+quantity;
    							JOptionPane.showMessageDialog(null, "You've purchased:   "+itemname);	
    							//ber++;
    							c=1;
    							count[5]=count[5]+1;
    							break;
    	case 7:
    						itemname="Glock 18";
    						unitcost=779.99;
    						itemcode="G18";
    						quantity = (Integer.parseInt(JOptionPane.showInputDialog(null, "How many Units of:  " +itemname)));
    						squantity=""+quantity;
    						JOptionPane.showMessageDialog(null,"You've purchased:   "+itemname);	
    						//g18++;
    						c=1;
    						count[6]=count[6]+1;
    						break;
    	case 8:
    							itemname="HK Mp5";
    							unitcost=1300.00;
    							itemcode="Hmp5";
    							quantity = (Integer.parseInt(JOptionPane.showInputDialog(null, "How many Units of:  " +itemname)));
    							squantity=""+quantity;
    							JOptionPane.showMessageDialog(null, "You've purchased:   "+itemname);
    							//mp5++;
    							c=1;
    							count[7]=count[7]+1;
    							break;
    	case 9:
    								itemname="Bushmaster Carbon 15";
    								unitcost=1880.95;
    								itemcode="Bc15";
    								quantity = (Integer.parseInt(JOptionPane.showInputDialog(null, "How many Units of:  " +itemname)));
    								squantity=""+quantity;
    								JOptionPane.showMessageDialog(null, "You've purchased:   "+itemname);	
    								//c15++;
    								c=1;
    								count[8]=count[8]+1;
    								break;
    	case 10:
    								itemname="IMI mini-UZI";
    								unitcost=899.99;
    								itemcode="Iuzi";
    								quantity = (Integer.parseInt(JOptionPane.showInputDialog(null, "How many Units of:  " +itemname)));
    								squantity=""+quantity;
    								JOptionPane.showMessageDialog(null, "You've purchased:   "+itemname);	
    								//imi++;
    								c=1;
    								count[9]=count[9]+1;
    								break;
    	case 11:
    								itemname="Kalashnikov AK-12";	
    								unitcost=1880.95;
    								itemcode="Ak12";
    								quantity = (Integer.parseInt(JOptionPane.showInputDialog(null, "How many Units of:  " +itemname)));
    								squantity=""+quantity;
    								JOptionPane.showMessageDialog(null, "You've purchased:   "+itemname);			
    								//kal++;
    								c=1;
    								count[10]=count[10]+1;
    								break;
     
    	case 12:					itemname="M1 Thompson (Tommy Gun)";
    								unitcost=1880.95;
    								itemcode="Tgun";
    								quantity = (Integer.parseInt(JOptionPane.showInputDialog(null, "How many Units of:  " +itemname)));
    								squantity=""+quantity;
    								JOptionPane.showMessageDialog(null, "You've purchased:   "+itemname);	
    								//tom++;
    								c=1;
    								count[11]=count[11]+1;
    								break;
     
    	case 0:						c=1;
    								//maincontrol=0;
    								break;
     
     
    	default:
    			JOptionPane.showMessageDialog(null,"Invalid please retry");
    			//System.exit(c);
    			c=0;
    			break;
    	}	
     
    double untaxed;
     
    		unitcost=(unitcost+(unitcost*tax));
    	 total=(unitcost*quantity);
    		total=(total-(total*discount));
    		untaxed=(total+(total*tax));
    		String stotal = ""+total;
    		sunitcost=""+unitcost;
    		JOptionPane.showMessageDialog(null, "Your Current Untaxed Balance:    $"+formatterx.format(untaxed));
    		JOptionPane.showMessageDialog(null, "Your Total Balance(including a  " +tax +"%   in payable GCT"    +"$"+formatterx.format(total));
     
     
    		try{
     
    			FileWriter fw = new FileWriter(salesfile,true);
    			BufferedWriter bw = new BufferedWriter(fw);
    			fw.write("	Product: "+itemname+"\t");
    			fw.write("\t\t");
    			fw.write("ItemCode: "+itemcode+"\t");
    			fw.write("\t\t");
    			fw.write("Unitcost: " +sunitcost+"\t");
    			fw.write("\t\t\t");
    			fw.write("Quantity: " +squantity+"\t");
    			fw.write("\t\t");
    			fw.write("Date of Purchase:" +dateNow);
     
    			fw.write("\n");
    			fw.write("\n");
    			bw.close();
    			fw.close();
     
    		}catch(IOException ioe){
    			System.out.println(ioe);
    		}
     
    		int record=JOptionPane.showConfirmDialog(null, "Do you  want to make another purchase ");
    		if(record==JOptionPane.YES_OPTION){
    			c=0;
    			}
    		else if(record==JOptionPane.NO_OPTION)
    			{c=1;
    			JOptionPane.showMessageDialog(null,"Thanks for purchasing a: " +itemname);
    			}
    		else System.exit(c);
    		}
     
    //return new int[12];
    	return total;	
    }
     
    }

Similar Threads

  1. Replies: 5
    Last Post: November 14th, 2012, 10:47 AM
  2. How to Translate working code into code with a Tester Class
    By bankoscarpa in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 15th, 2012, 02:13 PM
  3. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM
  4. problem in my code java code graph editeur
    By kisokiso in forum Java Theory & Questions
    Replies: 5
    Last Post: January 6th, 2012, 08:36 AM
  5. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM