14 Replies - 320 Views - Last Post: 01 December 2012 - 10:40 AM Rate Topic: -----

#1 dwayneb7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 30-November 12

Display the name and quantity of the item which was sold the most,

Posted 30 November 2012 - 11:12 PM

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];
		
}

}




Is This A Good Question/Topic? 0
  • +

Replies To: Display the name and quantity of the item which was sold the most,

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: Display the name and quantity of the item which was sold the most,

Posted 01 December 2012 - 12:33 AM

It's great that you used code tags on your first post, but it's also important to include some info about what you need help with. Otherwise, we're guessing, looking for something small in a haystack, but we don't know what.
Was This Post Helpful? 1
  • +
  • -

#3 dwayneb7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 30-November 12

Re: Display the name and quantity of the item which was sold the most,

Posted 01 December 2012 - 06:07 AM

View PostGregBrannon, on 01 December 2012 - 12:33 AM, said:

It's great that you used code tags on your first post, but it's also important to include some info about what you need help with. Otherwise, we're guessing, looking for something small in a haystack, but we don't know what.


i need an algorithm that can help me display the name and quantity of the item that sold the most, the program so far is a gunstore that has 12 guns selling, an it can perform several functions but the one function i need help with finding the item that sold most
Was This Post Helpful? 0
  • +
  • -

#4 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: Display the name and quantity of the item which was sold the most,

Posted 01 December 2012 - 06:20 AM

Does the array count[] keep track of how many of each product is sold? If so, it seems you'd only have to find the maximum value in that array, pair that with the weapon name, and report the result.

Keeping track of related data in that manner is known as using parallel arrays. The weapon names are in one array, the number of each weapon sold is in another array and, hopefully, the indices of the arrays match up: the indices of weapon1 name and weapon1 numberSold are the same.

Someone will suggest that you NOT use parallel arrays to keep track of related data. A Weapon class that contains instance variables for the name, caliber, class, how many were sold, etc. and then methods to report those variables would make much more sense and would be easier to manage and consistent with OOP concepts.
Was This Post Helpful? 1
  • +
  • -

#5 dwayneb7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 30-November 12

Re: Display the name and quantity of the item which was sold the most,

Posted 01 December 2012 - 06:25 AM

i agree, i only thought to try using and array to store values to be returned, but how would you use methods to report the variables? with my code
Was This Post Helpful? 0
  • +
  • -

#6 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: Display the name and quantity of the item which was sold the most,

Posted 01 December 2012 - 06:29 AM

public int findIndexOfMaxSold()
{
    // find the maximum value in count[] array
    // return index of the maximum value
}

String nameOfMaxSold = weaponName[findIndexOfMaxSold()];

Was This Post Helpful? 1
  • +
  • -

#7 dwayneb7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 30-November 12

Re: Display the name and quantity of the item which was sold the most,

Posted 01 December 2012 - 06:38 AM

View PostGregBrannon, on 01 December 2012 - 06:29 AM, said:

public int findIndexOfMaxSold()
{
    // find the maximum value in count[] array
    // return index of the maximum value
}

String nameOfMaxSold = weaponName[findIndexOfMaxSold()];


yea greg not bad, 1 more thing with this code have a look at my discount method its very inefficient, because users should be able to specify the amount of disount at any time my current discount method only says it returned a new value but sticks to the old discount
Was This Post Helpful? 0
  • +
  • -

#8 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: Display the name and quantity of the item which was sold the most,

Posted 01 December 2012 - 06:51 AM

I assume you mean the method setDiscount()?

setDiscount() returns a value - the new discount - but you don't use it. It is essentially discarded. The variable discount in the main() method and the variable discount in the setDiscount() method are two different variables with the same name. Doing something like the following may fix it, but I didn't test it.
case 6: discount = setdiscount( discount,tax );
maincontrol=0;
break;

Next time, instead of thinking of arrays to store values, think of classes with variables. A class-based design will be so much easier.
Was This Post Helpful? 1
  • +
  • -

#9 dwayneb7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 30-November 12

Re: Display the name and quantity of the item which was sold the most,

Posted 01 December 2012 - 07:00 AM

View PostGregBrannon, on 01 December 2012 - 06:51 AM, said:

I assume you mean the method setDiscount()?

setDiscount() returns a value - the new discount - but you don't use it. It is essentially discarded. The variable discount in the main() method and the variable discount in the setDiscount() method are two different variables with the same name. Doing something like the following may fix it, but I didn't test it.
case 6: discount = setdiscount( discount,tax );
maincontrol=0;
break;

