ont Maps Maps are similar to collections, however, they deal with collections of ordered pairs. They...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
ont Maps Maps are similar to collections, however, they deal with collections of ordered pairs. They are useful fin the construction of databases. Consider the following program that shows the implementation of a Student database. The class Hash Demo show how a database of students can be created and stored in a map. The Hashmap consist of the pair String, and Student. The String is the key that is used to search for the value linked to that key. import java.util.HashMap; import java.util.Scanner; on3" 1692!) Jinw( q.tuo.metay2 2 public class HashMapDemo { (920. public static void main(String[] args) { // TODO Auto-generated method stub return hireDate; Scanner scan = new Scanner (System.in); String searchName = ""; T HashMap<String, Student> student = new duq di staving HashMap<String, Student>(10); ram args student.put("Mike", new Student (23667,' Mike Mannix", new Date ("June", 15, 2006))); student.put("Julie", new Student (45771, " Julie Grosvenor", new Date ("May", 31, 2006))); : (2005 do { System.out.pr :008 System.exit 129T" = 9msn "Vsun6C")9±60 wen = 9160d System.out.println("\n Enter the student name that you wish to look up or press enter to end processing"); } (si searchName = scan.nextLine(); if(student.containsKey(searchName)) { Student stu = :("95 student.get(searchName); System.out.println(" Student Found: " + stu); Sy wmployee hire} else if(!searchName.equals("")){ 1109/00/8 10 insbu12)insbu±2 Iduq 1 System.out.println(" Student: " + searchName + " not found"); } } while (!searchName.equals("")); System.out.println(" End of Processing"); scan.close(); } } The Student class Jduq public class Student { 12 CH >qeMdzsH private int id; private String name; private Date hireDate; "Juq.Jn55012 public Student ( ) 60 wen,"honeva Siluc { id = 1000; } name = "Test Name"; hireDate = new Date("January",11, 2005); .. .. public Student (int theid, String the Name, Date theDate) { } ((smat{ if (theName == null || theDate == null) employee"); :br } 032 System.out.println("Fatal Error creating System.exit(0); id = theid; name = theName; hireDate = theDate; 12 } public Student (Student originalObject) { name = originalObject.name; hireDate = new Date(originalObject.hireDate); } public int getId() { } return id; public String getName() { } return name; public Date getHire Date() { reo) munters te Erro return hireDate;); } ) aЛsupe nes po neeJood olduq te.mo th; yea year) } /** bonadto = ad * Precondition newName is not null * @param args */ public void setName(String newName) { day, int /** if (newName == null) { int { System.out.println ("Fatal Error"); T System.exit(0); this.day = day; } thi else this year) ar; v):1oqmi } 9160 228Jɔ ɔiJduq name = newName; thom print2.steving else { ysb ni staving 169y tni staving * Precondition newDate is not null ror"); * @param args.exit(0); */ ()9760 dug public void setHire Date (Date newDate) { publif (newDate == null) { ysb System.out.println("Fatal Error setting wmployee hire " + "date. "); (169 System.exit(0); om } this.month = month; :(169y.,ysb Idnom)9780192 niyab tni.Qnin12tnom pn112)9160 Jduq 3 (9160 + } else }()bI9p this.hireDate = newDate; 91 12 Sifdug public String toString() { teman mu return (getId() + " " +getName() + " " getHireDate().toString()); } 90 9160 jdug 19] กามาร public boolean equals (Student otherObject) { public } } return this == otherObject; 20 19 732) 9m6Mt92 biov oiJduq ic St } (JJun == 9ms/wn)ti public class Date { The Date class import java.util.Scanner;(8)tixs.mstay2 private String month; mswap 261") nJtning.tuo.mstay2 new Date("January. private int day; heid, private int year; 2805); te public Date() { month = "January"; H2 biov ɔilduq day = 1; year = 1900; } Gwen)ti rev2 d 99yofgmw vearl public Date (int monthInt, int day, int year) { } setDate(month Int, day, year); public Date(String monthString, int day, int { } setDate(monthString, day, year); public Date (int year). sb.eing { setDate(1,1, year); } public Date(Date aDate) x9.mstay2 { if (aDate == null) return "June"; { System.out.println("Fatal Date Error"); System.exit(0); duq iЛduq } 160792 biov month = aDate.month; day = aDate.day; soy,1,1)9760192 year = aDate.year; } return y 192 biov year) public void setDate(int monthInt, int day, int { return ateo if (dateOK(monthInt, day, year)){ defa this.month = monthName (monthInt); Errer" 92 Je this.day = day; tln("Fatal Err this. year = year; } else { return (190 System.out.println("Fatal error"); ((SI<PHbd System.exit(0); 19dmu } > 13)) } year) (19d { System.out!"EVE public void setDate(String month, int day, int else if (dateOK(month, day, year)){ dinom this.month = month; 112 Ju (danom) das is } } this.day = day; this. year = year; } else { Idug System.out.println("Fatal error"); System.exit(0); un == 93606) TI dev2 public void setDate(int year) eve {ublic bool equal 1 = d dinom set Date (1,1, year); } 97808 = 769% public void setYear(int year) { if ((year< 1000 || year > 9999)) { } else } Jduq (160y System.out.println("Fatal Error"); System.exit(0); this.year = year; aid? sevizing public void setMonth (int monthNumber) if((monthNumber <= 0) || (monthNumber >12)) { { Ysb} else } System.out.println("Fatal Error"); System.exit(0); biov month = monthName (monthNumber); (159 teb) public String monthName (int month) { switch (month) { case 1: return "January"; case 2: return "February"; case 3: food staving return "March"; case 4: return "April"; case 5: 30Iyab) 33 (I=< inIysb) :((eeee >> Joy) 33 return "May"; case 6: return "June"; 33 (I=< the mont case 10: return "October"; case 7: return "July"; case 8: eyboard = return "August"; case 9: return "September"; nsefood steving (Jissy tni,JIvsb Scanner(System.in); Snom) กาบ รา the nativeb) :(eeee yboard.next(); case 11: [n = 1 nextInt(); return "November"; ard.nextInt(); case 12: return "December"; default: tnom) muterIn); 11 ("d7sM System.out.println("Fatal Error"); nom System.exit(0); return "Error"; dnom JCA") aJ6ups.tnom } Reent} { publi{ } 1.20QUA") al sups.dtnom. .d dinom } public void setDay(int day) do edme if ((day <= 0)||(day > 13)) else t System.out.println("Fatal Error"); System.exit(0); this.day = day; = 169) 30 (yeb.ysbd ()dnoMag ont2 tduq entinom.eint กามร้อ 0") )aJsups.dtnom ") aj aJsups.dtnom 7 :I 9280 private boolean dateOK(int monthInt, int dayInt, int yearInt) { return((monthInt >= 1) && (monthInt <=12) && (dayInt >=1) && (dayInt <= 31) && (yearInt >= 1990 ) && (yearInt <= 9999)); } private boolean dateOK(String monthSt, int dayInt, int yearInt) { int :8 e return (monthOK (monthSt) && (dayInt >=1) && (dayInt <= 31) && (yearInt >= 1990 ) && (yearInt <= 9999)); :81 9263 } id se uts :II 9263 299917 for"); private boolean monthOK (String month) { return (month.equals("January") || month.equals("February") || month.equals("March") || month.equals("April") || month.equals("June") || month.equals("July") || month.equals("May") || month.equals("September") || month.equals("August") || month.equals("October") || month.equals("November") || month.equals("December") ); } ((EI < out ysb)). public boolean equals (Date bday) return((month.equals(bday.month)) && (day bday.day) && (year == bday.year)); == } public String getMonth() { return this.month; } public int getDay() { return this.day; } public int getYear() { return this.year; } public void readInput() { boolean loop = true; I] args) C thod stuff Scanner keyboard = new Scanner(System.in); while (loop) { System.out.println("Enter the name of the month, day, year"); == String monthIn = keyboard.next(); int dayIn = keyboard.nextInt(); int year In = keyboard.nextInt(); if (dateOK (monthIn, dayIn, yearIn)) setDate(monthIn, dayIn, yearIn); loop = false; { } else Reenter data"); } keyboard.close(); } System.out.println("illegal date. e(); chName)) stud public String toString() { ht return(month + " "+ day + " " + year); //ystem.out.println(getMonth() + " " + getDay() + ", + getYear() ); 9 ont Maps Maps are similar to collections, however, they deal with collections of ordered pairs. They are useful fin the construction of databases. Consider the following program that shows the implementation of a Student database. The class Hash Demo show how a database of students can be created and stored in a map. The Hashmap consist of the pair String, and Student. The String is the key that is used to search for the value linked to that key. import java.util.HashMap; import java.util.Scanner; on3" 1692!) Jinw( q.tuo.metay2 2 public class HashMapDemo { (920. public static void main(String[] args) { // TODO Auto-generated method stub return hireDate; Scanner scan = new Scanner (System.in); String searchName = ""; T HashMap<String, Student> student = new duq di staving HashMap<String, Student>(10); ram args student.put("Mike", new Student (23667,' Mike Mannix", new Date ("June", 15, 2006))); student.put("Julie", new Student (45771, " Julie Grosvenor", new Date ("May", 31, 2006))); : (2005 do { System.out.pr :008 System.exit 129T" = 9msn "Vsun6C")9±60 wen = 9160d System.out.println("\n Enter the student name that you wish to look up or press enter to end processing"); } (si searchName = scan.nextLine(); if(student.containsKey(searchName)) { Student stu = :("95 student.get(searchName); System.out.println(" Student Found: " + stu); Sy wmployee hire} else if(!searchName.equals("")){ 1109/00/8 10 insbu12)insbu±2 Iduq 1 System.out.println(" Student: " + searchName + " not found"); } } while (!searchName.equals("")); System.out.println(" End of Processing"); scan.close(); } } The Student class Jduq public class Student { 12 CH >qeMdzsH private int id; private String name; private Date hireDate; "Juq.Jn55012 public Student ( ) 60 wen,"honeva Siluc { id = 1000; } name = "Test Name"; hireDate = new Date("January",11, 2005); .. .. public Student (int theid, String the Name, Date theDate) { } ((smat{ if (theName == null || theDate == null) employee"); :br } 032 System.out.println("Fatal Error creating System.exit(0); id = theid; name = theName; hireDate = theDate; 12 } public Student (Student originalObject) { name = originalObject.name; hireDate = new Date(originalObject.hireDate); } public int getId() { } return id; public String getName() { } return name; public Date getHire Date() { reo) munters te Erro return hireDate;); } ) aЛsupe nes po neeJood olduq te.mo th; yea year) } /** bonadto = ad * Precondition newName is not null * @param args */ public void setName(String newName) { day, int /** if (newName == null) { int { System.out.println ("Fatal Error"); T System.exit(0); this.day = day; } thi else this year) ar; v):1oqmi } 9160 228Jɔ ɔiJduq name = newName; thom print2.steving else { ysb ni staving 169y tni staving * Precondition newDate is not null ror"); * @param args.exit(0); */ ()9760 dug public void setHire Date (Date newDate) { publif (newDate == null) { ysb System.out.println("Fatal Error setting wmployee hire " + "date. "); (169 System.exit(0); om } this.month = month; :(169y.,ysb Idnom)9780192 niyab tni.Qnin12tnom pn112)9160 Jduq 3 (9160 + } else }()bI9p this.hireDate = newDate; 91 12 Sifdug public String toString() { teman mu return (getId() + " " +getName() + " " getHireDate().toString()); } 90 9160 jdug 19] กามาร public boolean equals (Student otherObject) { public } } return this == otherObject; 20 19 732) 9m6Mt92 biov oiJduq ic St } (JJun == 9ms/wn)ti public class Date { The Date class import java.util.Scanner;(8)tixs.mstay2 private String month; mswap 261") nJtning.tuo.mstay2 new Date("January. private int day; heid, private int year; 2805); te public Date() { month = "January"; H2 biov ɔilduq day = 1; year = 1900; } Gwen)ti rev2 d 99yofgmw vearl public Date (int monthInt, int day, int year) { } setDate(month Int, day, year); public Date(String monthString, int day, int { } setDate(monthString, day, year); public Date (int year). sb.eing { setDate(1,1, year); } public Date(Date aDate) x9.mstay2 { if (aDate == null) return "June"; { System.out.println("Fatal Date Error"); System.exit(0); duq iЛduq } 160792 biov month = aDate.month; day = aDate.day; soy,1,1)9760192 year = aDate.year; } return y 192 biov year) public void setDate(int monthInt, int day, int { return ateo if (dateOK(monthInt, day, year)){ defa this.month = monthName (monthInt); Errer" 92 Je this.day = day; tln("Fatal Err this. year = year; } else { return (190 System.out.println("Fatal error"); ((SI<PHbd System.exit(0); 19dmu } > 13)) } year) (19d { System.out!"EVE public void setDate(String month, int day, int else if (dateOK(month, day, year)){ dinom this.month = month; 112 Ju (danom) das is } } this.day = day; this. year = year; } else { Idug System.out.println("Fatal error"); System.exit(0); un == 93606) TI dev2 public void setDate(int year) eve {ublic bool equal 1 = d dinom set Date (1,1, year); } 97808 = 769% public void setYear(int year) { if ((year< 1000 || year > 9999)) { } else } Jduq (160y System.out.println("Fatal Error"); System.exit(0); this.year = year; aid? sevizing public void setMonth (int monthNumber) if((monthNumber <= 0) || (monthNumber >12)) { { Ysb} else } System.out.println("Fatal Error"); System.exit(0); biov month = monthName (monthNumber); (159 teb) public String monthName (int month) { switch (month) { case 1: return "January"; case 2: return "February"; case 3: food staving return "March"; case 4: return "April"; case 5: 30Iyab) 33 (I=< inIysb) :((eeee >> Joy) 33 return "May"; case 6: return "June"; 33 (I=< the mont case 10: return "October"; case 7: return "July"; case 8: eyboard = return "August"; case 9: return "September"; nsefood steving (Jissy tni,JIvsb Scanner(System.in); Snom) กาบ รา the nativeb) :(eeee yboard.next(); case 11: [n = 1 nextInt(); return "November"; ard.nextInt(); case 12: return "December"; default: tnom) muterIn); 11 ("d7sM System.out.println("Fatal Error"); nom System.exit(0); return "Error"; dnom JCA") aJ6ups.tnom } Reent} { publi{ } 1.20QUA") al sups.dtnom. .d dinom } public void setDay(int day) do edme if ((day <= 0)||(day > 13)) else t System.out.println("Fatal Error"); System.exit(0); this.day = day; = 169) 30 (yeb.ysbd ()dnoMag ont2 tduq entinom.eint กามร้อ 0") )aJsups.dtnom ") aj aJsups.dtnom 7 :I 9280 private boolean dateOK(int monthInt, int dayInt, int yearInt) { return((monthInt >= 1) && (monthInt <=12) && (dayInt >=1) && (dayInt <= 31) && (yearInt >= 1990 ) && (yearInt <= 9999)); } private boolean dateOK(String monthSt, int dayInt, int yearInt) { int :8 e return (monthOK (monthSt) && (dayInt >=1) && (dayInt <= 31) && (yearInt >= 1990 ) && (yearInt <= 9999)); :81 9263 } id se uts :II 9263 299917 for"); private boolean monthOK (String month) { return (month.equals("January") || month.equals("February") || month.equals("March") || month.equals("April") || month.equals("June") || month.equals("July") || month.equals("May") || month.equals("September") || month.equals("August") || month.equals("October") || month.equals("November") || month.equals("December") ); } ((EI < out ysb)). public boolean equals (Date bday) return((month.equals(bday.month)) && (day bday.day) && (year == bday.year)); == } public String getMonth() { return this.month; } public int getDay() { return this.day; } public int getYear() { return this.year; } public void readInput() { boolean loop = true; I] args) C thod stuff Scanner keyboard = new Scanner(System.in); while (loop) { System.out.println("Enter the name of the month, day, year"); == String monthIn = keyboard.next(); int dayIn = keyboard.nextInt(); int year In = keyboard.nextInt(); if (dateOK (monthIn, dayIn, yearIn)) setDate(monthIn, dayIn, yearIn); loop = false; { } else Reenter data"); } keyboard.close(); } System.out.println("illegal date. e(); chName)) stud public String toString() { ht return(month + " "+ day + " " + year); //ystem.out.println(getMonth() + " " + getDay() + ", + getYear() ); 9
Expert Answer:
Answer rating: 100% (QA)
Ive made corrections and completed the missing parts of the code Additionally Ive renamed the student HashMap to studentMap for clarity Please note th... View the full answer
Related Book For
Management Accounting Information for Decision-Making and Strategy Execution
ISBN: 978-0137024971
6th Edition
Authors: Anthony A. Atkinson, Robert S. Kaplan, Ella Mae Matsumura, S. Mark Young
Posted Date:
Students also viewed these programming questions
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
answer the question clearly You are building a flight-control system for which a convincing safety case must be made. Would you assign the tasks of safety requirements engineering, test case...
-
help me pls P acquired \( 80 \% \) of the capital of S on 1 January 2021. At the year end 31 December 2021 the two companies have the following statements of financial position: Notes 1....
-
Table 313 shows the process states for the VAX/VMS operating system. a. Can you provide a justification for the existence of so many distinct wait states? b. Why do the following states not have...
-
(a) Refer to the differential encoder used in Figure a. Table 6.10 defines the phase changes induced in the V.32 modem by varying input debits. Expand this table by including the corresponding...
-
At the same speed, the number of power strokes given by a two-stroke engine as compared to a four-stroke engine is: (a) Half (b) Same (c) Double (d) Four times
-
The balance sheet of Consolidated Paper, Inc., included the following shareholders' equity accounts at December 31, 2010: During 2011, several events and transactions affected the retained earnings...
-
Program for Read name, address, email and phone number of a person through keyboard and print the details.
-
Services to persons or entities that are requested by a third party require ______. a) Clarification of the nature of the relationship with each party, use of services, and limits to confidentiality...
-
Write a 4 page paper on Object Oriented Concepts. The paper should address the following: What is object oriented programming / concepts? What are some advantages of object oriented design? How would...
-
attached report on Alibaba's proposed move into Rwanda. How does Alibaba benefit from this move? What do you see as the biggest obstacle to success? How can Alibaba overcome this obstacle? How...
-
Summary: Counting with Beads: A counting activity using beads and yarn. Block Building Challenge: A spatial relations activity using blocks. Pattern Creation with Stickers: A pattern recognition...
-
Read the article of THE ACCIDENTAL THEORIST by Paul Krugman at http://www.pkarchive.org/theory/hotdog.html Briefly discuss the method of economics according to Professor Krugman. Justify your answer...
-
the colonization of part of the future United States. In the North, Puritans spoke about creating a "City Upon a Hill, " in which the colonies would be a righteous model for the rest of the world....
-
In the mass spectrum of benzyl alcohol (C6H3CH2OH), the base peak would be predicted to correspond to which of the following structures? A) C6H5CH2O+ (m/z 107) B) C6H4 CH2O (m/z 107) C) C6H5CH (m/z...
-
A Berhad, a Malaysian conglomerate, is considering setting up a subsidiary in Singapore to manufacture and sell in that country products currently made in Malaysia. An initial investment of S$5...
-
Write an SQL statement to display all data on products having a QuantityOnHand greater than 0.
-
Describe the product leadership value proposition and provide your own example of a company that has successfully implemented this value proposition.
-
Ming Company has two service departments (S1 and S2) and two production departments (P1 and P2). Last year, directly identified overhead costs were $300,000 for S1 and $300,000 for S2. Information on...
-
How can the information from an activitybased costing system guide improvements in operations and decisions about products and customers?
-
Under an evolutionary classification system, species are grouped together based on (a) their shared similarities. (b) how closely related they are to one another. (c) their position in a hierarchy...
-
What criteria are used to classify species in the Linnaean system?
-
What criteria are used to classify species in an evolutionary classification system?
Study smarter with the SolutionInn App