Need to print output without arrays

Stormstreet's Avatar, Join Date: Nov 2009
Go4Expert Member
Code:
import java.io.*;

public class Cw01 
{

    public static void main(String[] args) throws Exception
    {
       
       int w,r;
       String de,s,ic,st;
       float c;
       
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        do
        {
            System.out.println("=======================================");
            System.out.println("=========WELCOME TO TREKKER============");
            System.out.println("=======================================");
            
            System.out.println("ENTER ITEM CODE:");
            ic = br.readLine();            
            
            System.out.println("ENTER DESCRIPTION OF ITEM:");
            de = br.readLine();
            
            System.out.println("ENTER Weight OF ITEM IN GRAMS:");
            w = Integer.parseInt(s = br.readLine());
            
            System.out.println("ENTER COST OF ITEM ($):");
            c = Float.parseFloat(s = br.readLine());
            
            System.out.println("ENTER NUMBER OF ITEMS REQUIRED:");
            r = Integer.parseInt(s = br.readLine());
            
            
            System.out.println("**********************************************");
            System.out.println("  SUMMARY DATA FOR ITEM" +" "+ ic +" " + de);
            System.out.println("  TOTAL WEIGHT: " +" "+ w+" "+ "GRAMS");
            System.out.println("  TOTAL PRICE : "+" " + r*c );
            System.out.println("**********************************************");
            
            System.out.println("ENTER MORE DATA ? (Y/N)");
            st = br.readLine();
            st.charAt(0);
        }while (st.equalsIgnoreCase("y"));
            
            System.out.println("********************************************");
            System.out.println("********SUMMARY OF WHAT WAS ORDERED*********");
            System.out.println(r+" "+ de +" "+ ic+" "+"@"+" "+c+" "+ " TOTAL $" + r*c);
            
    }

}

Hi I need to print out a summary of all items that was input was by the user.When the program runs it only prints the last input and not all.How do i get it to print all items without using arrays
venami's Avatar, Join Date: Dec 2008
Ambitious contributor
You can declare a String variable and append the summary details(whatever it may be) to it for every item inside the loop.

Then you can print the variable outside the loop to view the summary of all the items.
Stormstreet like this
Stormstreet's Avatar, Join Date: Nov 2009
Go4Expert Member
Didnt I do that already.

String de,s,ic,st;

Or can u elaborate a liitile on your suggestion cause i'm a bit confused thanks.
Stormstreet's Avatar, Join Date: Nov 2009
Go4Expert Member
When asked if to enter more data and no is selected the final summary should be like this:
eg:
5 Rope k23/1 @ $12.34 Total $61.70
50 Nail 12/ewr @ $2.23 Total $111.50

Grand Total weight :
Grand total cost:

but its just printing the last statement entered.

A little more info on my problem
venami's Avatar, Join Date: Dec 2008
Ambitious contributor
You have calculated the values and displayed them inside the loop. You have displayed the summary outside the loop, where the variables that you declared will hold only the final value.

To have the details of all the items, you can have another variable, say str.
For every loop, append the details(variables that you already declared) at the end of the variable 'str'.

So, at the end of the loop, the variable 'str' will have all the items' details and you can print it.
Stormstreet like this
venami's Avatar, Join Date: Dec 2008
Ambitious contributor
If you could not understand yet, just let me know where you don't understand. I can explain.
Stormstreet like this
Stormstreet's Avatar, Join Date: Nov 2009
Go4Expert Member
ok tell me if i'm catching on or that badly off lol. I should declare a new String variable eg. str.Then assign variables i want to print out
eg. str =( r+" "+ de +" "+ ic+" "+"@"+" "+c+" "+ " TOTAL $" + r*c)
Stormstreet's Avatar, Join Date: Nov 2009
Go4Expert Member
Sorry but its my first time with java so forgive me lol
venami's Avatar, Join Date: Dec 2008
Ambitious contributor
You got my point. But the way you are doing is wrong.

So you can very well search the internet on how to append variables to another variable. Or you can also refer a JAVA book for that.

This is the correct way for a beginner like you to get familiarized with any programming language.
Stormstreet like this
Stormstreet's Avatar, Join Date: Nov 2009
Go4Expert Member
took your advice but still looking for how to append variables to a variable