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

Thread: HELP PLEASEE!!

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default HELP PLEASEE!!

    i'm a student taking a beginner java class and i need help just fixing some of my code

    basically, i need help figuring out how to read delimiters to separate tokens

    if anyone can help, please comment and i'll share my code! it shouldn't take too long - promise!

    thank you so much!!


  2. #2
    Junior Member
    Join Date
    Jul 2012
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: HELP PLEASEE!!

    here's my code; i always get InputMismatch error -___-

    import java.text.DecimalFormat;
    import java.text.NumberFormat;
    import java.io.*;
    import java.util.Scanner;
     
    public class Application{
     
    	public static void main (String[] args)
    	{
     
    	try{
    		//Input File
    		File input = new File ("squalmart.in");	
    		if (!input.exists() && !input.isFile()) {
    		System.err.println("File " + input.getName() + " does not exist.");
    		System.exit(1);
    			}
    		Scanner inputFile = new Scanner(input);
    		inputFile.useDelimiter("\t");
    		int totalLines = inputFile.nextInt();
    		int n = 0;
    		product[] p = new product [totalLines];
    		for (int i = 0; i < totalLines; i++)  {
    			String Product_Category = inputFile.next();
    			String Product_Name = inputFile.next();
    			int Quantity_On_Hand=0;
    			if (inputFile.hasNextInt()) {
    				Quantity_On_Hand = inputFile.nextInt();
    				}
    			else{
    				System.err.println ("The Quantity_On_Hand for this product is not a valid integer value. The input line has been discarded.");
    				inputFile.nextLine();
    				continue;
    				}
    			int Number_Sold = 0;
    			if (inputFile.hasNextInt()) {
    				Number_Sold = inputFile.nextInt(); 
    				}
    			else{
    				System.err.println ("The Number_Sold for this product is not a valid integer value. The input line has been discarded.");
    				inputFile.nextLine();
    				continue;
    				}
    			float Product_Price = 0;
    			if (inputFile.hasNextFloat()) {
    				Product_Price = inputFile.nextFloat(); 
    				}
    			else{
    				System.err.println ("The Product_Price for this product is not a valid value. The input line has been discarded.");
    				inputFile.nextLine();
    				continue;
    				}
    			float Product_Cost = 0;
    			if (inputFile.hasNextFloat()) {
    				Product_Cost = inputFile.nextFloat(); 
    				}
    			else{
    				System.err.println ("The Product_Cost for this product is not a valid value. The input line has been discarded.");
    				inputFile.nextLine();
    				continue;
    				}
    			if (Product_Category.equals("Shoes") || Product_Category.equals("Men's Wear") || Product_Category.equals("Women's Wear") || Product_Category.equals("Household") || Product_Category.equals("Home and Garden") || Product_Category.equals("Automotive")) {
    				p[n]=new product();
    				p[n].nproduct (Product_Category, Product_Name, Quantity_On_Hand, Number_Sold, Product_Price, Product_Cost);
    				n++;
    				System.out.println(n);
    				}
    			else {
    				System.err.println("The category does not match one of the possible categories. The input line has been discarded.");
    				System.err.println(Product_Category + Product_Name + Quantity_On_Hand + Number_Sold + Product_Price + Product_Cost);
    				inputFile.nextLine();
    				continue;
    			}		
    				p[n]=new product();
    				p[n].nproduct (Product_Category, Product_Name, Quantity_On_Hand, Number_Sold, Product_Price, Product_Cost);
    				n++;
    			}
    		System.out.println("howdy");
    		//Starts output file
    		String outputFile = "squalmart.out";
    		PrintWriter outputStream = new PrintWriter(outputFile);
    		//Category Report
    		outputStream.println("Category Report:");
    		outputStream.println("================");
    		outputStream.println("   Item                       Price       # In Stock");
    		outputStream.println("   -------------------------------------------------");
    		outputStream.flush();
    		DecimalFormat fmt = new DecimalFormat ("$####.00");
    		for (int j=0; j<n; j++) {
    			if (p[j].skip()) {
    			continue;
    				}
    			outputStream.println(p[j].Product_Category());
    			if (p[j].Quantity_On_Hand()==0) {
    				outputStream.println("\t" + p[j].Product_Name() + "\t\t      " + fmt.format(p[j].Product_Price()) + "\t\tCurrently out of stock");
    				}
    			else {
    			outputStream.println("\t" + p[j].Product_Name() + "\t\t      " + fmt.format(p[j].Product_Price()) + "\t\t" + p[j].Quantity_On_Hand());
    				}
    			for (int k=j+1; k<n; k++) {
    				if (p[j].Product_Category().equals(p[k].Product_Category())) {
    					if (p[k].Quantity_On_Hand()==0) {
    					outputStream.println("\t" + p[k].Product_Name() + "\t\t      " + fmt.format(p[k].Product_Price()) + "\t\tCurrently out of stock");
    					}
    				else {
    					outputStream.println("\t" + p[k].Product_Name() + "\t\t      " + fmt.format(p[k].Product_Price()) + "\t\t" + p[k].Quantity_On_Hand());
    					}
    					p[k].skip(true);
    					}
    				}
    			}
    		//Sales Report
    		outputStream.println("Sales Report:");
    		outputStream.println("==============");
    		outputStream.println("   Item                          Revenue          Profit");
    		outputStream.println("   -----------------------------------------------------");
    		for (int j=0; j<n; j++) {
    		if (p[j].skip()) {
    			continue; 
    			}
    			outputStream.println(p[j].Product_Category());
    			if (p[j].Number_Sold() == 0) {
    				outputStream.println("\t" + p[j].Product_Name() + "     Not Sold");
    				}
    			else {
    				outputStream.println("\t" + p[j].Product_Name() + "    " + fmt.format(p[j].Revenue()) + "           " + fmt.format(p[j].Profit()));
    				}
    			for (int k=j+1; k<n; k++) {
    				if (p[j].Product_Category() .equals(p[k].Product_Category())) {
    					outputStream.println("      " + p[k].Product_Name() + "    " + fmt.format(p[k].Revenue()) + "      " + fmt.format(p[k].Profit()));
    					}
    				}
    		}
    		//Manager's Report
    		outputStream.println("Manager's Report:");
    		outputStream.println("=================");
    		outputStream.println("   Total Number of Products Sold              Gross Sales");
    		outputStream.println("   ------------------------------------------------------");
    		float totalSales=0;
    		int totalSold=0;
    		for (int j=0; j<n; j++) {
    			totalSold=totalSold+p[j].Number_Sold();
    			totalSales=totalSales+p[j].Revenue();
    			}
    			outputStream.println(" " + totalSold + "                                " + fmt.format(totalSales)); 
    			outputStream.flush();
          		}
    		catch (IOException e) {
    			System.err.println("Caught IOException: " +  e.getMessage());
    			}
    		}
    	}
    Last edited by ash12; July 22nd, 2012 at 11:28 AM.

  3. #3
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: HELP PLEASEE!!

    Oh the pain to my eyes, all that code looking text there...
    Throw in some tags and I will look it over....

  4. #4
    Junior Member
    Join Date
    Jul 2012
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: HELP PLEASEE!!

    ahh i'm new! how do i use tags?

  5. #5
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: HELP PLEASEE!!

    put [ CODE] at the beginning and [/ Code] at the end without the space in there

  6. #6
    Junior Member
    Join Date
    Jul 2012
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: HELP PLEASEE!!

    fixed! thanks for offering to help!

  7. #7
    Junior Member
    Join Date
    Jul 2012
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: HELP PLEASEE!!

    I fixed it!

Similar Threads

  1. Beginner pleasee help with java code
    By chuy525 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 24th, 2011, 06:38 PM
  2. Anyone can help me with my code pleasee?
    By Kyo in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 29th, 2011, 08:07 AM
  3. help pleasee
    By YNWA in forum Object Oriented Programming
    Replies: 2
    Last Post: March 22nd, 2011, 09:39 PM