PRASHNIKAप्रश्निका
‹ Back to the paper

At Get It All supermarket, a POS (Point of Sale) system is designed. The cart management is visible…

Computer Science20255 marksShort answer
At Get It All supermarket, a POS (Point of Sale) system is designed. The cart management is visible to the POS operator. The newer carts get added and once the bill payment is done the current cart gets checked out from the system. The operator has 4 options like add cart, check out cart, view cart queue and close the counter. The class Cart is created to represent the node of the linked list.
public class Cart 
{ 
    int cartNo; 
    Cart next; 
    Cart(int cartNo) 
    { 
        this.cartNo = cartNo; 
        next = null; 
    } 
}
The class POS is created to represent the POS for cart management. Observe the given code and answer the following questions.
import java.util.*; 
public class POS 
{ 
    Cart first; 
    static int count = 0; 
    static Scanner sc = new Scanner(System.in); 
    void viewQueue( ) 
    { 
        Cart temp = first; 
        boolean flag = false; 
        System.out.println("The carts at the counter are"); 
        while(temp != null)  
        {        
            System.out.println(temp.cartNo); 
            ?1? 
            ?2? 
        }  
        if(!flag) 
            System.out.println("The checkout counter is empty"); 
        else 
            System.out.println("number of carts currently=" + count); 
    } 
    void addCart()  
    { 
        System.out.print("Enter the new cart number: "); 
        int no = sc.nextInt(); 
        Cart newCart = new Cart(no); 
        if(first == null) 
            first = newCart; 
        else 
        { 
            Cart temp = first; 
            while(temp.next != null) 
                temp = temp.next;   
            temp.next = newCart; 
        } 
        count++; 
    } 
    void checkOutCart()  
    { 
        ?1? 
        System.out.println("Cart being removed =" + temp.cartNo);  
        ?2? 
        temp.next = null; 
        temp = null; 
        ?3? 
        System.out.println("Carts remaining " + count); 
    } 
}
(a)[2.0]
Write the code for the blanks given in the method void viewQueue( ).
(b)[3.0]
Mention the code for the blanks given in the method void checkOutCart( ).

Answer

Answer (a)

AI
?1? flag = true; ?2? temp = temp.next;

Answer (b)

AI
?1? Cart temp = first; ?2? first = temp.next; ?3? count--;
Data structures

From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 62.