SlideShare a Scribd company logo
How can I add multiple names and addresses? To the following code?
Tablea addressBook = new Tablea();
Scanner scanner = new Scanner(System.in);
String key, value;
// Insert a new entry into the address book
System.out.print("Enter a name: ");
key = scanner.nextLine();
System.out.print("Enter an address: ");
value = scanner.nextLine();
addressBook.insert(key, value);
// Lookup an entry in the address book
System.out.print("Enter a name to look up: ");
key = scanner.nextLine();
String result = addressBook.lookUp(key);
if (result != null) {
System.out.println("Address: " + result);
} else {
System.out.println("Name not found");
}
// Delete an entry from the address book
System.out.print("Enter a name to delete: ");
key = scanner.nextLine();
boolean deleted = addressBook.delete(key);
if (deleted) {
System.out.println("Address deleted");
} else {
System.out.println("Name not found");
}
// Update an entry in the address book
System.out.print("Enter a name to update: ");
key = scanner.nextLine();
System.out.print("Enter a new address: ");
value = scanner.nextLine();
boolean updated = addressBook.update(key, value);
if (updated) {
System.out.println("Address updated");
} else {
System.out.println("Name not found");
}
// Display all entries in the address book
System.out.println("All entries:");
addressBook.displayAll();
// Quit the program
System.out.println("Quitting...");
}
public class Node {
private String key;
private String value;
private Node next;
Node() {
// add here ..
}
Node(String key, String value) {
// add here ..
this.key = key;
this.value = value;
this.next = null;
}
public String getKey() {
// add here ..
return this.key;
}
public void setKey(String key) {
// add here ..
this.key = key;
}
public String getValue() {
// add here ..
return this.value;
}
public void setValue(String value) {
// add here ..
this.value = value;
}
public Node getNext() {
// add here ..
return this.next;
}
public void setNext(Node next) {
// add here ..
this.next = next;
}
}
import java.util.Scanner;
public class Tablea {
private Node mark;
public Node getMark() {
return this.mark;
}
public void setMark(Node mark) {
this.mark = mark;
}
public boolean insert(String key, String value) {
Node newNode= new Node(key,value);
if (this.mark== null) {
this.mark = newNode;
}else {
newNode.setNext(this.mark.getNext());
this.mark.setNext(newNode);
}
return true;
}
public String lookUp(String key) {
Node current = this.mark;
while(current!=null) {
if (current.getKey().equals(key)) {
return current.getValue();
}
current = current.getNext();
}
return null;
}
public boolean delete(String key) {
Node current = this.mark;
Node prev = null;
while (current!= null) {
if (current.getKey().equals(key)) {
if (prev == null) {
this.mark = current.getNext();
}else {
prev.setNext(current.getNext());
}
return true;
}
prev = current;
current = current.getNext();
}
return false;
}
public boolean update(String key, String newValue) {
Node current = this.mark;
while (current != null) {
if (current.getKey().equals(key)) {
current.setValue(newValue);
return true;
}
current = current.getNext();
}
return false;
}
public boolean markToStart() {
if (this.mark== null) {
return false;
}
this.mark = null;
return true;
}
public boolean advanceMark() {
if (this.mark== null) {
return false;
}
this.mark = this.mark.getNext();
return true;
}
public String keyAtMark() {
if (this.mark== null) {
return null;
}
return this.mark.getKey();
}
public String valueAtMark() {
if (this.mark== null) {
return null;
}
return this.mark.getValue();
}
public int displayAll() {
Node current = this.mark;
int count = 0;
while (current != null) {
System.out.println(current.getKey()+":"+ current);
}
return count;
}
}

More Related Content

Similar to How can I add multiple names and addresses- To the following code- Tab.pdf

mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
fathimafancyjeweller
 
can you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdfcan you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdf
sales88
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
michardsonkhaicarr37
 
Javai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdfJavai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdf
stopgolook
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
arrowmobile
 
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 Sorted number list implementation with linked listsStep 1 Inspec.pdf Sorted number list implementation with linked listsStep 1 Inspec.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdf
almaniaeyewear
 
Given the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfGiven the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdf
illyasraja7
 
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdfimport java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
shaktisinhgandhinaga
 
