Free2Code
The majority of forums are now only available as archives, which means posting/editing is disabled.

The Anything and Everything forum is still open.
 
Time: 2013-05-18, 10:42pm
serious help!
Subject: serious help!  ·  Posted: 2004-02-21, 01:27pm
Rank: ? (25)
Member #: 10577
I dont think i ever been so lost in my life
i need to do a insert delete fetch update for data structures
here my main class
Code:
  1. package program1;
  2. import javax.swing.*;
  3. import java.awt.*;
  4. /**
  5. * <p> Name: Janine Nicole Cosentino </p>
  6. * <p>Title: Programming </p>
  7. * <p>Description: NYC Telephone Dictionary</p>
  8. * <p>Copyright: Copyright (c) 2004</p>
  9.   **/
  10. public class Main {
  11.   public static void main(String[] args)
  12.   {
  13.     String menu;
  14.     
  15.     do {
  16.    menu = "New York City Telephone Directory" +
  17.        "\nEnter: \n1 to perform an Insert operation"
  18.        + "\n2 to perform a Fetch operation" +
  19.        "\n3 to perform  a Delete operation " +
  20.        "\n4 to perform an Update operation" +
  21.        "\n5 Display the entire data base" +
  22.        "\n6 Exit the Program";
  23.    menu = JOptionPane.showInputDialog(null, menu,
  24.                                       "NYC Telephone Dictionary",
  25.                                       JOptionPane.QUESTION_MESSAGE);
  26.    int guessnum = Integer.parseInt(menu);
  27.    switch (guessnum) {
  28.      case 1:
  29.        JOptionPane.showMessageDialog(null,
  30.                                      "You have chosen an Insert operation", "Insert", JOptionPane.INFORMATION_MESSAGE);
  31.        Phonebook b = new Phonebook (10000);
  32.        Listing L = new Listing ();
  33.        L.getInfoName();
  34.        L.getInfoAdd();
  35.        L.getInfoNum();
  36.        Phonebook b = new Phonebook (10000);
  37.        Listing L = new Listing ();
  38.        L.getInfoName();
  39.        L.getInfoAdd();
  40.        L.getInfoNum();
  41.        String error = b.insert (L);
  42.        if (error =true);
  43.         System.out.println("Structure is full, Insert not done");
  44.        break;
  45.      case 2:
  46.        JOptionPane.showMessageDialog(null,
  47.                                      "You have chosen a Fetch operation","Fetch", JOptionPane.INFORMATION_MESSAGE);
  48.        break;
  49.      case 3:
  50.        JOptionPane.showMessageDialog(null,
  51.                                      "You have chosen a Delete operation", "Delete", JOptionPane.INFORMATION_MESSAGE);
  52.        break;
  53.      case 4:
  54.        JOptionPane.showMessageDialog(null,"You have chosen an Update operation","Update", JOptionPane.INFORMATION_MESSAGE);
  55.        break;
  56.      case 5:
  57.        JOptionPane.showMessageDialog(null,"This will display entire data base","Date Base",JOptionPane.INFORMATION_MESSAGE);
  58.        break;
  59.      case 6:
  60.        System.exit(0);
  61.      default:
  62.        JOptionPane.showMessageDialog(null, "That's not a choice",
  63.                                      "ERROR", JOptionPane.ERROR_MESSAGE);
  64.    }
  65. }
  66.     while (1==1);
  67.   }
  68. }



here my Listing code:
Code:
  1. package program1;
  2. import javax.swing.*;
  3. /**
  4. * <p>Title: </p>
  5. * <p>Description: </p>
  6. * <p>Copyright: Copyright (c) 2004</p>
  7. * <p>Company: </p>
  8. * @author not attributable
  9. * @version 1.0
  10. */
  11. public class Listing
  12. {
  13. private String name;
  14. private String address;
  15. private String number;
  16.   public Listing( )
  17.   {
  18.   }
  19. public String getInfoName ()
  20. { return name;
  21. }
  22. public String getInfoAdd ()
  23. { return address;
  24. }
  25. public String getInfoNum ()
  26.   {
  27.     return number;
  28.   }
  29.   public String setInfoName (String n)
  30.    { name = n;
  31.      return n;
  32.    }
  33.    public String setInfoAdd (String addy)
  34.     {address = addy;
  35.       return addy;
  36.     }
  37.     public String setInfoNum ( String nam)
  38.      { name = nam;
  39.        return nam;
  40.      }
  41.   public void insert ( String L)
  42.   {
  43.     
  44.   }
  45.   public Listing(String string, String string1, String string2) {
  46.   }
  47. }


