
import java.io.*;
import java.sql.*;





class Sweets
{
    int code;
	String item;
	String type;
	String expirydate;
	int quantity;
	double rate;
	
}
class Group1 extends Sweets
{
String size;	
}

class Group2 extends Sweets

{
	
	String weight;

}

class Sweets_System 
{
Group1 K;
Group2 F;


void Add() throws IOException
{

BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
 
 System.out.println("Add  code");
int code=Integer.parseInt(br.readLine());
System.out.println("Add  item");
String item=br.readLine();
System.out.println("Add  type");
 String type=br.readLine();
System.out.println("Add  expiry date");
String expirydate=br.readLine();
System.out.println("Add  quantity");
int quantity=Integer.parseInt(br.readLine());
System.out.println("Add rate");
String temp=br.readLine(); 
double rate = Double.valueOf(temp.trim()).doubleValue();



   if (type.equals("Chocolates")||type.equals("Cookies")||type.equals("Biscuits")||type.equals("Candies"))
	  {
System.out.println("Add Sweets size");
	    try {
  Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
  Connection con = DriverManager.getConnection("jdbc:odbc:sa","","");
String size=br.readLine();
  PreparedStatement stmt1 = con.prepareStatement("INSERT INTO Group1 VALUES(?, ?, ?, ?, ?, ?, ?)");

   stmt1.setInt(1, code);
   stmt1.setString(2, item);
   stmt1.setString(3, type);
   stmt1.setString(4, expirydate);
   stmt1.setInt(5, quantity);
   stmt1.setDouble(6, rate);
   stmt1.setString(7, size);
   stmt1.execute();
   stmt1.close();
   con.close();
    } catch (java.lang.Exception ex) {
	ex.printStackTrace();
	   }
	  }
	   else
		    if (type.equals("Halwa")||type.equals("Dates")||type.equals("Nuts"))
	  {
System.out.println("Add Sweets Weight");
		    try {
  Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
  Connection con = DriverManager.getConnection("jdbc:odbc:sa","","");
String weight=br.readLine();
PreparedStatement stmt1 = con.prepareStatement("INSERT INTO Group1 VALUES(?, ?, ?, ?, ?, ?, ?)");

   stmt1.setInt(1, code);
   stmt1.setString(2, item);
   stmt1.setString(3, type);
   stmt1.setString(4, expirydate);
   stmt1.setInt(5, quantity);
   stmt1.setDouble(6, rate);
    stmt1.setString(7, weight);
   stmt1.execute();
   stmt1.close();
   con.close();
    } catch (java.lang.Exception ex) {
	ex.printStackTrace();
	   }
	  }



void Display()throws IOException
	{


	}

void update()throws IOException
	{

	}

void search()throws IOException
{

	int code;
	String item;
	String type;
	int flag =0;
	
	BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
	System.out.print("\n\n\nEnter the Sweets to search\n\n \n");

	int code=Integer.parseInt(br.readLine());
	String item=br.readLine();
	String type=br.readLine();
    try 
		 {
		
		Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
		Connection con = DriverManager.getConnection("jdbc:odbc:emp","","");
		Statement st1 = con.createStatement();

		 if (type.equals("Chocolates")||type.equals("Cookies")||type.equals("Biscuits")||type.equals("Candies"))
		{
		ResultSet rs1  = st1.executeQuery("SELECT * from Group1");
		while(rs1.next())
			 {
				code= rs1.getInt(1);
				item = rs1.getString(2);
				type = rs1.getString(3);
				
				
				if(code ==code)
				 {
			
					System.out.println("code = "+code);
					System.out.println("item = "+item);
					System.out.println("type = "+type);				
					
					flag =1;
				 }
			 }
			 if (flag == 0)

			 System.out.println("sorry ,record not found");
		
		  }
		else if (type.equals("Halwa")||type.equals("Dates")||type.equals("Nuts"))
		{
			
		
		ResultSet rs1  = st1.executeQuery("SELECT * from Group2");
		while(rs1.next())
			 {
				code= rs1.getInt(1);
				item = rs1.getString(2);
				type = rs1.getString(3);
				
				
				if(code ==code)
				 {
			
					System.out.println("code = "+code);
					System.out.println("item = "+item);
					System.out.println("type = "+type);
					flag =1;
				 }
			 }
			 if (flag == 0)

			 System.out.println("sorry ,record not found");
		
		  }
	   
		}
	 catch (java.lang.Exception ex)
	   {
		ex.printStackTrace();
	   }
   
   }



void Delete() throws IOException

	{
try{
	BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.print("\n\n\nEnter the Sweets Code to Delete\n\n \n");
int code=Integer.parseInt(br.readLine());
 
	
		Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
		Connection con = DriverManager.getConnection("jdbc:odbc:sa","","");

		PreparedStatement ps = con.prepareStatement("DELETE FROM Group1 WHERE Code=? ");
		ps.setInt(1, code);
		ps.execute();
		ps.close();
		System.out.println("\nThe record is deleted \n");
		}

	   catch (java.lang.Exception ex)
	   {
		ex.printStackTrace();
	   }
	}
	
		
			try 
		 {
		Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
		Connection con = DriverManager.getConnection("jdbc:odbc:sa","","");
		PreparedStatement ps = con.prepareStatement("DELETE FROM Group2 WHERE Code=? ");
		ps.setInt(1, code);
		ps.execute();
		ps.close();
		System.out.println("\nThe record is Deleted \n");
		}

	   catch (java.lang.Exception ex)
	   {
		ex.printStackTrace();
	   }
		}
   
   }
   }

 class Sweetsmenu 
{
	public static void main(String[] args)throws IOException 
	{
   int choice;
   
	Sweets_System   p=new Sweets_System ();
	
	
do
{
	BufferedReader in= new BufferedReader(new InputStreamReader(System.in));

       
		  
	
	    System.out.println("");
		System.out.println("****************************");
		System.out.println("|**    Sweets System     **|");
		System.out.println("*****************************");
	    System.out.println("|         1- Add             ");
		System.out.println("|         2- Display         ");
        System.out.println("|         3- update          ");
		System.out.println("|         4- Search          ");
		System.out.println("|         5- Remove          ");
		System.out.println("*****************************");
		System.out.println("|           6-Exit           ");
        choice=Integer.parseInt(in.readLine());
		switch(choice)
		{
		case 1:
		         System.out.println(" Add");
			
			 p.Add();
			
			
			 break;
        case 2:
		     //   LIST
			 break;
       case 3:
             	     // update
			 break;
       case 4:
		   p.Delete();
             		// DELETE
			 break;
	   case 5:
		  
			 break;
		case 6:
		     System.out.println(" Exit");
			 break;
		default:	 
			 System.out.println("Wrong choice Enter again");
			 break;
			 }
	}while(choice!=6);
}
}