This is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdfThis is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdf
akaluza07
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
asarudheen07
 
6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. Streams
DEVTYPE
 
tested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdftested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdf
shanki7
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
archanaemporium
 
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfPLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
mallik3000
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
vishalateen
 
import java.util.Random;defines the Stock class public class S.pdf
import java.util.Random;defines the Stock class public class S.pdfimport java.util.Random;defines the Stock class public class S.pdf
import java.util.Random;defines the Stock class public class S.pdf
aquazac
 
1 OverviewFor this lab, you will implement the insert method and t.pdf
1 OverviewFor this lab, you will implement the insert method and t.pdf1 OverviewFor this lab, you will implement the insert method and t.pdf
1 OverviewFor this lab, you will implement the insert method and t.pdf
rajeshjain2109
 
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfJAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
calderoncasto9163
 
I have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdfI have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdf
allystraders
 
For this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docxFor this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docx
mckellarhastings
 

Similar to How can I add multiple names and addresses- To the following code- Tab.pdf (20)

mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
 
can you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdfcan you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdf
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
Javai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdfJavai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdf
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
 
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 Sorted number list implementation with linked listsStep 1 Inspec.pdf Sorted number list implementation with linked listsStep 1 Inspec.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 
Given the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfGiven the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdf
 
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdfimport java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
 
This is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdfThis is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdf
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
 
6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. Streams
 
tested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdftested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdf
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
 
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfPLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
 
import java.util.Random;defines the Stock class public class S.pdf
import java.util.Random;defines the Stock class public class S.pdfimport java.util.Random;defines the Stock class public class S.pdf
import java.util.Random;defines the Stock class public class S.pdf
 
1 OverviewFor this lab, you will implement the insert method and t.pdf
1 OverviewFor this lab, you will implement the insert method and t.pdf1 OverviewFor this lab, you will implement the insert method and t.pdf
1 OverviewFor this lab, you will implement the insert method and t.pdf
 
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfJAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
 
I have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdfI have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdf
 
For this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docxFor this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docx
 

More from ThomasXUMParsonsx

How would you define a community- The beginning of government's major.pdf
How would you define a community- The beginning of government's major.pdfHow would you define a community- The beginning of government's major.pdf
How would you define a community- The beginning of government's major.pdf
ThomasXUMParsonsx
 
How would you transform an organisation into a learning organisation u.pdf
How would you transform an organisation into a learning organisation u.pdfHow would you transform an organisation into a learning organisation u.pdf
How would you transform an organisation into a learning organisation u.pdf
ThomasXUMParsonsx
 
How to fixed these provide listsort-asm assembly code as same as the l.pdf
How to fixed these provide listsort-asm assembly code as same as the l.pdfHow to fixed these provide listsort-asm assembly code as same as the l.pdf
How to fixed these provide listsort-asm assembly code as same as the l.pdf
ThomasXUMParsonsx
 
How to measure effectiveness using 1- The goal approach2- The human-ba.pdf
How to measure effectiveness using 1- The goal approach2- The human-ba.pdfHow to measure effectiveness using 1- The goal approach2- The human-ba.pdf
How to measure effectiveness using 1- The goal approach2- The human-ba.pdf
ThomasXUMParsonsx
 
How should a company evaluate a society's level of interdependence exp.pdf
How should a company evaluate a society's level of interdependence exp.pdfHow should a company evaluate a society's level of interdependence exp.pdf
How should a company evaluate a society's level of interdependence exp.pdf
ThomasXUMParsonsx
 
How much would the force of gravity at the surface of the Earth differ.pdf
How much would the force of gravity at the surface of the Earth differ.pdfHow much would the force of gravity at the surface of the Earth differ.pdf
How much would the force of gravity at the surface of the Earth differ.pdf
ThomasXUMParsonsx
 
How is the human population changing globally- What general difference.pdf
How is the human population changing globally- What general difference.pdfHow is the human population changing globally- What general difference.pdf
How is the human population changing globally- What general difference.pdf
ThomasXUMParsonsx
 