Next time, instead of thinking of arrays to store values, think of classes with variables. A class-based design will be so much easier.


yes, typo i meant setdiscount() method, could you give an example of using classes with my code? #i'm a beginner in java
Was This Post Helpful? 0
  • +
  • -

#10 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: Display the name and quantity of the item which was sold the most,

Posted 01 December 2012 - 07:03 AM

I'll give you the link to Mac's tutorial on "Moving Away from Parallel Arrays" instead.
Was This Post Helpful? 2
  • +
  • -

#11 dwayneb7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 30-November 12

Re: Display the name and quantity of the item which was sold the most,

Posted 01 December 2012 - 08:17 AM

Hey greg i'm still having problems getting this code to work. could you let me know if can write examples of my code on to improve the functionality of it
Was This Post Helpful? 0
  • +
  • -

#12 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: Display the name and quantity of the item which was sold the most,

Posted 01 December 2012 - 08:19 AM

What problems?
Was This Post Helpful? 1
  • +
  • -

#13 dwayneb7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 30-November 12

Re: Display the name and quantity of the item which was sold the most,

Posted 01 December 2012 - 08:31 AM

View PostGregBrannon, on 01 December 2012 - 08:19 AM, said:

What problems?

thanks to yo I got the discount method working. but even though with the tutorial im still trying to understand the concept on how to get the name and quantity of the item that sold the most. I tried implementing a counter so that everytime the product is select it adds to counter array then in the final compare which value in counter was higher. i know the algorithm to find the largest value in an array but cant retrieve values in my array call from a method.
#thanks for the help so far greg!
heres the current 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;
		
		
		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 = null;
		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:
	maxsold( count);
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;
		
		
				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 int maxsold(int[] count){
	int maxValue = count[0];  
	  for(int i=1;i < count.length;i++){  
	    if(count[i] > maxValue){  
	      maxValue = count[i];  
	      JOptionPane.showMessageDialog(null, +maxValue);
	    }  
	  }  
	  return maxValue;  
}
public static double setdiscount(double discount, double tax){
	int ans=0;
	double xdis;
	double xtax;
	int ans1=0;
	JOptionP3ane.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 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];
		
}

}





Was This Post Helpful? 0
  • +
  • -

#14 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: Display the name and quantity of the item which was sold the most,

Posted 01 December 2012 - 08:54 AM

You have a typo on line 204, a misplaced '3'.

Again, you don't seem to be doing everything you could be doing to get the benefit of the method maxsold(). Yes, you're apparently showing the maximum number from the count[] array, but you're not using the index of that value.

Try modifying maxsold() to return the index of the max value in count[]:
    // method maxsold() returns the index of the maximum value in the array
    // count[].
    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;  
    }

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

As I looked for an array of item names, I couldn't find one. Without that (or the class of weapons I suggested earlier), you'll be at a loss to pair a weapon name with the max quantity sold, so define an array in your main() method - near the top - from which to get the names:

String[] itemName = { "Name1", "Name2", . . ., "Name12" };

Something similar should be in the tutorial you're following.

I'm not going to give you any more help using parallel arrays, but I'm not going to rewrite the tutorial you're working on either.
Was This Post Helpful? 1
  • +
  • -

#15 dwayneb7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 30-November 12

Re: Display the name and quantity of the item which was sold the most,

Posted 01 December 2012 - 10:40 AM

View PostGregBrannon, on 01 December 2012 - 08:54 AM, said:

You have a typo on line 204, a misplaced '3'.

Again, you don't seem to be doing everything you could be doing to get the benefit of the method maxsold(). Yes, you're apparently showing the maximum number from the count[] array, but you're not using the index of that value.

Try modifying maxsold() to return the index of the max value in count[]:
    // method maxsold() returns the index of the maximum value in the array
    // count[].
    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;  
    }

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

As I looked for an array of item names, I couldn't find one. Without that (or the class of weapons I suggested earlier), you'll be at a loss to pair a weapon name with the max quantity sold, so define an array in your main() method - near the top - from which to get the names:

String[] itemName = { "Name1", "Name2", . . ., "Name12" };

Something similar should be in the tutorial you're following.

I'm not going to give you any more help using parallel arrays, but I'm not going to rewrite the tutorial you're working on either.




I know you said you wont help me but current solution crash my program given the current code. Could you have a look at the main1 method too see if its correctly implementing the array usage properly to return values
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 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];
		
}

}







Was This Post Helpful? 0
  • +
  • -

Page 1 of 1