Top-Rated Free Essay
Preview

Using ArrayListITSystem Reading And Writing Data

Powerful Essays
1222 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Using ArrayListITSystem Reading And Writing Data
Using ArrayList<ITSystem>, Reading and writing Data to/from Files
Note: slight changes were made on 11/14 (1 day after this was put up). Specifically, the source files are slightly different from the solution to p2. When comparing two ITSystems we are now only concerned with ID. Highlighted text reflects changes made to the assignment.
For this assignment, we will continue to work with the SysInventory program we developed in the last programming project, with a few minor changes/additions. See the provided files. Note thatITSystem now has an equals method, coded following equals for Point, pages 595-596. If you completed all the problems for project 2 you may use your own files for project 3. If you do, you will be expected to complete the same work, but some of the advice on how to accomplish it may be incorrect. If you did not complete all the problems, or you would prefer a fresh start, you You should use the files provided to start with.

1. Convert the ITSystem array of SysInventory to ArrayList<ITSystem> systems. We will no longer use an empty 0 slot as we did with the array, but instead look up ITSystems by their id using the helper method findSystem(id). We want to eventually allow ids like 100, 101, 120, etc,, as well as the simple sequence 1, 2, 3, …. The helper method findSystem(id) can be written as follows: ArrayList<ITSystem> systems = new ArrayList<ITSystem>(findSystem(id));

private ITSystem findSystem(int id) { return systems.get(systems.indexOf(new ITSystem(id, 0, 0)));
}

This works because ITSystem has equals based on the id, so indexOf searches for the matching id. The “0, 0” arguments are necessary to make the constructor work, but these zero values are never used in the search. The challenge here is finding all the places that use the array and changing them over to using the ArrayList. For example, in whichITSystem() we have “return systems[idNumber]”, but now we want “return findSystem(idNumber)”. These changes will not affect the user experience, except that it is no longer necessary to ask how many systems will be set up (Enter how many systems: 2), since we can just start with an empty ArrayList and add any number of systems to it. We now need to let the user say when he/she is done adding systems. After this part is complete, the system should run as follows (for example):
Welcome to Departmental Network Systems
Enter system's room no, or 0 to quit adding systems: 10 System is assigned number 1
Enter system's room no, or 0 to quit adding systems: 20 System is assigned number 2
Enter system's room no, or 0 to quit adding systems: 0
Enter system inventory number, print-all, room <n>, or 0 to quit: 2
System 2 selected
Actions: exit, help, print, record-problem, in-same-room, move
Enter action: record-problem
The system now has 1 recorded problems
Enter action: help
Actions: exit, help, print, record-problem, in-same-room, move
Enter action: exit
Enter system inventory number, print-all, room <n>, or 0 to quit: 0
Goodbye from Departmental Network Systems 2. See the provided file systems.dat.
File systems.dat:
100 100 1
101 200 0
120 100 2
This file is describing three ITSystems, with id first, room number second, and number of problems third on the line. We want to read this file in our system and put the three ITSystem objects in the ArrayList.
a. Change the method open by adding a filename parameter: public void open(Scanner input, String filename) and change the call in SystemInventoryMain to open(input, “systems.dat”);
Further, have open call private void load(String filename) to read the named file into systems. To start with, just have load print “loading…”.
b. Now fill out load to actually read the file. Note that systems is directly available to all object methods because it is a SysInventory field. Method load should read the file, line by line, and call method processLine to interpret one line and put its values into a new ITSystem object and return it. See somewhat similar code on pages 410-411. Then load should add the new ITSystem object into the growing ArrayList. When load returns to open, open should report the number of ITSystems now in systems. Then the user should be invited to add more entries using the old code. After this part is complete, the system should run as follows (for example):
Welcome to Departmental Network Systems
3 systems read from systems.dat
Enter additional systems as needed now
Enter system's room no, or 0 to quit adding systems: 100 System is assigned number 121 (adding 1 to highest id so far)
Enter system's room no, or 0 to quit adding systems: 0 Enter system inventory number, print-all, room <n>, or 0 to quit: 100
System 100 selected
Actions: exit, help, print, record-problem, in-same-room, move
Enter action: in-same-room Systems in the same room as system 100:
ID: 100, Room: 100, Problems Reported: 1
ID: 120, Room: 100, Problems Reported: 2
ID: 121, Room: 100, Problems Reported: 0
Enter Action: exit
Enter system inventory number, print-all, room <n>, or 0 to quit: 0 Goodbye from Departmental Network Systems

3. Similar to load(String filename), implement save(filename) to save the ArrayList contents to a file. Add a method close(filename) to SysInventory that asks the user whether to save the file or not, and if so, calls save(filename). Call close(“systems1.dat”) from SystemInventoryMain after the call to doCommands(). Note the example MakeFile.java in the p3 files area. It shows how to create a new named file and use println to specify the contents.
Welcome to Departmental Network Systems
3 systems read from systems.dat
Enter additional systems as needed now
Enter system's room no, or 0 to quit adding systems: 100 System is assigned number 121 (adding 1 to highest id so far)
Enter system's room no, print-all, or 0 to quit adding systems: 0
Enter system inventory number, room <n>, or 0 to quit: 100
System 100 selected
Actions: exit, help, print, record-problem, in-same-room, move
Enter action: in-same-room Systems in the same room as system 100:
ID: 100, Room: 100, Problems Reported: 1
ID: 101, Room: 100, Problems Reported: 2
ID: 120, Room: 100, Problems Reported: 0
Enter Action: exit
Save ITSystems to file systems1.dat? Enter y or n: y
Saved 4 ITSystems to file systems1.dat. Resulting file systems1.dat:
100 100 1
101 200 0
120 100 2
121 100 0 4. Write a narrative that describes how you went about designing and implementing these modifications, any problems you encountered and how yu solved them, how you tested your program (how test cases were chosen and why) and a (cut and pasted) result for these tests. Put this in a text file called memo.txt. Delivery
Create a subdirectory p3 (not P3) in your it115 subdirectory on your CS Unix network account, and transfer a copy of your resulting Java files and narrative there, in plain text file memo.txt
Delivery files: Make sure the names are the same as specified here, including their case (Not Memo.txt for example)
1. ITSystem.java (as provided, or your own if preferred).
2. SysInventory.java with added code as specified above.
3. SystemInventoryMain.java: changed to call open and close with a filename argument.
4. memo.txt, with interactive tests shown. In addition, make a paper copy of memo.txt and bring it to class on November 25. Hand it in at the beginning of class. memo.txt should have the name of the file on it, your name, and the assignment (p3). It should be either paper-clipped or stapled together. In addition, make a copy of p3.gradesheet.htm and hand it in with memo.txt in class, at the beginning of class on November 25. Your name should be on p3.grade_sheet.htm. Nothing else should be filled in.