How many different groups of two students can be formed out of 4 stud.pdf
How many different groups of two students can be formed out  of 4 stud.pdfHow many different groups of two students can be formed out  of 4 stud.pdf
How many different groups of two students can be formed out of 4 stud.pdf
ThomasXUMParsonsx
 
How might environment might influence the total phenotypic variance in.pdf
How might environment might influence the total phenotypic variance in.pdfHow might environment might influence the total phenotypic variance in.pdf
How might environment might influence the total phenotypic variance in.pdf
ThomasXUMParsonsx
 
How long will it take $100 to grow to $400 if invested at 4-5- compoun.pdf
How long will it take $100 to grow to $400 if invested at 4-5- compoun.pdfHow long will it take $100 to grow to $400 if invested at 4-5- compoun.pdf
How long will it take $100 to grow to $400 if invested at 4-5- compoun.pdf
ThomasXUMParsonsx
 
How many samples should we collect for the following scenario- We want.pdf
How many samples should we collect for the following scenario- We want.pdfHow many samples should we collect for the following scenario- We want.pdf
How many samples should we collect for the following scenario- We want.pdf
ThomasXUMParsonsx
 
How is of_type modeled- Not modeled into any relationship Relation and.pdf
How is of_type modeled- Not modeled into any relationship Relation and.pdfHow is of_type modeled- Not modeled into any relationship Relation and.pdf
How is of_type modeled- Not modeled into any relationship Relation and.pdf
ThomasXUMParsonsx
 
How is Plane_service modeled- Relation and foreign key with single att.pdf
How is Plane_service modeled- Relation and foreign key with single att.pdfHow is Plane_service modeled- Relation and foreign key with single att.pdf
How is Plane_service modeled- Relation and foreign key with single att.pdf
ThomasXUMParsonsx
 
How has the Internet created a new marketing model- What are the main.pdf
How has the Internet created a new marketing model- What are the main.pdfHow has the Internet created a new marketing model- What are the main.pdf
How has the Internet created a new marketing model- What are the main.pdf
ThomasXUMParsonsx
 
How have human diseases changed from pre-1950 to the present- and how.pdf
How have human diseases changed from pre-1950 to the present- and how.pdfHow have human diseases changed from pre-1950 to the present- and how.pdf
How have human diseases changed from pre-1950 to the present- and how.pdf
ThomasXUMParsonsx
 
How frequently are incidents of violence and-or corruption in policing.pdf
How frequently are incidents of violence and-or corruption in policing.pdfHow frequently are incidents of violence and-or corruption in policing.pdf
How frequently are incidents of violence and-or corruption in policing.pdf
ThomasXUMParsonsx
 
How does myosin II differ from myosin V- Myosin II assembles into bipo.pdf
How does myosin II differ from myosin V- Myosin II assembles into bipo.pdfHow does myosin II differ from myosin V- Myosin II assembles into bipo.pdf
How does myosin II differ from myosin V- Myosin II assembles into bipo.pdf
ThomasXUMParsonsx
 
How does Fogel justify using only one year of data in his social savin.pdf
How does Fogel justify using only one year of data in his social savin.pdfHow does Fogel justify using only one year of data in his social savin.pdf
How does Fogel justify using only one year of data in his social savin.pdf
ThomasXUMParsonsx
 
How Effective Managers Use Information Systems Advances in computer-ba.pdf
How Effective Managers Use Information Systems Advances in computer-ba.pdfHow Effective Managers Use Information Systems Advances in computer-ba.pdf
How Effective Managers Use Information Systems Advances in computer-ba.pdf
ThomasXUMParsonsx
 
How does bias affect human resource function How does bias affect huma.pdf
How does bias affect human resource function How does bias affect huma.pdfHow does bias affect human resource function How does bias affect huma.pdf
How does bias affect human resource function How does bias affect huma.pdf
ThomasXUMParsonsx
 

More from ThomasXUMParsonsx (20)

How would you define a community- The beginning of government's major.pdf
How would you define a community- The beginning of government's major.pdfHow would you define a community- The beginning of government's major.pdf
How would you define a community- The beginning of government's major.pdf
 
How would you transform an organisation into a learning organisation u.pdf
How would you transform an organisation into a learning organisation u.pdfHow would you transform an organisation into a learning organisation u.pdf
How would you transform an organisation into a learning organisation u.pdf
 
