0

I am trying to get series of user input and from them I need to get this kind of output, I tried various methods but didn't work.

Day      Sales
Sunday   $ 0.00
Monday   $ 4,300.76
Tuesday  $ 276.92
Wednesday$ 15,976.43
Thursday $ 0.00
Friday   $ 49,764.67
Saturday $ 250.00
-----------
Total Sales: $ 70,568.78
Average sale value: $2,367.92
Commission on Sales: $7,551.19 ***

I am trying using this, But it gives me errors and I don't have idea to get that kind of output. And also I used list but how can I separate the values?

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    do
    {
        System.out.println("Enter Day of Sale (Sunday, Monday, Tuesday, etc.): ");
        String text = br.readLine();
        System.out.println("Enter Sale Amount: ");
        int a  = Integer.parseInt(br.readLine(), 7);
        System.out.println("Are you finished entering sales? (Y/N)");

        System.out.println(text);
        System.out.println(a);
        if (br.readLine().startsWith("y"))
        {
        } else
        {
            break;
        }
    } while (true);
    br.close();

How can I do that? Thanks in advance.

3
  • Do you handle the IOException that the BufferedReader can produce? Because the readLine method got throws IOException so you need to handle that. P.S: I would recommend to use the Scanner instead Commented Oct 17, 2018 at 11:55
  • It gives me errors is not a working problem description. See minimal reproducible example. Beyond that: go about one problem after the other. And first use a search engine and see what others already asked before. Commented Oct 17, 2018 at 11:57
  • On what criteria you are calculating commission ? Commented Oct 17, 2018 at 12:22

1 Answer 1

2

tl;dr - Introduce object which will hold data, and add object's to List. To display, iterate thru List.

 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 List<Entry> collectedData = new ArratList<>();

    do
    {
        Entry entry = new Entry();
        System.out.println("Enter Day of Sale (Sunday, Monday, Tuesday, etc.): ");
        entry.dayName = br.readLine();
        System.out.println("Enter Sale Amount: ");
        entry.value  = Integer.parseInt(br.readLine(), 7);
        collectedData.add(entry);
        System.out.println("Are you finished entering sales? (Y/N)");

        System.out.println(text);
        System.out.println(a);
        if (br.readLine().startsWith("y"))
        {
        } else
        {
            break;
        }
    }

for(entry : collectedData) {
    System.out.println(entry.dayName + ": " + entry.value);
}

public class Entry {
    String dayName;
    Integer value;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.