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 1 of 1

Thread: Java help:3. Display the name and quantity of the item which was sold the most, thus far

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

    Default Java help:3. Display the name and quantity of the item which was sold the most, thus far

    trouble with questions asking to: 1.Provides the details of the highest sale for the day. 2. Display the name and quantity of the item which was sold the most, thus far .

    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;
     
     
    		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;
     
    	//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;
     
    		int count;
    		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,imi,kal,tom,bus,g18,sw,ber,col,rev,des,mp5,c15);
    	maincontrol=0;
    	break;
     
    case 2:   highsale(total);
    	maincontrol=0;
    	break;
     
    case 3:
     
    maincontrol=0;
    break;
     
    case 4: 
     
     
    case 5: allstoresale(salesfile);
    maincontrol=0;
    break;
     
    case 6: 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;
     
     
    				int count;
    				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,imi,kal,tom,bus,g18,sw,ber,col,rev,des,mp5,c15);
    			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);
    	}
    }
     
     
    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=Integer.parseInt(JOptionPane.showInputDialog(null,"Do you wish to enter new discount price? (Press a number)"));
    while(ans>=0){
    		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 ");
    		ans=-4;
    }JOptionPane.showMessageDialog(null,"The Current Tax is at:   "  +tax +"%   per purchase ");
    		ans1=Integer.parseInt(JOptionPane.showInputDialog(null,"Do you wish to enter new Tax? (Press a number)"));
    		while(ans>=0){
    			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 ");
    		}		
     
    		JOptionPane.showMessageDialog(null,"\n New Discount= " +discount  +"\n New Tax(GCT)= " +tax);
    	return discount;
    	//}
     
    	//return discount;
     
    }
    public static int[] 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];
     
    }
     
    }
    Last edited by helloworld922; December 1st, 2012 at 01:13 AM. Reason: please use [code] tags


Similar Threads

  1. Replies: 0
    Last Post: August 7th, 2012, 11:20 AM
  2. JcomboBox showing only one item
    By ishiro in forum What's Wrong With My Code?
    Replies: 6
    Last Post: May 31st, 2012, 09:29 AM
  3. [SOLVED] HELP ME! How to update quantity (JAVA)
    By kerrina in forum What's Wrong With My Code?
    Replies: 12
    Last Post: August 2nd, 2011, 03:27 AM
  4. drag item or insert item into new Jlabel in JPanel
    By qaromi in forum AWT / Java Swing
    Replies: 5
    Last Post: July 6th, 2010, 07:37 PM
  5. [SOLVED] how to delete an item from a form
    By mahdi in forum Java ME (Mobile Edition)
    Replies: 3
    Last Post: August 30th, 2009, 01:06 PM