You May Also Find These Documents Helpful

  • Good Essays

    Arrays store items that have the same type of data type like a group of employees’ names and social security numbers for a team of 2000 personal. Pointer is a variable that greatly extends the power and flexibility of a program, each memory location that is used to store data value has an address. The address provides the means for a PC hardware to reference a particular data item.…

    • 485 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    5. [3] Ten processes share a critical section implemented by using a semaphore x. Nine…

    • 299 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    From the first look at the CourseMate recourses, user will find a number of very intelligent tools that can help him/her to read, practice, and even taking some quizzes to evaluate his/her level. Those recourses are available for each chapter and can be accessed easily with valid course key and CourseMate pin number.…

    • 695 Words
    • 3 Pages
    Good Essays
  • Good Essays

    Chapter 8 Quiz

    • 469 Words
    • 2 Pages

    4. Which is the simplest search technique to use to find an item in an array? (Points : 7)…

    • 469 Words
    • 2 Pages
    Good Essays
  • Good Essays

    7 and Array

    • 500 Words
    • 2 Pages

    7. When a single array element, such as myArray[2], is passed to a method, the method receives _____.…

    • 500 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    E4.6: The label array_x is the starting address of an array of 100 8bit elements.…

    • 900 Words
    • 4 Pages
    Satisfactory Essays
  • Satisfactory Essays

    The day the Great Depression started is known as Black Tuesday, it is the day the stock marets crashed. The saock prices crashed to a point whereit was believed for them to never rise again. This cause a long period of panic struck. Many people tried to sell their purchased stocks bnot a single personwas buying. The stock market was seen as road to riches and after it crashed it was shadowed in people seeing it as a road to bankruptcy.…

    • 170 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    Is 310 Ch 1 Assignment

    • 801 Words
    • 4 Pages

    5. Typically, a(n) computer operations manager is responsible for a large computer center and all the software running in it.…

    • 801 Words
    • 4 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Syllabus

    • 627 Words
    • 3 Pages

    Submit file in Blackboard (“Found Dog Flyer.docx”) Complete in SAM: Lab 1-1 Study Habits Flyer.docx Submit file in Blackboard (“Triangulation Paper.docx”) Complete in SAM: Lab 2-1 Game Controllers Paper.docx Submit file in Blackboard (“Heartland Advertisement Letter.docx”) Complete in SAM: Lab 3-1 Cloud Storage Letter.docx Word Windows 7…

    • 627 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    4. At this part of The Catcher In the Rye, Holden is talking to Phoebe about his possible future careers, however his choice in career reflects Holden's affinity for all things innocent and his will to a protector of them. Holden remembers a part of a Robert Burns poem incorrectly as "if a body catch a body coming through the rye" this causes him to imagine himself saving children by "catch[ing] them" before they "go over the cliff." Ironically, the poem itself is about casual sex, yet Holden interprets it differently in a much more innocent manner. He believes that someone must save the children before they fall off the cliff. The children represent innocence and Holden wants to save the children before they fall off the cliff and enter into the pit of adulthood and a world full of phonies. As Holden himself struggles with realizing his own future, he does not realize that he also wants to be saved from the…

    • 636 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    Essay: a Rose for Emily

    • 517 Words
    • 3 Pages

    In the short story “A Rose for Emily”, the reader can conclude that Emily appears to have had schizophrenia by way she interacts in the town. Emily’s mental problems start to come to light to the reader when she begins having hallucinations. The reader gains further background and further sees mental instability in Emily right after her father dies. The town people also begin to see that there are mental issues with Emily, yet do not want to make it known to keep the integrity of the town. Emily’s inability to form age appropriate coping skills furthers the point of schizophrenia.…

    • 517 Words
    • 3 Pages
    Good Essays
  • Powerful Essays

    This paragraph shall contain a full identification of the database to which this document applies including identification number(s), title(s), abbreviation(s), version number(s),…

    • 1336 Words
    • 6 Pages
    Powerful Essays
  • Powerful Essays

    Computer Systems

    • 1233 Words
    • 5 Pages

    I certify that the work submitted or this assignment is my own and research sources are fully acknowledged.Learner signature: Date:|…

    • 1233 Words
    • 5 Pages
    Powerful Essays
  • Powerful Essays

    Linked List

    • 3270 Words
    • 14 Pages

    – Must know the pointer to the first element of the list (called start, head, etc.).…

    • 3270 Words
    • 14 Pages
    Powerful Essays
  • Satisfactory Essays

    OCJA exam prep

    • 5816 Words
    • 24 Pages

    2. Which statement represents a valid statement that will allow for the inclusion of classes from the java.util package?…

    • 5816 Words
    • 24 Pages
    Satisfactory Essays

Related Topics