and here my Phonebook code:

Code:
  1. package program1;
  2. /**
  3. * <p>Title: </p>
  4. * <p>Description: </p>
  5. * <p>Copyright: Copyright (c) 2004</p>
  6. * <p>Company: </p>
  7. * @author not attributable
  8. * @version 1.0
  9. */
  10. public class Phonebook
  11. { private Listing []book;
  12.   
  13. public Phonebook (int s)
  14. {  
  15.   book = new Listing [s];
  16. for (int i=  0; i <s ; i++)
  17.    book[i] = new Listing ();
  18.   }
  19.   public boolean insert(String L)
  20.   {
  21.     if (book[] = Listing L)
  22.     {
  23.       return false;
  24.     }
  25.     else
  26.     {    return true;
  27.     }
  28.   }


 
  Reply to this ·  Post link ·  Top
Subject: updated!  ·  Posted: 2004-02-22, 11:44am
Rank: ? (25)
Member #: 10577
Not executing right:



Code:
  1. package program1;
  2. import javax.swing.*;
  3. import java.awt.*;
  4. /**
  5. * <p> Name: Janine Nicole Cosentino </p>
  6. * <p>Title: Programming </p>
  7. * <p>Description: NYC Telephone Dictionary</p>
  8. * <p>Copyright: Copyright (c) 2004</p>
  9.   **/
  10. public class Main {
  11.   public static void main(String[] args) {
  12.     String number = "";
  13.     String name = "";
  14.     String address = "";
  15.     String menu;
  16.     int n,h;
  17.     boolean error;
  18.     Listing i;
  19.     i = new Listing ();
  20.     Listing f;
  21.     f = new Listing(args);
  22.     Phonebook d = new Phonebook (10000);
  23.     do {
  24.    menu = "New York City Telephone Directory" +
  25.        "\nEnter: \n1 to perform an Insert operation"
  26.        + "\n2 to perform a Fetch operation" +
  27.        "\n3 to perform  a Delete operation " +
  28.        "\n4 to perform an Update operation" +
  29.        "\n5 Display the entire data base" +
  30.        "\n6 Exit the Program";
  31.    menu = JOptionPane.showInputDialog(null, menu,
  32.                                       "NYC Telephone Dictionary",
  33.                                       JOptionPane.QUESTION_MESSAGE);
  34.    int guessnum = Integer.parseInt(menu);
  35.    switch (guessnum) {
  36.      case 1:
  37.       JOptionPane.showMessageDialog(null,
  38.                                     "You have chosen an Insert operation", "Insert", JOptionPane.INFORMATION_MESSAGE);
  39.        Phonebook b = new Phonebook (10000);
  40.        Listing L = new Listing ();
  41.        L.getInfoName();
  42.        L.getInfoAdd();
  43.        L.getInfoNum();
  44.        L.getInfoName();
  45.        L.getInfoAdd();
  46.        L.getInfoNum();
  47.        if (error = true)
  48.        {
  49.          System.out.println("Structure full Insert ");
  50.        }
  51.        else
  52.        {
  53.          System.out.println("Insert Pending");
  54.        }
  55.        break;
  56.      case 2:
  57.      JOptionPane.showMessageDialog(null,
  58.                                  "You have chosen a Fetch operation","Fetch", JOptionPane.INFORMATION_MESSAGE);
  59.    String Key = JOptionPane.showInputDialog("Please enter what you want to fetch:");
  60.       if (d.fetch( Key))
  61.         System.out.println("found" + Key);
  62.         else
  63.           System.out.println("Cant find" + Key);
  64.        break;
  65.      case 3:
  66.        JOptionPane.showMessageDialog(null,
  67.                                      "You have chosen a Delete operation", "Delete", JOptionPane.INFORMATION_MESSAGE);
  68.        break;
  69.      case 4:
  70.       JOptionPane.showMessageDialog(null,"You have chosen an Update operation","Update", JOptionPane.INFORMATION_MESSAGE);
  71.        break;
  72.      case 5:
  73.        JOptionPane.showMessageDialog(null,"This will display entire data base","Date Base",JOptionPane.INFORMATION_MESSAGE);
  74.        i.setInfoAdd(address);
  75.        i.setInfoName(name);
  76.        i.setInfoNum(number);
  77.        d.display();
  78.        break;
  79.      case 6:
  80.        System.exit(0);
  81.      default:
  82.        JOptionPane.showMessageDialog(null, "That's not a choice",
  83.                                      "ERROR", JOptionPane.ERROR_MESSAGE);
  84.    }
  85. }
  86.     while (1==1);
  87.   }
  88. }



Code:
  1. package program1;
  2. import javax.swing.*;
  3. /**
  4. * <p>Title: </p>
  5. * <p>Description: </p>
  6. * <p>Copyright: Copyright (c) 2004</p>
  7. * <p>Company: </p>
  8. * @author not attributable
  9. * @version 1.0
  10. */
  11. public class Listing
  12. {
  13. private String name;
  14. private String address;
  15. private String number;
  16.   public Listing( )
  17.   {
  18.   }
  19. public String getInfoName ()
  20. { name = JOptionPane.showInputDialog("please enter name:");
  21.    return name;
  22. }
  23. public String getInfoAdd ()
  24. {
  25.     name = JOptionPane.showInputDialog("please enter Address:");
  26.    return address;
  27. }
  28. public String getInfoNum ()
  29.   {
  30.     name = JOptionPane.showInputDialog("please enter number:");
  31.     return number;
  32.   }
  33.   public String setInfoName (String n)
  34.    { name = n;
  35.      return n;
  36.    }
  37.    public String setInfoAdd (String addy)
  38.     {address = addy;
  39.       return addy;
  40.     }
  41.     public String setInfoNum ( String nam)
  42.      { name = nam;
  43.        return nam;
  44.      }
  45.   public void insert ( String L)
  46.   {
  47.   }
  48.   public Listing(String string, String string1, String string2) {
  49.   }
  50.   public void delete(int i) {
  51.   }
  52.   public Listing(int i) {
  53.   }
  54. public void fetch (int searchKey)
  55.   {
  56.   }
  57.   public boolean fetch(Listing searchKey) {
  58.     String Key = JOptionPane.showInputDialog("Please enter what you want to fetch:");
  59.    return false;
  60.   }
  61.   public Listing(String[] strings) {
  62.   }
  63.   public void setInfoAdd() {
  64.   }
  65.   public void setInfoName(int n) {
  66.   }
  67. }



Code:
  1. package program1;
  2. import javax.swing.*;
  3. /**
  4. * <p>Title: </p>
  5. * <p>Description: </p>
  6. * <p>Copyright: Copyright (c) 2004</p>
  7. * <p>Company: </p>
  8. * @author not attributable
  9. * @version 1.0
  10. */
  11. public class Phonebook
  12. { private Listing []book;
  13. private int i;
  14. public Phonebook (int s)
  15. {
  16.    int e;
  17.    for ( e=0 ; e<1; e++  
  18.   book = new Listing [s];
  19. for ( i=  0; i <s ; i++)
  20.    book[i] = new Listing ();
  21.   }
  22.   public void insert(Listing L)
  23.   {
  24.     book [i] = L;
  25.     i++;
  26.   }
  27. public boolean delete (Listing L)
  28. {
  29.    int j;
  30.    for ( j = 0 ; j <i ; j++)
  31.     if ( L == book[j])
  32.       break;
  33.     if (j==i)
  34.       return false;
  35.     else
  36.     {
  37.       for (int k=0; k<i;k++)
  38.         book[k] =book [k+1];
  39.         i--;
  40.         return true;
  41.     }
  42. }
  43.   public boolean fetch (Listing searchKey)
  44.   {
  45.     int j;
  46.     for (j=0; j<i;j++)
  47.       if(book[j] == searchKey)
  48.       {
  49.         break;
  50.       }
  51.     if (j == i)
  52.     {
  53.       return false;
  54.     }
  55.     else
  56.       return true;
  57.   }
  58.   public boolean fetch(int searchKey) {
  59.     return false;
  60.   }
  61.   public void display ()
  62.   {
  63.     for (int j = 0; j<i; j++)
  64.      System.out.print(book[j] + " ");
  65.      System.out.println(" ");
  66.   }
  67.   public boolean fetch(String Key) {
  68.     return false;
  69.   }
  70. }


 
  Reply to this ·  Post link ·  Top

Pages: 1

Please login or register to post a reply.

Penguino AVR

Want to learn about robotics or microcontrollers?
Check out the Penguino AVR from our friends at
Icy Labs