How to fixed these provide listsort-asm assembly code as same as the l.pdf
How to fixed these provide listsort-asm assembly code as same as the l.pdfHow to fixed these provide listsort-asm assembly code as same as the l.pdf
How to fixed these provide listsort-asm assembly code as same as the l.pdf
 
How to measure effectiveness using 1- The goal approach2- The human-ba.pdf
How to measure effectiveness using 1- The goal approach2- The human-ba.pdfHow to measure effectiveness using 1- The goal approach2- The human-ba.pdf
How to measure effectiveness using 1- The goal approach2- The human-ba.pdf
 
How should a company evaluate a society's level of interdependence exp.pdf
How should a company evaluate a society's level of interdependence exp.pdfHow should a company evaluate a society's level of interdependence exp.pdf
How should a company evaluate a society's level of interdependence exp.pdf
 
How much would the force of gravity at the surface of the Earth differ.pdf
How much would the force of gravity at the surface of the Earth differ.pdfHow much would the force of gravity at the surface of the Earth differ.pdf
How much would the force of gravity at the surface of the Earth differ.pdf
 
How is the human population changing globally- What general difference.pdf
How is the human population changing globally- What general difference.pdfHow is the human population changing globally- What general difference.pdf
How is the human population changing globally- What general difference.pdf
 
How many different groups of two students can be formed out of 4 stud.pdf
How many different groups of two students can be formed out  of 4 stud.pdfHow many different groups of two students can be formed out  of 4 stud.pdf
How many different groups of two students can be formed out of 4 stud.pdf
 
How might environment might influence the total phenotypic variance in.pdf
How might environment might influence the total phenotypic variance in.pdfHow might environment might influence the total phenotypic variance in.pdf
How might environment might influence the total phenotypic variance in.pdf
 
How long will it take $100 to grow to $400 if invested at 4-5- compoun.pdf
How long will it take $100 to grow to $400 if invested at 4-5- compoun.pdfHow long will it take $100 to grow to $400 if invested at 4-5- compoun.pdf
How long will it take $100 to grow to $400 if invested at 4-5- compoun.pdf
 
How many samples should we collect for the following scenario- We want.pdf
How many samples should we collect for the following scenario- We want.pdfHow many samples should we collect for the following scenario- We want.pdf
How many samples should we collect for the following scenario- We want.pdf
 
How is of_type modeled- Not modeled into any relationship Relation and.pdf
How is of_type modeled- Not modeled into any relationship Relation and.pdfHow is of_type modeled- Not modeled into any relationship Relation and.pdf
How is of_type modeled- Not modeled into any relationship Relation and.pdf
 
How is Plane_service modeled- Relation and foreign key with single att.pdf
How is Plane_service modeled- Relation and foreign key with single att.pdfHow is Plane_service modeled- Relation and foreign key with single att.pdf
How is Plane_service modeled- Relation and foreign key with single att.pdf
 
How has the Internet created a new marketing model- What are the main.pdf
How has the Internet created a new marketing model- What are the main.pdfHow has the Internet created a new marketing model- What are the main.pdf
How has the Internet created a new marketing model- What are the main.pdf
 
How have human diseases changed from pre-1950 to the present- and how.pdf
How have human diseases changed from pre-1950 to the present- and how.pdfHow have human diseases changed from pre-1950 to the present- and how.pdf
How have human diseases changed from pre-1950 to the present- and how.pdf
 
How frequently are incidents of violence and-or corruption in policing.pdf
How frequently are incidents of violence and-or corruption in policing.pdfHow frequently are incidents of violence and-or corruption in policing.pdf
How frequently are incidents of violence and-or corruption in policing.pdf
 
How does myosin II differ from myosin V- Myosin II assembles into bipo.pdf
How does myosin II differ from myosin V- Myosin II assembles into bipo.pdfHow does myosin II differ from myosin V- Myosin II assembles into bipo.pdf
How does myosin II differ from myosin V- Myosin II assembles into bipo.pdf
 
