0

I am trying to make a method that finds the max value of an integer in a vector. I want a method such as

     /**
     * The method returns an integer.
     * The integer is the greatest value of all tagValues of the lab    devices
     */
public int findMaximumValueTag()

The tag values will be the integer beside a device in a text file, on every line, such as

Android,53
Blackberry2,-95
iPhone,45

So, with the above, the method should return the 53.

The start of the class that contains the method is as follows:

public class Lab  implements MaxTagValue {

String labName;
Vector<MobileDevice> devices;

Any help at all with pseudo code or anything would be greatly appreciated to get this started, thank you very much!

Also the beginning of the MobileDevice class is as follows:

public class MobileDevice {

String       deviceName;  // the device name
int          valueTag;    // an integer between -100 and 100
Lab          lab;         // the lab having this device it its inventory
brooksyp
  • 1
  • 1
  • 3
  • 1
    Find all numbers in the file as following in [this answer](http://stackoverflow.com/questions/3806062/how-to-open-a-txt-file-and-read-numbers-in-java) and then simply find max value. – DimaSan Nov 25 '16 at 15:36

1 Answers1

0

you can iterate through your vector with a for-each-loop and save the int value in a variable called max or something like that. and every time you go through the loop you check if the current int value is bigger than max or not. if yes you set max to the current int value if not you ignore it

code:

Vector<MobileDevice> devices;
        int max=0;
        for(MobileDevice md:devices){
            if(md.getValueTag()>max){
                max=md.getValueTag();
            }
        }
XtremeBaumer
  • 6,275
  • 3
  • 19
  • 65