• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Replacing old values with new values

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For a school assignment the class was asked to modify some existing code that we had done earlier so that on of our methods would call another method to see if a certain text file had any duplicate entries, and replace any old values with the newer values. We had already written one method called ipos to read and display all of the entries in the file. We had also written a method called addAttr to add any missing values. We were asked to modify the addAttr method using ipos to replace the old value of each of the attributes in the file with the new attribute. We were told to use an if statement. The code I have is below, I know that what I have is what my professor wanted, I am simply unsure of what to put in the if block to replace old values with the new ones that ipos finds.



The first block is the addAttr method that is being modified. The second method is the ipos method that scans the config file line by line and returns each key and its associated value. If you need any additional information please let me know and I will try to answer to the best of my ability. If you need to see the rest of the code that is fine as well. Just let me know and I'll post the code in its entirety.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi and welcome to the Javaranch.

Is it correct that ipos() returns the index location of the attribute in the array? In that case just replace the value at that location without incrementing numCfg.
By the way: why don't you use an ArrayList to store your values that way you have access to handy method such as contains().
 
I am a man of mystery. Mostly because of this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic