1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

caN someone help me with this

Discussion in 'Java' started by botong, Apr 9, 2008.

  1. botong

    botong New Member

    Joined:
    Apr 9, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    i cant store information can someone help me modify this program
    Code:
    import java.io.*;
    public class Mprogram
    {
           static   MetalNode curr,curr2,curr3,
     prev,newNode,list,list2,list3;
           static   BufferedReader br;
           static   int choice,choice1,choice2,choice3;
    	   static   String weight,price,color,name,select,search;
    
    		//brand name
    		static void displayName()
    		{
    			System.out.println("Brand Name : "+name);
    		}
           //weight number
           static void displayList ( MetalNode list )
           {
                for ( MetalNode curr = list; curr != null; curr =
     curr.getNext())
                {
    				System.out.println("Weight Number : "+ curr.getItem() + " -> ");
    			}
           }
    
           //price
           static void displayList2 (MetalNode list2)
           {
    		   for ( MetalNode curr2 = list2; curr2 != null; curr2 =
     curr2.getNext())
    		   {
    		   	 System.out.println("Price : "+ curr2.getItem2() + " -> ");
    	   	   }
    	   }
    
           //color
    	   static void displayList3 (MetalNode list3)
    	   {
    	   	   for ( MetalNode curr3 = list3; curr3 != null; curr3 =
     curr3.getNext())
    		   {
    		     System.out.println("Color : "+ curr3.getItem3() + " -> ");
               }
    	   }
    
    
           //add item
           static void addItem () throws IOException
           {
               br = new BufferedReader( new InputStreamReader( System.in));
    
    			//Brand name
    			System.out.print("Brand Name : " );
    			name = br.readLine();
    
                 //list
                 System.out.print("Weight Number : " );
                 weight = br.readLine();
                 choice = Integer.parseInt(weight);
                 newNode = new MetalNode(choice);
    
                 prev = null;
                 curr = list;
                 while ( curr != null && choice > curr.getItem())
                 {
    				 prev = curr;
                     curr = curr.getNext();
    			 }
    			 if ( prev == null )
    			 {
    				 newNode.setNext(list);
                     list = newNode;
                 }
    	         if ( prev != null && list != null )
    	         {
                     newNode.setNext(curr);
    	             prev.setNext(newNode);
                 }
    
                 //list2
                 System.out.print("Price : " );
    			 price = br.readLine();
    			 choice1 = Integer.parseInt(price);
                 newNode = new MetalNode(choice1);
    			 prev = null;
                 curr2 = list2;
    		     while ( curr2 != null && choice1 > curr2.getItem2())
    			 {
    				 prev = curr2;
                     curr2 = curr2.getNext();
    			 }
    			  if ( prev == null )
    			   {
    			 	  newNode.setNext(list2);
    			 	  list2 = newNode;
    			   }
    
    			   if ( prev != null && list2 != null )
    			   {
          		       newNode.setNext(curr2);
    			       prev.setNext(newNode);
                   }
    
                 //list3
                 System.out.print("Color : " );
    			 color = br.readLine();
    			 choice2 = Integer.parseInt(color);
                 newNode = new MetalNode(choice2);
    			 prev = null;
                 curr3 = list3;
    			 while ( curr != null && choice2 > curr3.getItem3())
    			 {
                      prev = curr3;
                      curr3 = curr3.getNext();
                 }
                   if ( prev == null )
    			   {
    			       newNode.setNext(list3);
    			       list3 = newNode;
    			   }
    
    			   if ( prev != null && list3 != null )
    			   {
    			      newNode.setNext(curr3);
    			      prev.setNext(newNode);
                   }
                   System.out.println("");
                   displayName();
                   displayList(list);
                   displayList2(list2);
                   displayList3(list3);
            }
    
    //delete item
        static void deleteItem() throws IOException
        {
             br = new BufferedReader ( new InputStreamReader( System.in));
             System.out.print("Remove Price : " );
             price = br.readLine();
             choice = Integer.parseInt(price);
    
             prev = null;
             curr2 = list2;
             while ( curr2 != null && choice != curr2.getItem())
             {
                         prev = curr2;
                         curr2 = curr2.getNext();
             }
    
             if ( prev == null )
             {
                  list2 = list2.getNext();
             }
    
             if (prev != null && list2 != null )
             {
                  prev.setNext(curr.getNext());
             }
             displayList(list2);
             System.out.println("Price Deleted!");
         }
    
     //viewing
     	static void view()
     	{
    		displayName();
    		displayList(list);
    		displayList2(list2);
            displayList3(list3);
    	}
    
    //searching
    	static void search() throws IOException
    	{
    		br = new BufferedReader (new InputStreamReader (System.in));
    
    	  	System.out.print("Search Item : ");
    	  	search = br.readLine();
    
    	  	if(search == name)
    	  	{
    			displayName();
    		    displayList(list);
    			displayList2(list2);
                displayList3(list3);
            }
            else
             System.out.println("Item Found!");
    	}
    	 //main program
    	 public static void main (String[] args)throws Exception
    	 {
    	  list = null;
    	          do
    	          {
    	              br = new BufferedReader ( new InputStreamReader(
    	 System.in));
    
    
    				  System.out.println("                      |              |");
    				  System.out.println("                      |    Metalshop |");
    				  System.out.println("                      |              |");
    
    	              System.out.println("                         Selection");
    	              System.out.println("                        1 - Add Item");
    	              System.out.println("                        2 - Delete Item");
    	              System.out.println("                        3 - View Item" );
    	              System.out.println("                        4 - Search Item" );
    	              System.out.println("                        5 - Exit" );
    	              System.out.print("                      Enter Your Choice ");
    	              select = br.readLine();
    	              choice = Integer.parseInt(select);
    
    	              switch (choice)
    	              {
    	                  case 1 : addItem();
    	                   break;
    	                  case 2 : deleteItem();
    	                   break;
    	                  case 3 : view();
    	                   break;
    	                  case 4 : search();
    	                   break;
    	                  case 5 : System.out.println(" ~~~~~~~ Program Terminated! ~~~~~~~");
    	                   break;
    	                  default : System.out.println("Invalid Input");
    	                   break;
    	              }
    	          } while (choice!=5);
    	   System.exit(0);
    	  }
    }
    
    public class MetalNode
    {
    		 private int color,weight_number,price;
    		 private MetalNode next;
    
    		public MetalNode ( int newItem )
    		{
    			color = newItem;
    			weight_number = newItem;
    			price = newItem;
    			next = null;
    		}
    
    
    		public void setItem ( int newItem )
    		{
    			color = newItem;
    			weight_number = newItem;
    			price = newItem;
    		}
    
    		public int getItem ()
    		{
    		 	return color;
    		}
    
    		public int getItem2 ()
    		{
    			return weight_number;
    	    }
    
    	    public int getItem3 ()
    	    {
    			return price;
    		}
    
    
    public void setNext ( MetalNode nextNode )
        {
    		next = nextNode;
    	}
    
    	public MetalNode getNext()
    	{
    		return next;
    	}
    }
     
    Last edited by a moderator: Apr 9, 2008

Share This Page