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

Thread: Can't get right output for my code

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can't get right output for my code

    Hey everyone, I am having difficulties getting my project to run correctly, when I run the code I only get one input box and none for the other strings
    I am new to java programming if someone could test this on their compiler and perhaps suggest a fix It would be greatly appreciated

    package robsproject;
    import javax.swing.JOptionPane;

    import java.io.*;
    public class Amazon {
    //Each output will have 5 different product fields: Productcode, Productdescription, inventorylevels, price, & cost.
    //Part 1
    public static String[] Productcode = new String[1000];
    public static String[] Productdesc = new String[1000];
    public static double[] price = new double[1000];
    public static double[] cost = new double[1000];
    public static double[] inv = new double[1000];

    public static double[] retailvalue = new double[1000];
    public static double[] profitvalue = new double[1000];

    public static int count = 0;
    public static int bookCount = 0;
    public static int softwareCount = 0;
    public static double totalInv = 0.0;
    public static double totalValue = 0.0;
    public static double totalProfit = 0.0;
    public static double discount = 0.0;

    public static void main(String[] args) throws IOException {
    String fileName = "Amazonproductlist.txt"; //"C:\\datafiles\\products.txt" in java you need the \\
    FileReader inputFile = new FileReader(fileName);
    BufferedReader inputBuffer = new BufferedReader(inputFile);
    //Header
    String header = inputBuffer.readLine();
    //System.out.println("Description Qty Price Cost Retail Value Profit Value ");
    System.out.printf("%-10s %-20s %10s %10s %10s %15s %15s \n", "Code", "Description", "Price",
    "Cost", "Qty", "Retail Value", "Profit Value");

    //Body
    String numString = inputBuffer.readLine();
    while (numString != null)
    {

    String[] a = numString.split(",");
    Productcode[count] = (a[0]).trim();
    Productdesc[count] = (a[1]).trim();
    price[count] = Double.parseDouble((a[2]).trim());
    cost[count] = Double.parseDouble((a[3]).trim());
    inv[count] = Double.parseDouble((a[4]).trim());

    retailvalue[count] += price[count] * inv[count];
    profitvalue[count] += (price[count] - cost[count]) * inv[count];

    totalInv += inv[count];
    totalValue += retailvalue[count];
    totalProfit += profitvalue[count];

    //to keep track of books and software:
    if (Productcode[count].substring(0,1).equals("J"))
    bookCount++;
    else if (Productcode[count].substring(0,1).equals("N"))
    softwareCount++;

    //output the arrays
    System.out.printf("%-10s %-20s %,10.0f %,10.2f %,10.2f %,15.2f %,15.2f \n", Productcode[count],
    Productdesc[count], price[count], cost[count], inv[count], retailvalue[count], profitvalue[count]);

    count++;
    numString = inputBuffer.readLine();
    }
    inputBuffer.close();
    //Footer
    /*
    The total number products read in was 42.
    The total number of inventory items read in was 3800.
    The total number books read in was 12.
    The total number software read in was 30.
    The total retail value of inventory is $397,455.00.
    The total profit value of inventory is $197,455.00.
    */
    System.out.println("The total number products read in was " + count);
    System.out.println("The total number of book products read in was " + bookCount); //complete this System.out.println(bookCount); //complete this
    System.out.println("The total number of software products read in was " + softwareCount); //complete this
    System.out.println("The total number of inventory items read in was " + totalInv); //complete this or use below
    System.out.printf("The total retail value of inventory is $%,.2f \n", totalValue);
    System.out.printf("The total profit value of inventory is $%,.2f \n", totalProfit);

    adjustPrice();

    String strSearch = JOptionPane.showInputDialog("Enter code to search");
    for (int i=0; i< count;i++)
    {
    if (strSearch.equals(Productcode[i])){

    if (Productcode[i].equals(strSearch)){


    System.out.println("Product Code:\t\t\t\t" +Productcode[i] + "\n" + "Description:\t\t\t\t" + Productdesc[i] + "\n" +
    "Price:\t\t\t\t\t\t$" + Math.round(price[i] *100)/100.0 + "\n" + "Cost:\t\t\t\t\t\t$" + cost[i] + "\n" + "Inventory:\t\t\t\t\t" + inv[i]+ "\n"+
    "Retail Value:\t\t\t\t$"+ totalValue+ "\n" + "Profit Value: \t\t\t\t$" + totalProfit);


    }


    }
    }


    }

    private static void adjustPrice() {

    }
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Can't get right output for my code

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly using code or highlight tags per the above link.

Similar Threads

  1. Replies: 1
    Last Post: June 30th, 2014, 10:11 AM
  2. can someone fix my code to get the following output?
    By kmal47 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 8th, 2014, 05:50 AM
  3. how to get output for this ajax using code. Code is shown bellow.
    By pragathi in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 4th, 2014, 05:51 AM
  4. My Code has no output
    By dustinjl45 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 11th, 2013, 10:00 AM
  5. What does this code output?
    By rickjames8710 in forum Java Theory & Questions
    Replies: 4
    Last Post: January 14th, 2012, 11:06 PM