Jump to content

tombguy5

Community Member
  • Posts

    216
  • Joined

  • Last visited

  • Donations

    0.00 GBP 

Posts posted by tombguy5

  1. So after a few more projects, I've come across another problem, this time with a Java Binary Search Algorithm.

    The goal is to open a .txt file with a bunch of random numbers and the program will ask you what you want to find and then display whether it is found or not. I have created the Algorithm, however, I need a way to call the method.

     

    The solution may be somethign simple but I cannot find it.

     

    Here is the code:

     

     

    package searchingalgorithm;
     
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.RandomAccessFile;
     
    public class SearchingAlgorithm {
        
        public static void main(String[] args) throws IOException
        { 
            
        }
        
        private static long search(RandomAccessFile file, String target) throws IOException
        {
            /*
             * because we read the second line after each seek there is no way the
             * binary search will find the first line, so check it first.
             */
            System.out.println("Binary Search Working");
            file.seek(0);
            String line = file.readLine();
            if (line == null || line.compareTo(target) >= 0) {
                /*
                 * the start is greater than or equal to the target, so it is what
                 * we are looking for.
                 */
                return 0;
            }
     
            /*
             * set up the binary search.
             */
            long beg = 0;
            long end = file.length();
            while (beg <= end) {
                /*
                 * find the mid point.
                 */
                long mid = beg + (end - beg) / 2;
                file.seek(mid);
                file.readLine();
                line = file.readLine();
     
                if (line == null || line.compareTo(target) >= 0) {
                    /*
                     * what we found is greater than or equal to the target, so look
                     * before it.
                     */
                    end = mid - 1;
                } else {
                    /*
                     * otherwise, look after it.
                     */
                    beg = mid + 1;
                }
            }
     
            /*
             * The search falls through when the range is narrowed to nothing.
             */
            file.seek(beg);
            file.readLine();
            return file.getFilePointer();
        }
        
    }

     

  2. Yeah what they both said, Shoot for a 600 series. Perhaps a 650.

    I have a Nvidia GeForce GTX 560 Ti and I can run ArmA 3 on ultra with less than 25 fps, High with 40fps depending on situation, and 50fps on low (which the graphics are godawful). My advice, do not get a 500 series unless you are running older games. I can barely handle Battlefield 4 with 40fps on medium graphic settings. Eventually, once I find a job where I actually get more than 10 hours a month, I'll be saving up to buy a GTX 780 (maybe TITAN if on sale). :)

    Hope this helps!

     

    Here's the link to the Nvidia GeForce GTX 650

  3. To the best of our knowledge, the "copilot slot" bug is not specific to the I&A map, it is a general de-sync problem in the core architecture of the Arma 3 server program. They did not initially program Arma 3 to stream out as much custom coding and data (the amount found in I&A) to such a high number of players at one time. 

     

    And what about the Repair trucks? Only repair once per vehicle and its useless unless destroyed, that was where I was getting to.

  4. I was playing I&A on the US Server with the latest I&A mission build.

     

    I was the transport pilot and as I was picking up the first round of troopers for the AO, I saw the infamous -Character as passenger but outside of helicopter in mid air going through the blades and breaking it- Which did occur and well, needless to say, I was able to fix it with the first repair from a HEMMT Repair Support truck. Afterwards, the aircraft was deemed air worthy again; however, as the soldiers started to embark, the same situation occurrs as when I was starting the rotors, then the helicopter was deemed oncemore, broken.

     

    So I decide to get out, get the HEMMT again and go onward to repair it, but there would be no option to do so nor does it do it automatically. I was basically stuck at the boarding area with a broken helicopter and no means to repair it. I've asked people to switch to Repair Spec but as usual, no one obliges. I've tried many things with the HEMMT and Bobcat and any repair vehicles I can obtain, all to no avail. (and I am ashamed to say, but I had to resort to smashing the helicopter to smithereens just to be able to get some progress; I even warned the troops at base to get away, so they were warned and I hate to say, I had to resort to this unpleasant action.)

     

    So my question is, is this a feature of I&A or is it a glitch with the core ArmA 3 game?

    If feature, perhaps change it to 3 repairs before a cooldown.

    If a core ArmA 3 game... well. fudge.

     

    That is all I have to say,

     

    - R. Berezon

  5. Okay, I have found the solution!

    I had to use a try and catch statement in the bubblesort algorithm with an integer parse and and a NumberFormatException for the catch statement with a regular string comparison. So now this program will run on both Integer and String datatypes at once in the program.

     

    CODE:

     

    package bubblesort_v2;
     
    import java.util.Scanner;
    import java.lang.*;
     
    public class Bubblesort_v2 {
        
        public static void main(String[] args) throws InterruptedException
        {
            int j;
            Scanner in = new Scanner(System.in);
                
            //finding the length of the Array value by user input
            System.out.print("How many values? - Input in numbers: ");
            int totalvalue = Integer.parseInt(in.nextLine());
            String[] value = new String [totalvalue];
     
            int y = 1;
            for(j = 0; j < value.length;j++) //allows user to input values of any sort.
            {
                System.out.print(y + ") Name your values: ");
                value[j] = in.nextLine();
                y += 1;
            }
            Thread.sleep(2000);
     
            System.out.println("\n"+"Unsorted List:");
            for (String element:value)
            {   
                System.out.println(element);
            }
            Thread.sleep(1500);
            bubble_srt(value,value.length);
                    
            System.out.print("\n"+"Sorted List:\n");
                for(j = 0; j < value.length; j++)
                    System.out.print(value[j]+"  "); 
                    System.out.println("\n\n" + "Ending");
        }
        
        public static void bubble_srt( String[] a, int n )
        {//String[] a  is now a function that allows strings as part of the algorithm same to integer (int n)
        int j, i = 0; String t;
            for(j = 0; j < n; j++)
            {
                for(i = 1; i < (n-j); i++)
                {
                    try
                    {
                        if( Integer.parseInt(a[i-1]) > Integer.parseInt(a) )
                        {
                            t = a[i-1];
                            a[i-1]=a;
                            a=t;
                        }
                    }
                    catch( NumberFormatException E )
                    {
                        if( a[i-1].compareTo(a)>0 ) //Another way to look at it is: someValue.compareTo(otherValue) and checks if it is positive ("> 0")
                        {
                            t = a[i-1];
                            a[i-1]=a;
                            a=t;
                        }
                    }
                }
            }
        }
    }
  6. Hey there guys, 

     

    I am trying to make an ambient independent buzzard jet fly by using the BIS_fnc_ambientFlyBy

    I got the blufor helicopters working, but i cannot figure out the independant helicopter/jet.

     

    The issue is to find the independant side classname.

    I already know of BLUFOR and OPFOR (west and east) but not independant, I have already tried guer, resi, guerilla, resistance, green, inde, independent...

    Do any of you guys know the side classname?

     

    Much appreciated!

     

    - R. Berezon

  7. Wok and Rarek: you are great guys. :-)

    I suggested asking in the ahoy forums the first time berezon needed help with java and I couldn't help him. It worked then and it worked this time too. Makes me feel good about the community :-)

     

    It's true, danne suggested this for any assistance and I got it, thanks to you danne.

    And many thanks to Wok and Rarek for suggesting and helping me! :)

  8. Well, I tried to cast it, I'm pretty sure I'm on the right track but I cannot seem to fix the error.

    Here's what I want... I want the program to check if the string value contains integers only so I can cast it to an int rather than a string as it starts off as a string.

    I think I'm on the right path but I keep getting this error I have no idea how to fix.

     

    NOTE: the bold text below is the addition in comparison to my previous code above.

     

    CODE:

     

    package bubblesort_v2;
     
    import java.util.Scanner;
    import java.lang.*;
     
    public class Bubblesort_v2 {
        
       
        
        public static void main(String[] args) throws InterruptedException
        {//To solve the string to int format is to cast it
            int j;
            Scanner in = new Scanner(System.in);
            
            //finding the length of the Array value by user input
            System.out.print("How many values? - Input in numbers: ");
            int totalvalue = Integer.parseInt(in.nextLine());
            String[] value = new String [totalvalue];
           
            
            //allows user to input values of any sort.
            int y = 1;
            for(j = 0; j < value.length;j++) 
            {
                System.out.print(y + ") Name your values: ");
                value[j] = in.nextLine();
                y += 1;
            }
     
            isInteger(value,value.length);        
     
            System.out.println("\n"+"Unsorted List:");
            for (String element:value)
            {   
                System.out.println(element);
            }
            
            Thread.sleep(1500);
            bubble_srt(value,value.length);
            
                System.out.print("\n"+"Sorted List:\n");
                for(j = 0; j < value.length; j++)
                    
                    System.out.print(value[j]+"  "); 
                    System.out.println("\n\n" + "Ending");
        }
        
        public static void bubble_srt(String[] a, int n)
        {//String[] a  is now a function that allows strings as part of the algorithm same to integer (int n)
        int j, i =0;
          String t;
            for(j = 0; j < n; j++)
            {
                for(i = 1; i < (n-j); i++)
                {
                    if(a[i-1].compareTo(a)>0)//Another way to look at it is: someValue.compareTo(otherValue) and checks if it is positive ("> 0")
                    {
                        t = a[i-1];
                        a[i-1]=a;
                        a=t;
                    }
                }
            }
        }
        
        public static boolean isInteger(String value)
        {
            try
            {
                Integer.parseInt(value);
            }
            catch(NumberFormatException e)
            {
                return false;
            }
          return true;  
        }
     }
  9. I will look at it on that aspect. Thanks Rarek!

    If I solve it, I'll post the solution here!

    Cheers!

    Hmm... Perhaps I should cast it... I'll figure that out

     

    P.S. My IT class is actually using Python, but I prefer Java myself so I was able to come to a compromise with my teacher to allow me to use Java for the projects. (Useless bit of information :D)

×
×
  • Create New...