Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is the output of my code

Enter price of an item 1: 
5
Do you want to proceed(yes/no)
yes
Enter Price of an item 2: 
3
Do you want to proceed(yes/no)
no
Prices of an item[5, 3]


What I have tried:

package pointofsales;
import java.util.Scanner; 
import java.util.ArrayList;
public class POINTOFSALES {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        
        System.out.println("Enter price of an item 1: ");
        int price1 = input.nextInt(); 
        System.out.println("Do you want to proceed(yes/no)");
        
        String question1 = input.next();   
        if(question1.equalsIgnoreCase("yes")){
            
        System.out.println("Enter Price of an item 2: ");
        int price2 = input.nextInt();
        System.out.println("Do you want to proceed(yes/no)");
        
        String question2 = input.next();
        if(question2.equalsIgnoreCase("no")){
             
            ArrayList<Integer>list1 = new ArrayList<Integer>();
            
            list1.add(price1);
            list1.add(price2);        
            System.out.println("Prices of an item" +list1);
             
         }
        }
    }        
}
Posted
Updated 8-Oct-21 21:34pm
v3
Comments
OriginalGriff 9-Oct-21 3:37am    
Stop trying to get rid of the evidence that you wanted help with your homework.
It makes the answers meaningless, and that helps nobody.

1 solution

First off, you are going to need a loop to enter values: Loops - Learn Python - Free Interactive Python Tutorial[^] - I'd suggest a while loop based on the result of the "Do you want to proceed?" question.

Inside the loop, you add the prices to your collection: Python - Add List Items[^]

After the loop, print your items, and the total value. You can either calculate it as you go round your main loop, or use a for loop to process each element.

Think about it: it's pretty simple to do (and involves less code that you have at the moment!)
Get the while loop working first, then add items to your collection, then work out the total - code, test, fix, test, fix, test, and only move on to the next bit when you have it working.

This may help: How to Write Code to Solve a Problem, A Beginner's Guide[^] but nobody here is going to write all the code for you - it's your homework, and you really need to do it for yourself if you are going to learn how to do these things at all!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900