|
|
| 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:
package program1;
- import javax.swing.*;
- import java.awt.*;
- /**
- * <p> Name: Janine Nicole Cosentino </p>
- * <p>Title: Programming </p>
- * <p>Description: NYC Telephone Dictionary</p>
- * <p>Copyright: Copyright (c) 2004</p>
- **/
-
- public class Main {
- public static void main(String[] args)
- {
-
- String menu;
-
- do {
-
- menu = "New York City Telephone Directory" +
- "\nEnter: \n1 to perform an Insert operation"
- + "\n2 to perform a Fetch operation" +
- "\n3 to perform a Delete operation " +
- "\n4 to perform an Update operation" +
- "\n5 Display the entire data base" +
- "\n6 Exit the Program";
-
- menu = JOptionPane.showInputDialog(null, menu,
- "NYC Telephone Dictionary",
- JOptionPane.QUESTION_MESSAGE);
-
- int guessnum = Integer.parseInt(menu);
-
- switch (guessnum) {
- case 1:
- JOptionPane.showMessageDialog(null,
- "You have chosen an Insert operation", "Insert", JOptionPane.INFORMATION_MESSAGE);
- Phonebook b = new Phonebook (10000);
- Listing L = new Listing ();
- L.getInfoName();
- L.getInfoAdd();
- L.getInfoNum();
- Phonebook b = new Phonebook (10000);
- Listing L = new Listing ();
- L.getInfoName();
- L.getInfoAdd();
- L.getInfoNum();
- String error = b.insert (L);
- if (error =true);
- System.out.println("Structure is full, Insert not done");
- break;
- case 2:
- JOptionPane.showMessageDialog(null,
- "You have chosen a Fetch operation","Fetch", JOptionPane.INFORMATION_MESSAGE);
- break;
- case 3:
- JOptionPane.showMessageDialog(null,
- "You have chosen a Delete operation", "Delete", JOptionPane.INFORMATION_MESSAGE);
- break;
- case 4:
- JOptionPane.showMessageDialog(null,"You have chosen an Update operation","Update", JOptionPane.INFORMATION_MESSAGE);
- break;
- case 5:
- JOptionPane.showMessageDialog(null,"This will display entire data base","Date Base",JOptionPane.INFORMATION_MESSAGE);
- break;
- case 6:
- System.exit(0);
- default:
- JOptionPane.showMessageDialog(null, "That's not a choice",
- "ERROR", JOptionPane.ERROR_MESSAGE);
- }
-
-
-
- }
- while (1==1);
- }
- }
here my Listing code:
Code:
package program1;
- import javax.swing.*;
-
-
- /**
- * <p>Title: </p>
- * <p>Description: </p>
- * <p>Copyright: Copyright (c) 2004</p>
- * <p>Company: </p>
- * @author not attributable
- * @version 1.0
- */
-
- public class Listing
- {
- private String name;
- private String address;
- private String number;
-
- public Listing( )
- {
-
- }
- public String getInfoName ()
- { return name;
- }
-
- public String getInfoAdd ()
- { return address;
- }
-
- public String getInfoNum ()
- {
- return number;
- }
-
- public String setInfoName (String n)
- { name = n;
- return n;
- }
-
- public String setInfoAdd (String addy)
- {address = addy;
- return addy;
- }
- public String setInfoNum ( String nam)
- { name = nam;
- return nam;
- }
-
- public void insert ( String L)
- {
-
- }
-
- public Listing(String string, String string1, String string2) {
- }
- }
and here my Phonebook code:
Code:
package program1;
-
- /**
- * <p>Title: </p>
- * <p>Description: </p>
- * <p>Copyright: Copyright (c) 2004</p>
- * <p>Company: </p>
- * @author not attributable
- * @version 1.0
- */
-
- public class Phonebook
- { private Listing []book;
-
-
- public Phonebook (int s)
- {
- book = new Listing [s];
- for (int i= 0; i <s ; i++)
- book[i] = new Listing ();
-
- }
-
- public boolean insert(String L)
- {
- if (book[] = Listing L)
- {
- return false;
- }
- else
- { return true;
-
- }
-
- }
|
|
|
| Subject: updated! · Posted: 2004-02-22, 11:44am |
|
|
|
Rank: ? (25)
Member #: 10577
|
Not executing right:
Code:
package program1;
- import javax.swing.*;
- import java.awt.*;
- /**
- * <p> Name: Janine Nicole Cosentino </p>
- * <p>Title: Programming </p>
- * <p>Description: NYC Telephone Dictionary</p>
- * <p>Copyright: Copyright (c) 2004</p>
- **/
-
- public class Main {
- public static void main(String[] args) {
- String number = "";
- String name = "";
- String address = "";
-
- String menu;
- int n,h;
- boolean error;
- Listing i;
- i = new Listing ();
- Listing f;
- f = new Listing(args);
- Phonebook d = new Phonebook (10000);
- do {
-
- menu = "New York City Telephone Directory" +
- "\nEnter: \n1 to perform an Insert operation"
- + "\n2 to perform a Fetch operation" +
- "\n3 to perform a Delete operation " +
- "\n4 to perform an Update operation" +
- "\n5 Display the entire data base" +
- "\n6 Exit the Program";
-
- menu = JOptionPane.showInputDialog(null, menu,
- "NYC Telephone Dictionary",
- JOptionPane.QUESTION_MESSAGE);
-
- int guessnum = Integer.parseInt(menu);
-
- switch (guessnum) {
- case 1:
- JOptionPane.showMessageDialog(null,
- "You have chosen an Insert operation", "Insert", JOptionPane.INFORMATION_MESSAGE);
- Phonebook b = new Phonebook (10000);
- Listing L = new Listing ();
- L.getInfoName();
- L.getInfoAdd();
- L.getInfoNum();
- L.getInfoName();
- L.getInfoAdd();
- L.getInfoNum();
- if (error = true)
- {
- System.out.println("Structure full Insert ");
- }
- else
- {
- System.out.println("Insert Pending");
- }
- break;
- case 2:
- JOptionPane.showMessageDialog(null,
- "You have chosen a Fetch operation","Fetch", JOptionPane.INFORMATION_MESSAGE);
-
- String Key = JOptionPane.showInputDialog("Please enter what you want to fetch:");
-
-
- if (d.fetch( Key))
- System.out.println("found" + Key);
- else
- System.out.println("Cant find" + Key);
-
- break;
- case 3:
- JOptionPane.showMessageDialog(null,
- "You have chosen a Delete operation", "Delete", JOptionPane.INFORMATION_MESSAGE);
-
-
-
- break;
- case 4:
- JOptionPane.showMessageDialog(null,"You have chosen an Update operation","Update", JOptionPane.INFORMATION_MESSAGE);
- break;
- case 5:
- JOptionPane.showMessageDialog(null,"This will display entire data base","Date Base",JOptionPane.INFORMATION_MESSAGE);
-
- i.setInfoAdd(address);
- i.setInfoName(name);
- i.setInfoNum(number);
- d.display();
-
- break;
- case 6:
- System.exit(0);
- default:
- JOptionPane.showMessageDialog(null, "That's not a choice",
- "ERROR", JOptionPane.ERROR_MESSAGE);
- }
-
-
-
- }
- while (1==1);
- }
- }
Code:
package program1;
- import javax.swing.*;
-
-
- /**
- * <p>Title: </p>
- * <p>Description: </p>
- * <p>Copyright: Copyright (c) 2004</p>
- * <p>Company: </p>
- * @author not attributable
- * @version 1.0
- */
-
- public class Listing
- {
- private String name;
- private String address;
- private String number;
-
- public Listing( )
- {
-
- }
- public String getInfoName ()
- { name = JOptionPane.showInputDialog("please enter name:");
- return name;
- }
-
- public String getInfoAdd ()
- {
- name = JOptionPane.showInputDialog("please enter Address:");
-
- return address;
- }
-
- public String getInfoNum ()
- {
- name = JOptionPane.showInputDialog("please enter number:");
-
- return number;
- }
-
- public String setInfoName (String n)
- { name = n;
- return n;
- }
-
- public String setInfoAdd (String addy)
- {address = addy;
- return addy;
- }
- public String setInfoNum ( String nam)
- { name = nam;
- return nam;
- }
-
- public void insert ( String L)
- {
-
- }
-
- public Listing(String string, String string1, String string2) {
- }
-
- public void delete(int i) {
- }
-
- public Listing(int i) {
- }
- public void fetch (int searchKey)
- {
- }
- public boolean fetch(Listing searchKey) {
- String Key = JOptionPane.showInputDialog("Please enter what you want to fetch:");
-
- return false;
- }
-
- public Listing(String[] strings) {
- }
-
- public void setInfoAdd() {
- }
-
- public void setInfoName(int n) {
- }
- }
Code:
package program1;
- import javax.swing.*;
- /**
- * <p>Title: </p>
- * <p>Description: </p>
- * <p>Copyright: Copyright (c) 2004</p>
- * <p>Company: </p>
- * @author not attributable
- * @version 1.0
- */
-
- public class Phonebook
- { private Listing []book;
- private int i;
-
- public Phonebook (int s)
- {
- int e;
-
-
- for ( e=0 ; e<1; e++  
- book = new Listing [s];
- for ( i= 0; i <s ; i++)
- book[i] = new Listing ();
-
- }
-
- public void insert(Listing L)
- {
- book [i] = L;
- i++;
-
- }
- public boolean delete (Listing L)
- {
- int j;
- for ( j = 0 ; j <i ; j++)
- if ( L == book[j])
- break;
- if (j==i)
- return false;
- else
- {
- for (int k=0; k<i;k++)
- book[k] =book [k+1];
- i--;
- return true;
- }
-
- }
- public boolean fetch (Listing searchKey)
- {
-
-
- int j;
- for (j=0; j<i;j++)
- if(book[j] == searchKey)
- {
- break;
- }
- if (j == i)
- {
- return false;
- }
- else
- return true;
- }
-
- public boolean fetch(int searchKey) {
- return false;
- }
-
- public void display ()
- {
- for (int j = 0; j<i; j++)
- System.out.print(book[j] + " ");
- System.out.println(" ");
- }
-
- public boolean fetch(String Key) {
- return false;
- }
- }
|