Current location: Hot Scripts Forums » Programming Languages » Everything Java » need help plss


need help plss

Reply
  #1 (permalink)  
Old 04-08-08, 09:04 PM
botong botong is offline
New Member
 
Join Date: Apr 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Talking need help plss

can you modify the adding information part

java Code:
  1. import java.io.*;
  2. public class Mprogram
  3. {
  4.        static   MetalNode curr,curr2,curr3,
  5.  prev,newNode,list,list2,list3;
  6.        static   BufferedReader br;
  7.        static   int choice,choice1,choice2,choice3;
  8.        static   String weight,price,color,name,select,search;
  9.  
  10.         //brand name
  11.         static void displayName()
  12.         {
  13.             System.out.println("Brand Name : "+name);
  14.         }
  15.        //weight number
  16.        static void displayList ( MetalNode list )
  17.        {
  18.             for ( MetalNode curr = list; curr != null; curr =
  19.  curr.getNext())
  20.             {
  21.                 System.out.println("Weight Number : "+ curr.getItem() + " -> ");
  22.             }
  23.        }
  24.  
  25.        //price
  26.        static void displayList2 (MetalNode list2)
  27.        {
  28.            for ( MetalNode curr2 = list2; curr2 != null; curr2 =
  29.  curr2.getNext())
  30.            {
  31.              System.out.println("Price : "+ curr2.getItem2() + " -> ");
  32.            }
  33.        }
  34.  
  35.        //color
  36.        static void displayList3 (MetalNode list3)
  37.        {
  38.            for ( MetalNode curr3 = list3; curr3 != null; curr3 =
  39.  curr3.getNext())
  40.            {
  41.              System.out.println("Color : "+ curr3.getItem3() + " -> ");
  42.            }
  43.        }
  44.  
  45.  
  46.        //add item
  47.        static void addItem () throws IOException
  48.        {
  49.            br = new BufferedReader( new InputStreamReader( System.in));
  50.  
  51.             //Brand name
  52.             System.out.print("Brand Name : " );
  53.             name = br.readLine();
  54.  
  55.              //list
  56.              System.out.print("Weight Number : " );
  57.              weight = br.readLine();
  58.              choice = Integer.parseInt(weight);
  59.              newNode = new MetalNode(choice);
  60.  
  61.              prev = null;
  62.              curr = list;
  63.              while ( curr != null && choice > curr.getItem())
  64.              {
  65.                  prev = curr;
  66.                  curr = curr.getNext();
  67.              }
  68.              if ( prev == null )
  69.              {
  70.                  newNode.setNext(list);
  71.                  list = newNode;
  72.              }
  73.              if ( prev != null && list != null )
  74.              {
  75.                  newNode.setNext(curr);
  76.                  prev.setNext(newNode);
  77.              }
  78.  
  79.              //list2
  80.              System.out.print("Price : " );
  81.              price = br.readLine();
  82.              choice1 = Integer.parseInt(price);
  83.              newNode = new MetalNode(choice1);
  84.              prev = null;
  85.              curr2 = list2;
  86.              while ( curr2 != null && choice1 > curr2.getItem2())
  87.              {
  88.                  prev = curr2;
  89.                  curr2 = curr2.getNext();
  90.              }
  91.               if ( prev == null )
  92.                {
  93.                   newNode.setNext(list2);
  94.                   list2 = newNode;
  95.                }
  96.  
  97.                if ( prev != null && list2 != null )
  98.                {
  99.                  newNode.setNext(curr2);
  100.                    prev.setNext(newNode);
  101.                }
  102.  
  103.              //list3
  104.              System.out.print("Color : " );
  105.              color = br.readLine();
  106.              choice2 = Integer.parseInt(color);
  107.              newNode = new MetalNode(choice2);
  108.              prev = null;
  109.              curr3 = list3;
  110.              while ( curr != null && choice2 > curr3.getItem3())
  111.              {
  112.                   prev = curr3;
  113.                   curr3 = curr3.getNext();
  114.              }
  115.                if ( prev == null )
  116.                {
  117.                    newNode.setNext(list3);
  118.                    list3 = newNode;
  119.                }
  120.  
  121.                if ( prev != null && list3 != null )
  122.                {
  123.                   newNode.setNext(curr3);
  124.                   prev.setNext(newNode);
  125.                }
  126.                System.out.println("");
  127.                displayName();
  128.                displayList(list);
  129.                displayList2(list2);
  130.                displayList3(list3);
  131.         }
  132.  
  133. //delete item
  134.     static void deleteItem() throws IOException
  135.     {
  136.          br = new BufferedReader ( new InputStreamReader( System.in));
  137.          System.out.print("Remove Price : " );
  138.          price = br.readLine();
  139.          choice = Integer.parseInt(price);
  140.  
  141.          prev = null;
  142.          curr2 = list2;
  143.          while ( curr2 != null && choice != curr2.getItem())
  144.          {
  145.                      prev = curr2;
  146.                      curr2 = curr2.getNext();
  147.          }
  148.  
  149.          if ( prev == null )
  150.          {
  151.               list2 = list2.getNext();
  152.          }
  153.  
  154.          if (prev != null && list2 != null )
  155.          {
  156.               prev.setNext(curr.getNext());
  157.          }
  158.          displayList(list2);
  159.          System.out.println("Price Deleted!");
  160.      }
  161.  
  162.  //viewing
  163.     static void view()
  164.     {
  165.         displayName();
  166.         displayList(list);
  167.         displayList2(list2);
  168.         displayList3(list3);
  169.     }
  170.  
  171. //searching
  172.     static void search() throws IOException
  173.     {
  174.         br = new BufferedReader (new InputStreamReader (System.in));
  175.  
  176.         System.out.print("Search Item : ");
  177.         search = br.readLine();
  178.  
  179.         if(search == name)
  180.         {
  181.             displayName();
  182.             displayList(list);
  183.             displayList2(list2);
  184.             displayList3(list3);
  185.         }
  186.         else
  187.          System.out.println("Item Found!");
  188.     }
  189.      //main program
  190.      public static void main (String[] args)throws Exception
  191.      {
  192.       list = null;
  193.               do
  194.               {
  195.                   br = new BufferedReader ( new InputStreamReader(
  196.      System.in));
  197.  
  198.  
  199.                   System.out.println("                      |              |");
  200.                   System.out.println("                      |    Metalshop |");
  201.                   System.out.println("                      |              |");
  202.  
  203.                   System.out.println("                         Selection");
  204.                   System.out.println("                        1 - Add Item");
  205.                   System.out.println("                        2 - Delete Item");
  206.                   System.out.println("                        3 - View Item" );
  207.                   System.out.println("                        4 - Search Item" );
  208.                   System.out.println("                        5 - Exit" );
  209.                   System.out.print("                      Enter Your Choice ");
  210.                   select = br.readLine();
  211.                   choice = Integer.parseInt(select);
  212.  
  213.                   switch (choice)
  214.                   {
  215.                       case 1 : addItem();
  216.                        break;
  217.                       case 2 : deleteItem();
  218.                        break;
  219.                       case 3 : view();
  220.                        break;
  221.                       case 4 : search();
  222.                        break;
  223.                       case 5 : System.out.println(" ~~~~~~~ Program Terminated! ~~~~~~~");
  224.                        break;
  225.                       default : System.out.println("Invalid Input");
  226.                        break;
  227.                   }
  228.               } while (choice!=5);
  229.        System.exit(0);
  230.       }
  231. }
  232.  
  233.  
  234. public class MetalNode
  235. {
  236.          private int color,weight_number,price;
  237.          private MetalNode next;
  238.  
  239.         public MetalNode ( int newItem )
  240.         {
  241.             color = newItem;
  242.             weight_number = newItem;
  243.             price = newItem;
  244.             next = null;
  245.         }
  246.  
  247.  
  248.         public void setItem ( int newItem )
  249.         {
  250.             color = newItem;
  251.             weight_number = newItem;
  252.             price = newItem;
  253.         }
  254.  
  255.         public int getItem ()
  256.         {
  257.             return color;
  258.         }
  259.  
  260.         public int getItem2 ()
  261.         {
  262.             return weight_number;
  263.         }
  264.  
  265.         public int getItem3 ()
  266.         {
  267.             return price;
  268.         }
  269.  
  270.  
  271. public void setNext ( MetalNode nextNode )
  272.     {
  273.         next = nextNode;
  274.     }
  275.  
  276.     public MetalNode getNext()
  277.     {
  278.         return next;
  279.     }
  280. }

Last edited by Nico; 04-09-08 at 02:12 AM. Reason: [highlight=java] wrappers.
Reply With Quote
  #2 (permalink)  
Old 04-09-08, 02:13 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
I think you're gonna have to be a lot more specific than that...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 05:44 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.