Results 1 to 7 of 7
  1. #1
    shi
    shi is offline Member
    Join Date
    Dec 2015
    Posts
    4
    Rep Power
    0

    Default I realy need help to complete my code :quarterly sales

    Hello,
    I am writing a quarterly sales program.There is a txt file that the program should read. and at the end calculate the total for every for division and quarter separately.I have tried to use different variable for calculation but it did not work.I cannot figure it out how it is possible, because I should not use array.Can anybody help me?
    this is the file that the program should read:

    N
    1
    35.50
    N
    2
    26.99
    N
    3
    77.45
    N
    4
    58.30
    S
    1
    132.15
    S
    2
    81.19
    S
    3
    159.06
    S
    4
    83.55
    E
    1
    99.40
    E
    2
    25.39
    E
    3
    50.25
    E
    4
    43.21
    W
    1
    120.89
    W
    2
    392.11
    W
    3
    105.76
    W
    4
    299.95
    N
    2
    66.15
    N
    3
    38.22
    N
    4
    27.66
    E
    2
    135.32
    E
    3
    37.50
    E
    4
    9.10
    and here is my code:
    import java.io.*;
    import java.util.Scanner;

    public class SalesReporting {
    public static void main(String[] args) throws Exception {
    String inputData;
    String division=null;
    int qtrRead=0;
    double salesRead=0.0;
    String filePath;
    File file;
    PrintWriter outputErrorLog;
    Scanner keyboard = new Scanner(System.in);
    Scanner inputFile;
    Boolean dataFileError;
    Boolean ValidSaleFile = false;

    System.out.println("\tHarmway Corporation\nQuarterly Sales Report Generator");

    do {
    System.out.print("\nEnter sales data file: ");
    filePath = keyboard.next();
    file = new File(filePath);
    if (!file.exists()) {
    System.out.println("\n[!] Sales data file not found");
    }
    } while (!file.exists());
    inputFile = new Scanner(file);
    file = new File("errorlog.txt");
    outputErrorLog = new PrintWriter(file);
    dataFileError = false;
    System.out.println("Validating sales file...");
    while (inputFile.hasNext())
    {
    inputData = inputFile.next();
    try
    {
    division = inputData;
    if (isValidDivision(division)) {
    }
    else
    {
    dataFileError = true;
    outputErrorLog.println(division + ",Invalid division value");
    }
    }
    catch (Exception e)
    {
    dataFileError = true;
    outputErrorLog.println(inputData + ",Invalid division value");
    }
    inputData = inputFile.next();
    try
    {
    qtrRead = Integer.parseInt(inputData);

    if (isValidQuarter(qtrRead)) {

    }

    else
    {
    dataFileError = true;
    outputErrorLog.println(qtrRead + ",Invalid quarter value");
    }
    }
    catch (Exception e)
    {
    dataFileError = true;
    outputErrorLog.println(inputData + ",Invalid quarter value");
    }
    inputData = inputFile.next();
    try
    {
    salesRead = Double.parseDouble(inputData);
    if (isValidSales(salesRead)) {
    }
    else
    {
    dataFileError = true;
    outputErrorLog.println(salesRead + ",Invalid sales amount value");
    }
    }
    catch (Exception e)
    {
    dataFileError = true;
    outputErrorLog.println(inputData + ",Invalid sales amount value");
    }
    }
    if (dataFileError)
    {
    ValidSaleFile = false;
    System.out.print("\nThe data file contains data errors"
    + " (See error log for details)");
    }
    else
    {
    ValidSaleFile = true;
    System.out.print("\nThe data file is validated");
    ValidSaleFile = true;
    System.out.println( "\n Sales Report\n --------------------\n");
    }
    inputFile.close();
    outputErrorLog.close();
    }
    public static boolean isValidDivision(String division) {
    if (division.equalsIgnoreCase("N") ||
    division.equalsIgnoreCase("S") ||
    division.equalsIgnoreCase("E") ||
    division.equalsIgnoreCase("W")) {
    return true;
    }
    else {
    return false;
    }
    }
    public static boolean isValidQuarter(int qtrRead) {
    if (qtrRead >= 1 && qtrRead <= 4) {
    return true;
    }

    else {
    return false;
    }
    }
    public static boolean isValidSales(double salesRead) {
    if (salesRead >= 0) {
    return true;
    }

    else {
    return false;
    }
    }
    }

    This is the the description:
    A compony division would like to automate the process of report development for company sales across all their sales divisions.

    Division Value representing North, South, East and West.
    Quarter Value representing Jan-Mar, Apr-Jun, Jul-Sep and Oct-Dec.

    Design and develop a solution that will read in sales information from a txt file, validate the data, and generate a quarterly sales report.
    When a field does not pass validation, a message indicating the value and field causing the error will be written to an error log file. The error log file will contain all validation errors which were found in the data file.

    If no validation errors were found, display the report.

    Screen Output Requirements

    Sales Report
    ----------------------
    Total Sales by division:
    North $total
    South $total
    East $total
    West $total

    Total Sales by quarter:
    Jan-Mar $total
    Apr-Jun $total
    Jul-Sep $total
    Oct-Dec $total

    Year End Total: $total

    My problem is calculating the totals(9 different totals)

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: I realy need help to complete my code :quarterly sales

    Please place your code between [CODE][/CODE] tags to preserve formatting.
    Also, make certain your {} are properly indented to more easily follow the code.

    Since you can't use arrays, you need to process the input as you read it.
    When you see an "N", then process the North division, "S" for South division.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    shi
    shi is offline Member
    Join Date
    Dec 2015
    Posts
    4
    Rep Power
    0

    Default Re: I realy need help to complete my code :quarterly sales

    Thanks for your reply.
    How I can specify to only sum up the sales prices for N division not all the amounts?

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: I realy need help to complete my code :quarterly sales

    Each division has 3 values. The division designator (N,S,E,W), the quarter, and the amount. So you know that when you read a letter, the following information applies to that letter until you read another letter. Or you can just assume the next two entries after each letter go with the letter.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    shi
    shi is offline Member
    Join Date
    Dec 2015
    Posts
    4
    Rep Power
    0

    Default Re: I realy need help to complete my code :quarterly sales

    I added this part in
    Java Code:
         switch ( division)
                   {
                     case ("N"):
                        double ntotal=0.0;
                         ntotal=salesRead+ntotal;
                         System.out.println("n"+ntotal);
                       break;
                       
                     case ("S"):
                        double stotal=0.0;
                        stotal=salesRead+stotal;
                        System.out.println("s"+stotal);
                        break;
                     case ("W"):
                         double wtotal=0.0;
                        stotal=salesRead+wtotal;
                        System.out.println("w"+wtotal);
                        break;
                     case  ("E"):
                       double etotal=0.0;
                        stotal=salesRead+etotal;
                        System.out.println("e"+etotal);
                        break;
                    }
    but it does not calculate the total for each division.it just print the amount for each quarter. at least one step forward
    Last edited by shi; 01-14-2016 at 10:46 PM.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: I realy need help to complete my code :quarterly sales

    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: I realy need help to complete my code :quarterly sales

    Your total variables are local to that case.
    You need to define them outside of the switch statement if you want to actually sum up all the rows.

    ETA: In fact they need to be defined right at the start, before any looping over the file.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. pls help me to complete this code
    By michael wamicha in forum New To Java
    Replies: 1
    Last Post: 10-30-2013, 10:51 AM
  2. I m new in java pls help me complete this code
    By michael wamicha in forum New To Java
    Replies: 4
    Last Post: 10-29-2013, 10:14 PM
  3. I need urgent help to complete this code please!
    By kenson02 in forum New To Java
    Replies: 3
    Last Post: 12-14-2011, 03:37 AM
  4. complete the code
    By blackz in forum New To Java
    Replies: 2
    Last Post: 09-11-2011, 03:04 AM
  5. help me with a realy easy program (substring)
    By michcio in forum New To Java
    Replies: 7
    Last Post: 01-27-2008, 01:41 AM

Posting Permissions

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