SlideShare a Scribd company logo
How do you update an address according to this code?
Currently, I figured out up to (the bolded line) How do I update address, display all entries and
quit.
Add a name (n)
Look up a name (l)
Update address (u)
Delete an entry (d)
Display all entries (a)
Quit (q)
-> n
import java.util.Scanner;
public class AddressBook {
public static void main(String[] args) {
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 a 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");
}
}
}
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

PDF
How can I add multiple names and addresses- To the following code- Tab.pdf
PDF
There is something wrong with my program-- (once I do a for view all t.pdf
PDF
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
PDF
How to fix this error- Exception in thread -main- q- Exit java-lang-.pdf
PDF
why will it not display all of the entries-- output -nMenu n-Add Entr.pdf
PDF
could you implement this function please, im having issues with it..pdf
PDF
Note             Given Code modified as required and required met.pdf
PDF
package singlylinkedlist; public class Node { public String valu.pdf
How can I add multiple names and addresses- To the following code- Tab.pdf
There is something wrong with my program-- (once I do a for view all t.pdf
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
How to fix this error- Exception in thread -main- q- Exit java-lang-.pdf
why will it not display all of the entries-- output -nMenu n-Add Entr.pdf
could you implement this function please, im having issues with it..pdf
Note             Given Code modified as required and required met.pdf
package singlylinkedlist; public class Node { public String valu.pdf

Similar to How do you update an address according to this code- Currently- I fig.pdf (20)

PDF
can you add a delete button and a add button to the below program. j.pdf
PDF
Create a new java class called ListNode. Implement ListNode as a gen.pdf
PDF
This is to test a balanced tree. I need help testing an unbalanced t.pdf
PDF
import java-util--- public class MyLinkedList{ public static void.pdf
PDF
java question Fill the add statement areaProject is to wo.pdf
PDF
import java.util.Random;defines the Stock class public class S.pdf
PDF
in this assignment you are asked to write a simple driver program an.pdf
PDF
Hi, Please find my code.I have correted all of your classes.Plea.pdf
PDF
Please implement in Java. comments would be appreciated 5.pdf
PDF
public class CircularDoublyLinkedList-E- implements List-E- { privat.pdf
PDF
Sorted number list implementation with linked listsStep 1 Inspec.pdf
PDF
TutorialII_Updated____niceupdateprogram.pdf
PDF
6. Generics. Collections. Streams
PDF
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
PDF
1 OverviewFor this lab, you will implement the insert method and t.pdf
PDF
Java code to find the closest pair using divide and conquer algorith.pdf
PDF
mainpublic class AssignmentThree {    public static void ma.pdf
PDF
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
PDF
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
PDF
So I have this code(StackInAllSocks) and I implemented the method but.pdf
can you add a delete button and a add button to the below program. j.pdf
Create a new java class called ListNode. Implement ListNode as a gen.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
java question Fill the add statement areaProject is to wo.pdf
import java.util.Random;defines the Stock class public class S.pdf
in this assignment you are asked to write a simple driver program an.pdf
Hi, Please find my code.I have correted all of your classes.Plea.pdf
Please implement in Java. comments would be appreciated 5.pdf
public class CircularDoublyLinkedList-E- implements List-E- { privat.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdf
TutorialII_Updated____niceupdateprogram.pdf
6. Generics. Collections. Streams
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
1 OverviewFor this lab, you will implement the insert method and t.pdf
Java code to find the closest pair using divide and conquer algorith.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
Ad

More from ThomasXUMParsonsx (20)

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

Recently uploaded (20)

PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Presentation on HIE in infants and its manifestations
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Institutional Correction lecture only . . .
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Cell Types and Its function , kingdom of life
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Lesson notes of climatology university.
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
102 student loan defaulters named and shamed – Is someone you know on the list?
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
O5-L3 Freight Transport Ops (International) V1.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Anesthesia in Laparoscopic Surgery in India
Microbial disease of the cardiovascular and lymphatic systems
A systematic review of self-coping strategies used by university students to ...
Presentation on HIE in infants and its manifestations
VCE English Exam - Section C Student Revision Booklet
Institutional Correction lecture only . . .
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
STATICS OF THE RIGID BODIES Hibbelers.pdf
Microbial diseases, their pathogenesis and prophylaxis
Cell Types and Its function , kingdom of life
202450812 BayCHI UCSC-SV 20250812 v17.pptx
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Lesson notes of climatology university.
Abdominal Access Techniques with Prof. Dr. R K Mishra

How do you update an address according to this code- Currently- I fig.pdf

  • 1. How do you update an address according to this code? Currently, I figured out up to (the bolded line) How do I update address, display all entries and quit. Add a name (n) Look up a name (l) Update address (u) Delete an entry (d) Display all entries (a) Quit (q) -> n import java.util.Scanner; public class AddressBook { public static void main(String[] args) { 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 a 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();
  • 2. 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"); } } } public class Node { private String key; private String value; private Node next; Node() { // add here ..
  • 3. } 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; }
  • 4. 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 {
  • 5. 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 {
  • 6. 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;
  • 7. } 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(); }
  • 8. public int displayAll() { Node current = this.mark; int count = 0; while (current != null) { System. out .println(current.getKey()+":"+ current); } return count; } }