How does Fogel justify using only one year of data in his social savin.pdf
How does Fogel justify using only one year of data in his social savin.pdfHow does Fogel justify using only one year of data in his social savin.pdf
How does Fogel justify using only one year of data in his social savin.pdf
 
How Effective Managers Use Information Systems Advances in computer-ba.pdf
How Effective Managers Use Information Systems Advances in computer-ba.pdfHow Effective Managers Use Information Systems Advances in computer-ba.pdf
How Effective Managers Use Information Systems Advances in computer-ba.pdf
 
How does bias affect human resource function How does bias affect huma.pdf
How does bias affect human resource function How does bias affect huma.pdfHow does bias affect human resource function How does bias affect huma.pdf
How does bias affect human resource function How does bias affect huma.pdf
 

Recently uploaded

PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
ArianaBusciglio
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 

Recently uploaded (20)

PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 

How can I add multiple names and addresses- To the following code- Tab.pdf

  • 1. How can I add multiple names and addresses? To the following code? Tablea addressBook = new Tablea(); Scanner scanner = new Scanner(System.in); String key, value; // Insert a new entry into the address book System.out.print("Enter a name: "); key = scanner.nextLine(); System.out.print("Enter an address: "); value = scanner.nextLine(); addressBook.insert(key, value); // Lookup an entry in the address book System.out.print("Enter a name to look up: "); key = scanner.nextLine(); String result = addressBook.lookUp(key); if (result != null) { System.out.println("Address: " + result); } else { System.out.println("Name not found"); } // Delete an entry from the address book System.out.print("Enter a name to delete: "); key = scanner.nextLine(); boolean deleted = addressBook.delete(key);
  • 2. if (deleted) { System.out.println("Address deleted"); } else { System.out.println("Name not found"); } // Update an entry in the address book System.out.print("Enter a name to update: "); key = scanner.nextLine(); System.out.print("Enter a new address: "); value = scanner.nextLine(); boolean updated = addressBook.update(key, value); if (updated) { System.out.println("Address updated"); } else { System.out.println("Name not found"); } // Display all entries in the address book System.out.println("All entries:"); addressBook.displayAll(); // Quit the program System.out.println("Quitting..."); } public class Node { private String key;
  • 3. private String value; private Node next; Node() { // add here .. } Node(String key, String value) { // add here .. this.key = key; this.value = value; this.next = null; } public String getKey() { // add here .. return this.key; } public void setKey(String key) { // add here .. this.key = key; } public String getValue() { // add here .. return this.value; } public void setValue(String value) { // add here .. this.value = value; } public Node getNext() { // add here .. return this.next; } public void setNext(Node next) { // add here .. this.next = next; } }
  • 4. import java.util.Scanner; public class Tablea { private Node mark; public Node getMark() { return this.mark; } public void setMark(Node mark) { this.mark = mark; } public boolean insert(String key, String value) { Node newNode= new Node(key,value); if (this.mark== null) { this.mark = newNode; }else { newNode.setNext(this.mark.getNext()); this.mark.setNext(newNode); } return true; } public String lookUp(String key) { Node current = this.mark; while(current!=null) { if (current.getKey().equals(key)) { return current.getValue(); } current = current.getNext(); } return null; } public boolean delete(String key) { Node current = this.mark; Node prev = null; while (current!= null) { if (current.getKey().equals(key)) { if (prev == null) { this.mark = current.getNext(); }else { prev.setNext(current.getNext()); }
  • 5. return true; } prev = current; current = current.getNext(); } return false; } public boolean update(String key, String newValue) { Node current = this.mark; while (current != null) { if (current.getKey().equals(key)) { current.setValue(newValue); return true; } current = current.getNext(); } return false; } public boolean markToStart() { if (this.mark== null) { return false; } this.mark = null; return true; } public boolean advanceMark() { if (this.mark== null) { return false; } this.mark = this.mark.getNext(); return true; } public String keyAtMark() { if (this.mark== null) { return null; } return this.mark.getKey(); }
  • 6. public String valueAtMark() { if (this.mark== null) { return null; } return this.mark.getValue(); } public int displayAll() { Node current = this.mark; int count = 0; while (current != null) { System.out.println(current.getKey()+":"+ current); } return count; } }