LAB09, Array of objects – Binary Search, Sequential Search Points: 25 OBJECTIVE
ID: 3832350 • Letter: L
Question
LAB09, Array of objects – Binary Search, Sequential Search Points: 25
OBJECTIVE
To demonstrate using parallel arrays
To demonstrate using a binary search through arrays
To demonstrate using a sequential search through arrays
REQUIRED
A report of your work, in a flat pocket folder, in the following order:
1. Grade Form
2. This program description
3. The source listing of the Student class Student.java
4. Problem Analysis with Input, Output, Pseudocode (word processed)
5. The listing of the source program Lab09.java
Data dictionary (included as comments)
6. Listing of the input file Lab09StudentFile.txt
7. Listing of the student name file Lab09Names.txt
8. Listing of the expected results (already created) Lab09ExpectedResults.xlsx
9. Listing of the output file Lab09Report.txt
SPECIFICATIONS
Start with Lab08
1. Instead of doing a sequential search through the names file, load the file into two parallel arrays. Parallel arrays are arrays that are linked positionally. For this application, create an array for the student number and an array for the student name. This should be done in main.
2. Do a binary search to locate the student name. Use a method for the binary search. See Java13BinarySearch and Java13BinarySearchTrace.
3. Set up the letter grade and low range in parallel arrays. Create an array for the low end of the range and an array for the letter grade. This should be done in main
4. Convert the average to a letter grade.
Use a method and a sequential search to select the letter grade.
Instead of doing an “==” comparison, use a “>=” comparison on the low end of the grade range.
FOR EXAMPLE:
First time through the search loop, if average is >= low (97), then grade is an ‘A+’
If not an ’A+’, then average MUST be 96 or less, so if average >= low (93), then grade is an ‘A’
If not an ’A’, then average MUST be 92 or less, so if average >= low (90), then grade is an ‘A-’
Etc.
Exit the search when the correct grade is found or when the search is over
Grade low - high
A+ 97%-100%
A 93%-96%
A- 90%-92%
B+ 87%- 89%
B 83%- 86%
B- 80%- 82%
C+ 77%- 79%
C 73%- 76%
C- 70%- 72%
D+ 67%- 69%
D 63%- 66%
D- 60% - 62%
F 00%- 59%
INPUT
File: Student file Lab09StudentFile.txt
Record: Student record
Field Data Type
Student id# 4 numbers (ex. 1234)
Ten test scores integers (valid numbers are 0 -100)
INPUT
File: Student name file Lab09Names.txt
Record: Student name record
Field Data Type
Student id# 4 numbers (ex. 1234)
Student name String
OUTPUT
File: Grade Report file LAB09Report.txt
Record:
Student Grade Report, sorted by Name
ID# Name /---------------------TEST Scores----------------------/ Total Adj Total Avg Grade
xxxx xxxxxxxxxxxxxxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxxx xxxx xxx xx
xxxx xxxxxxxxxxxxxxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxxx xxxx xxx xx
xxxx xxxxxxxxxxxxxxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxxx xxxx xxx xx
Total students = xx
Here's a link to the completed Lab08 which this builds upon.--> https://pastebin.com/UXT6XHTw
Here's the link to the completed Student Class file.--> https://pastebin.com/DvZvKq2M
Here's a link to the Lab09Names file.-->https://pastebin.com/hVsq0Pwk
Explanation / Answer
public final class Dungeon { private final Map map = new HashMap(); private Room currentRoom; private int currentX = 0; private int currentY = 0; private Dungeon() { } private void putRoom(int x, int y, Room room) { if (!map.containsKey(x)) { map.put(x, new HashMap()); } map.get(x).put(y, room); } private Room getRoom(int x, int y) { return map.get(x).get(y); } private boolean roomExists(int x, int y) { if (!map.containsKey(x)) { return false; } return map.get(x).containsKey(y); } private boolean isComplete() { return currentRoom.isBossRoom() && currentRoom.isComplete(); } public void movePlayer(Player player) throws IOException { boolean northPossible = roomExists(currentX, currentY + 1); boolean southPossible = roomExists(currentX, currentY - 1); boolean eastPossible = roomExists(currentX + 1, currentY); boolean westPossible = roomExists(currentX - 1, currentY); System.out.print("Where would you like to go :"); if (northPossible) { System.out.print(" North (n)"); } if (eastPossible) { System.out.print(" East (e)"); } if (southPossible) { System.out.print(" South (s)"); } if (westPossible) { System.out.print(" West (w)"); } System.out.print(" ? "); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String direction = in.readLine(); if (direction.equals("n") && northPossible) { currentY++; } else if (direction.equals("s") && southPossible) { currentY--; } else if (direction.equals("e") && eastPossible) { currentX++; } else if (direction.equals("w") && westPossible) { currentX--; } currentRoom = getRoom(currentX, currentY); currentRoom.enter(player); } public void startQuest(Player player) throws IOException { while (player.isAlive() && !isComplete()) { movePlayer(player); } if (player.isAlive()) { System.out.println(Art.CROWN); } else { System.out.println(Art.REAPER); } } public static Dungeon newInstance() { Dungeon dungeon = new Dungeon(); dungeon.putRoom(0, 0, Room.newRegularInstance()); dungeon.putRoom(-1, 1, Room.newRegularInstance()); dungeon.putRoom(0, 1, Room.newRegularInstance()); dungeon.putRoom(1, 1, Room.newRegularInstance()); dungeon.putRoom(-1, 2, Room.newRegularInstance()); dungeon.putRoom(1, 2, Room.newRegularInstance()); dungeon.putRoom(-1, 3, Room.newRegularInstance()); dungeon.putRoom(0, 3, Room.newRegularInstance()); dungeon.putRoom(1, 3, Room.newRegularInstance()); dungeon.putRoom(0, 4, Room.newBossInstance()); dungeon.currentRoom = dungeon.getRoom(0, 0); return dungeon; } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.