Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q1: Write a java code for the following state diagram. The diagram represents an

ID: 3572206 • Letter: Q

Question

Q1: Write a java code for the following state diagram. The diagram represents an online Accessories shopping system. The system offers 3 basic items (shoes, bags, And accessories) the user most select one of the items that he wants to buy then the system should add them to the chart. When selecting the shoes the user has to choose a color (black, white or gray shoes), When selecting a bag the user has to choose the type (hand or back bag) and when selecting the accessories the user has to choose the type (ring, earrings, necklace or bracelet).

ect item k Shdes shoes White shdes gray shges nd b g ck b bag ring aring ckla accessories racel

Explanation / Answer

import java.io.*;
import java.util.*;

public class Shopping {
  
   public static void main(String[] args)
   {
       Scanner scan = new Scanner(System.in);
       System.out.println("Select an item(s:shoes, b:bag, a:accessories)");
       String s=scan.next();
       if(s.equals("s"))
       {
           System.out.println("Select shoe color(b:black, w:white, g:gray)");
           String s1=scan.next();
           if(s1.equals("b"))
           {
               System.out.println("black shoe has been added to chart");
           }
           else if(s1.equals("w"))
           {
               System.out.println("white shoe has been added to chart");
           }
           else if(s1.equals("g"))
           {
               System.out.println("gray shoe has been added to chart");
           }
       }
       else if(s.equals("b"))
       {
           System.out.println("Select bag type(b:back bag, h:hand bag)");
           String s1=scan.next();
           if(s1.equals("b"))
           {
               System.out.println("back bag has been added to chart");
           }
           else if(s1.equals("h"))
           {
               System.out.println("hand bag has been added to chart");
           }
       }
       else if(s.equals("a"))
       {
           System.out.println("Select accessories type(r:ring, e:earring, n:necklace, b:bracelet)");
           String s1=scan.next();
           if(s1.equals("b"))
           {
               System.out.println("bracelet has been added to chart");
           }
           else if(s1.equals("r"))
           {
               System.out.println("ring has been added to chart");
           }
           else if(s1.equals("e"))
           {
               System.out.println("earring has been added to chart");
           }
           else if(s1.equals("n"))
           {
               System.out.println("necklace has been added to chart");
           }
       }
   }

}