Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Beginner having some Java class trouble

    The "Add Lumber" & "Add Customer" sections aren't working correctly. Eclipse tells me that I haven't added the while statement; is there something else wrong? I added a comment saying "Need to find out which one the customer wants." I need to ask the customer if they want to edit the price or stock level. I don't know specifically how. Any advice would be appreciated. I'm almost done with the program I just need these errors/problems fixed.

    Code:
    package Lumber;
    
    import javax.swing.JOptionPane;
    import java.io.*;
    import java.util.*;
    import java.text.*;
    
    public class Lumber
    {
    public static void main(String[] args) 
    	{
    	int count=-1,c;
    	int place=-1,l;
    	int [] number = new int [100];
    	String [] lastname = new String [100];
    	String [] firstname = new String [100];
    	String [] address = new String [100];
    	double [] creditlimit = new double [100];
    	int [] code = new int [100];
    	String [] type = new String [100];
    	double [] price = new double [100];
    	int [] stocklevel = new int [100];
    	
    		int selection;
    		count=start_program(number,lastname,firstname,address,creditlimit,count);
    		place=start_program1(code,type,price,stocklevel,place);
    		selection =menu();
    	     while(selection!=4)
    	     {
    	    	    if (selection == 1)
    	    	       	Modify_Customer(number,lastname,firstname,address,creditlimit,count);
    	    	      else 
    	    	    	  if (selection == 2)
    	    	      	   	  Modify_Lumber(code,type,price,stocklevel,place);
    	    	         else 
    	    	        	 if (selection == 3)
    	    	               Report(count,place,number,lastname,firstname,address,creditlimit,code,type,price,stocklevel);
    	    	  selection =menu();
    	     }//end of while loop
    	     exit_program(number,lastname,firstname,address,creditlimit,count);
    	     exit_program1(code,type,price,stocklevel,place);
    	     System.exit(0);
    	}// end of main 
    
    		public static int menu()
    		{
    			  String mnumber;
    			  int number;
    			  String output = "Chestnut Ridge lumber Comapny" + " \n " + " \n " +
    		      "1. Add/Modify Customer Data " + " \n " +
    		      "2. Add/Modify Lumber Data " + " \n " +
    		      "3. Report Section " + " \n " +
    		      "4. Exit the System" + " \n" + " \n " +
    		      "Please make your selection  >";
    		       mnumber = JOptionPane.showInputDialog(null, output, " ",
    		                                        JOptionPane.QUESTION_MESSAGE);
    		       number=Integer.parseInt(mnumber);
    		       return number;
    		     } 
    	
    		public static void Modify_Customer(int[]number,String[]lastname,String[]firstname,String[]address,double[]creditlimit,int count)
    		{
    			String Choice = "";
    			
    			 String reportChoices = "Customer Information Menu" + "\n" + "1. Add Customer" + "\n" + "2. Delete Customer" + "\n" + "3. Modify Customer";
    			 
    			 Choice= JOptionPane.showInputDialog(null,reportChoices,"",JOptionPane.QUESTION_MESSAGE);
    			 
    			 int i;
    			 
    			 if (Choice.equals("1")){
    				 System.out.println("Add Customer:");
    				 
    				 String more = "Y/N";
    				do{  				 
    				 for (i=0; i<= count; i++) {
    					 String ID_Number,last_name, first_name, Address;
    					 int  ID_number;
    					 String Credit_Limit;
    					 count=count+1;
    					 
    					 ID_Number = JOptionPane.showInputDialog(null,"Enter The New Customer ID:" +
    								"",JOptionPane.QUESTION_MESSAGE);
    					 ID_number = Integer.parseInt(ID_Number);
    					 last_name = JOptionPane.showInputDialog(null,"Enter The New Customer's Last Name:" +
    								"",JOptionPane.QUESTION_MESSAGE);
    					 first_name = JOptionPane.showInputDialog(null,"Enter The New Customer's First Name:" +
    								"",JOptionPane.QUESTION_MESSAGE);
    					 Address = JOptionPane.showInputDialog(null,"Enter The New Customer's City:" +
    								"",JOptionPane.QUESTION_MESSAGE);
    					 Credit_Limit = JOptionPane.showInputDialog(null,"Enter The New Customer's Credit Limit:" +
    								"",JOptionPane.QUESTION_MESSAGE);
    					  double Cred_Lim = Double.parseDouble(Credit_Limit);
    						  
    					number[count] = ID_number;
    				    firstname[count] = first_name;
    					lastname[count] = last_name;
    					address[count] = Address;
    					creditlimit[count] = Cred_Lim;
    				 }while (more.equals("Y"));
    				}
    			 }
    			 
    			 else if (Choice.equals("2")){
    				 System.out.println("Delete Customer:");
    				  {
    					//Ask for customer ID
    						String customerID = JOptionPane.showInputDialog(null,"Enter The Customer ID:" +
    								"",JOptionPane.QUESTION_MESSAGE);
    						int cust_ID = Integer.parseInt(customerID);
    						
    						//Search array
    						for (i=0; i <= count; i++) {
    							if (number[i] == cust_ID) {
    								
    								for (int p = i; p <= count; p++){
    								number[p] = number[p-1];
    							    firstname[p] = firstname[p-1];
    								lastname[p] = lastname[p-1];
    								address[p] = address[p-1];
    								creditlimit[p] = creditlimit[p-1];
    								}
    			 }
    				  }
    			 }
    			 }
    				
    		 else if (Choice.equals("3")){
    			 System.out.println("Modify Customer:");
    			//Ask for customer ID
    				String customerID = JOptionPane.showInputDialog(null,"Enter The Customer ID:" +
    						"",JOptionPane.QUESTION_MESSAGE);
    				int cust_ID = Integer.parseInt(customerID);
    				
    				//Search array
    				for (i=0; i <= count; i++) {
    					if (number[i] == cust_ID) {
    						String input = JOptionPane.showInputDialog(null,"Enter The New Customer's Credit Limit:" +
    								"",JOptionPane.QUESTION_MESSAGE);
    						int ID_Replace = Integer.parseInt(input);
    						creditlimit[i] = ID_Replace;
    		 }
    				}
    		 }
    			}
    
    		public static void Modify_Lumber(int[]code,String[]type,double[]price,int[]stocklevel,int place)
    		{
    			String Choice = "";
    			
    			 String reportChoices = "Lumber Information Menu" + "\n" + "1. Add Lumber Item" + "\n" + "2. Delete Lumber Item" + "\n" + "3. Modify Lumber Item";
    			 
    			 Choice= JOptionPane.showInputDialog(null,reportChoices,"",JOptionPane.QUESTION_MESSAGE);
    			 
    			 int i;
    			 
    			 int count;
    			if (Choice.equals("1")){
    				 System.out.println("Add Lumber Item:");
    				 
    				 String more = "Y/N";
    				do{  				 
    				 for (i=0; i<= place; i++) {
    					 String Lumber_Code,Lumber_Type, Lumber_Price, Lumber_Stock;
    					 int  Lumber_code, Lumber_stock;
    					 Double Lumber_price;
    					 String Credit_Limit;
    					 place=place+1;
    					 
    					 Lumber_Code = JOptionPane.showInputDialog(null,"Enter The New Lumber's Code:" +
    								"",JOptionPane.QUESTION_MESSAGE);
    					 Lumber_code = Integer.parseInt(Lumber_Code);
    					 Lumber_Type = JOptionPane.showInputDialog(null,"Enter The New Lumber's Type:" +
    								"",JOptionPane.QUESTION_MESSAGE);
    					 Lumber_Price = JOptionPane.showInputDialog(null,"Enter The New Lumber's Price:" +
    								"",JOptionPane.QUESTION_MESSAGE);
    					 Lumber_price = Double.parseDouble(Lumber_Price);
    					 Lumber_Stock = JOptionPane.showInputDialog(null,"Enter The New Lumber's Stock Availability:" +
    								"",JOptionPane.QUESTION_MESSAGE);
    					 Lumber_stock = Integer.parseInt(Lumber_Stock);
    					 
    					code[count] = Lumber_code;
    				    type[count] = Lumber_Type;
    					price[count] = Lumber_price;
    					stocklevel[count] = Lumber_stock;
    				 }while (more.equals("Y"));
    				}
    			 }
    			 
    			 else if (Choice.equals("2")){
    				 System.out.println("Delete Lumber Item:");
    				  {
    					//Ask for Lumber code
    						String LumberCode = JOptionPane.showInputDialog(null,"Enter The Lumber Item's Code:" +
    								"",JOptionPane.QUESTION_MESSAGE);
    						int lumb_Code = Integer.parseInt(LumberCode);
    						
    						//Search array
    						for (i=0; i <= count; i++) {
    							if (code[i] == lumb_Code) {
    								
    								for (int p = i; p <= count; p++){
    								code[p] = code[p-1];
    							    type[p] = type[p-1];
    								price[p] = price[p-1];
    								stocklevel[p] = stocklevel[p-1];
    								}
    			 }
    				  }
    			 }
    			 }
    				
    		 else if (Choice.equals("3")){
    			 System.out.println("Modify Lumber Item:");
    			//Ask for lumber code
    			 String LumberCode = JOptionPane.showInputDialog(null,"Enter The Lumber Item's Code:" +
    						"",JOptionPane.QUESTION_MESSAGE);
    				int lumb_Code = Integer.parseInt(LumberCode);
    				
    				//Search array
    				for (i=0; i <= count; i++) {
    					if (code[i] == lumb_Code) {
    						//Need to find how to ask which one customer wants
    						String input = JOptionPane.showInputDialog(null,"Enter The New Lumber's Price:" +
    								"",JOptionPane.QUESTION_MESSAGE);
    						int Price_Replace = Integer.parseInt(input);
    						price[i] = Price_Replace;
    						String input2 = JOptionPane.showInputDialog(null,"Enter The New Lumber's Stock Level:" +
    								"",JOptionPane.QUESTION_MESSAGE);
    						int Stock_Replace = Integer.parseInt(input);
    						stocklevel[i] = Stock_Replace;
    		 }
    				}
    		 }
    			}
    
    		public static void Report(int count,int place,int [] number,String [] lastname,String [] firstname,String [] address,double [] creditlimit,int [] code,String [] type,double [] price,int [] stocklevel)
    		{
    			String Choice = "";
    			
    			while (!(Choice.equals("9"))){
    			 String reportChoices = "Reports" + "\n" + "1. All Customer Info" + "\n" + "2. All Lumber Info" + "\n" + "3. Current Value of Lumber Inventory" + "\n" + "4. All Customers Above Specific Credit Limit" + "\n" + "5. Report 5" + "\n" + "6. Report 6"
    			 + "\n" + "7. Report 7" + "\n" + "8. Report 8" + "\n" + "9. Exit report Menu";
    			 
    			 Choice= JOptionPane.showInputDialog(null,reportChoices,"",JOptionPane.QUESTION_MESSAGE);
    			 
    			 int i;
    			 
    			 if (Choice.equals("1")){
    				 System.out.println("All Customer Info:");
    				 for (i=0; i<= count; i++) {
    					 System.out.println(number[i] + "" + lastname[i] + ", " + firstname[i] + ": " + address[i] + " - Credit Score: " + creditlimit[i]);
    				 }//for end
    				 System.out.println(" ");
    			 }//if end
    			 else if (Choice.equals("2")){
    				 System.out.println("All Lumber Info:");
    				 for (i=0; i<= place; i++) {
    					 System.out.println(code[i] + "" + type[i] + ", " + price[i] + ": " + " - In Stock: " + stocklevel[i]);
    				 }//for end
    				 System.out.println(" ");
    			 }//else if end
    			 
    			 else if (Choice.equals("3")){
    				 double lumbinventory = 0;
    				 
    				 for (i=0; i<= place; i++){
    					 lumbinventory += (price[i] * stocklevel[i]);
    				 }//end for
    				 System.out.println("Current Value of Lumber Inventory: $" + lumbinventory + "\n");
    				 System.out.println(" ");
    			 }
    			 else if (Choice.equals("4")){
    				 double credlimit;
    				 String input;
    				 
    				 //Prompt for credit score
    				 input= JOptionPane.showInputDialog(null, "Enter Value of Credit Score:" + "", JOptionPane.QUESTION_MESSAGE);
    				 credlimit = Double.parseDouble(input);
    				 
    				 System.out.println("Customers Above A Credit Limit of " + credlimit +":");
    				 
    				 for (i=0; i <= count; i++){
    					 if (creditlimit[i] > credlimit){
    						 System.out.println(lastname[i] + ", " + firstname[i] + ": " + creditlimit[i]);
    					 }//end for
    				 }//end if
    				 System.out.println(" ");
    				 
    			 }
    			 else if (Choice.equals("5")){
    				 int inputcode;
    				 String input;
    				 
    				 //Prompt for lumber code
    				 input= JOptionPane.showInputDialog(null, "Enter the Lumber Code:" + "", JOptionPane.QUESTION_MESSAGE);
    				 inputcode = Integer.parseInt(input);
    				 
    				 System.out.println("Lumber information for code number " + input +":");
    				 
    				 for (i=0; i <= count; i++){
    					 if (code[i] == inputcode){
    						 System.out.println(type[i] + ", " + price[i] + ", " + stocklevel[i]);
    			 }
    				 }
    				 System.out.println(" ");
    			 }
    					 
    			 else if (Choice.equals("6")){
    				  String input;
    				 
    				 //Prompt for address
    				 input= JOptionPane.showInputDialog(null, "Enter a Customer's City of Residence:" + "", JOptionPane.QUESTION_MESSAGE);
    				 
    				 System.out.println("Customer information for " + input +":");
    				 
    				 for (i=0; i <= count; i++){
    					 if (address[i].equalsIgnoreCase(input)){
    						 System.out.println(number[i] + "," + lastname[i] + ", " + firstname[i] + "," + creditlimit[i]);
    			 }
    				 }
    				 System.out.println(" ");
    				 }
    					 
    			 else if (Choice.equals("7")) {
    					String customerID = "", first = "", last = "", items = "", itemName = "", report = "", addItem = "";
    					int cust_ID = 0, itemChosen = 0, item_stock = 0, quantity = 0;
    					double item_price = 0, cost = 0, item_cost = 0, total = 0, tax = 0;
    					
    					//Ask for customer ID
    					customerID =  JOptionPane.showInputDialog(null,"Enter The Customer ID:" +
    							"",JOptionPane.QUESTION_MESSAGE);
    					cust_ID = Integer.parseInt(customerID);
    					
    					//Search array
    					for (i=0; i <= count; i++) {
    						if (number[i] == cust_ID) {
    							
    							//Store first and last name
    							first = firstname[i];
    							last = lastname[i];
    							
    							do {
    						
    							items ="LumberInventory: \n\n";
    							
    							int placement = 19;
    							//Create a variable with lumber options
    							for (i=0; i <= placement; i++) {
    								items += "Code: " + code[i] + "       Type: " + type[i] + "       Price: $" + price[i] +
    								"       Amount In Stock: " + stocklevel[i] + "\n";
    							}
    							
    							items += "\n\n" + "Please enter the lumber code you wish to purchase:";
    							
    							//Prompt for item ID
    							String input = JOptionPane.showInputDialog(null,items + "",JOptionPane.QUESTION_MESSAGE);
    							itemChosen = Integer.parseInt(input);
    							
    							//Find the item in the array
    							for (i=0; i <= placement; i++) {
    								if (code[i] == itemChosen) {
    									item_price = price[i];
    									item_stock = stocklevel[i];
    									itemName = type[i];
    								}
    							}
    							
    							input =  JOptionPane.showInputDialog(null,"How many " + itemName + "'s would you like to purchase? In Stock: " +
    									item_stock + "  @ $" + item_price +"/each",JOptionPane.QUESTION_MESSAGE);
    							quantity = Integer.parseInt(input);
    							
    							if (quantity <= item_stock) {
    								item_cost = item_price * quantity;
    								cost += item_cost;
    								
    								report += quantity + "- " + itemName + " @  $" + item_price + "/each:  $" + item_cost + "\n";
    								
    							} else {
    								do {
    
    									input =  JOptionPane.showInputDialog(null,"ERROR: There is not enough in stock \n\n" +" How many " 
    											+ itemName + "'s would you like to purchase? In Stock: " + item_stock,JOptionPane.QUESTION_MESSAGE);
    									quantity = Integer.parseInt(input);
    								} while (quantity > item_stock);//End while
    								
    								item_cost = item_price * quantity;
    								cost += item_cost;
    								
    								report += quantity + "- " + itemName + " @  $" + item_price + "/each:  $" + item_cost + "\n";
    							}//End Else
    							
    							//Update stock level
    							for (i=0; i <= placement; i++) {
    								if (code[i] == itemChosen) {
    									stocklevel[i] = stocklevel[i] - quantity;
    								}
    							}
    							
    							//Prompt for another item
    							addItem =  JOptionPane.showInputDialog(null,"Would you like to add another item? (Y/N):" +
    									"",JOptionPane.QUESTION_MESSAGE);
    							
    							} while (addItem.equalsIgnoreCase("Y"));
    							
    							//Output sales report
    							System.out.println("Sales Report for " + last + ", " + first + ": \n");
    							System.out.println(report);
    								//Calculate tax
    								tax = cost * 0.07;
    							System.out.println("Sales Tax: $" + tax);
    								//Calculate total price
    								total = cost + tax;
    							System.out.println("Total Price: $" + total);
    							
    						}//End If
    					} //End for
    					System.out.println(" ");
    			 }
    			 
    			 else if (Choice.equals("8")){
    				 int inputPrice;
    				 String input;
    				 
    				 //Prompt for lumber code
    				 input= JOptionPane.showInputDialog(null, "Enter the Desired Lumber Price (ex. 1, 2, 3):" + "", JOptionPane.QUESTION_MESSAGE);
    				 inputPrice = Integer.parseInt(input);
    				 
    				 System.out.println("Information for Lumber Priced Less Than $" + input +":");
    				 
    				 for (i=0; i <= count; i++){
    					 if (price[i] < inputPrice){
    						 System.out.println(code[i] + "" + type[i] + ", " + price[i] + ": " + " - In Stock: " + stocklevel[i]);
    			 }
    				 }
    				 System.out.println(" ");
    			 }
    			}
    		}
    					 
    		
    		public static int start_program(int[]number,String[]lastname,String[]firstname,String[]address,double[]creditlimit,int count)
    		  {
    	        String newLine;
    	          try
    	          {
    	            //define a file variable for Buffered read
    	             BufferedReader Customer_file = new BufferedReader(new FileReader("customer.dat"));
    	             //read lines in file until there are no more lines in the file to read
    	             while ((newLine = Customer_file.readLine()) != null)
    	               {
    	                 //there is a "#" between each data item in each line
    	                  StringTokenizer delimiter = new StringTokenizer(newLine,"#");
    	                  count=count+1;
    	                  number[count] =Integer.parseInt(delimiter.nextToken());
    	                  lastname[count] = delimiter.nextToken();
    	                  firstname[count] =delimiter.nextToken();
    	                  address[count] =delimiter.nextToken();
    	                  creditlimit[count] = Double.parseDouble(delimiter.nextToken());
    	                }//while loop
    	               Customer_file.close();
    	            }//end try
    	        catch (IOException error)
    	          {
    	          //there was an error on the file writing
    	          System.out.println("Error on file read " + error);
    	          }//error on read
    	        return count;
    	  }//end start_program
    		
    		public static int start_program1(int[]code,String[]type,double[]price,int[]stocklevel,int place)
    		  {
    	        String newLine;
    	          try
    	          {
    	            //define a file variable for Buffered read
    	             BufferedReader Lumber_file = new BufferedReader(new FileReader("lumber.dat"));
    	             //read lines in file until there are no more lines in the file to read
    	             while ((newLine = Lumber_file.readLine()) != null)
    	               {
    	                 //there is a "#" between each data item in each line
    	                  StringTokenizer delimiter = new StringTokenizer(newLine,"#");
    	                  place=place+1;
    	                  code[place] =Integer.parseInt(delimiter.nextToken());
    	                  type[place] = delimiter.nextToken();
    	                  price[place] = Double.parseDouble(delimiter.nextToken());
    	                  stocklevel[place] =Integer.parseInt(delimiter.nextToken());
    	                }//while loop
    	               Lumber_file.close();
    	            }//end try
    	        catch (IOException error)
    	          {
    	          //there was an error on the file writing
    	          System.out.println("Error on file read " + error);
    	          }//error on read
    	        return place;
    	  }//end start_program
    
    		
    
    		public static void exit_program(int[]number,String[]lastname,String[]firstname,String[]address,double[]creditlimit,int count)
    		{
    			try
    			      {
    			      BufferedWriter Customer_file = new BufferedWriter(new FileWriter("customer.dat"));
    						for (int i = 0; i<=count; ++i)
    			              {
    			                //put "#" between each data item in the file
    			            	Customer_file.write(number[i] + "#" + lastname[i] + "#" +firstname[i]+ "#" +address[i] + "#" +creditlimit[i]);
    			                //write a new line in the file
    			            	Customer_file.newLine();
    			              }//for loop
    			            Customer_file.close();
    			          }//end try
    			        catch (IOException error)
    			          {
    			            //there was an error on the write to the file
    			             System.out.println("Error on file write " + error);
    			          }
    		}
    			
    		
    }//end of class

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You'll need to run this through the formatter first, then repost it. Its too difficult to follow as is.
    If its complaining about a 'while', it means you have a do without an enclosing while condition. That indicates a problem with your close brace positioning (which will be easier to see after you let eclipse format it).

  • #3
    Regular Coder
    Join Date
    Mar 2012
    Posts
    168
    Thanks
    5
    Thanked 11 Times in 11 Posts
    Under modify customer you need another brace. The current one only corresponds to the for loop.

    Code:
    number[count] = ID_number;
    firstname[count] = first_name;
    lastname[count] = last_name;
    address[count] = Address;
    creditlimit[count] = Cred_Lim;
    }}while (more.equals("Y"));


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •