Question

I need Help PLZ ( Java Code ).

Today 14.06.2019 I have to hand in my homework.

reachability

Actually, you find flying very good, but you do not trust the whole new-fangled flying stuff and the infrastructure it has built up. As a diehard medieval metal fan you prefer to travel from A to B but rather the good old catapult. Since one can not easily take the favorite cat on vacation with it (cats do not get drafts, which is why ICEs are also eliminated), they let themselves be asked to take a plane on vacation. So you are now looking at the network spanned by airports and existing direct connections and wondering which airports are actually critical. A critical airport is an airport whose sudden disappearance would make it impossible to reach all other (remaining) airports from any (remaining) airport. For example, in the following example, the airports ICT and TXL are critical airports, but not BER:

LAS JAV BER IKT! FNJ

So you decide to write a program that will calculate the amount of critical airports for you. You can assume the following assumptions:

At the beginning, all other airports can be reached from any airport.
If a connection from airport
F1 to F2 airport will also consist of a link from F2 airport back to F1.
In the ads.set3.airports package, write a CriticalAirportFinder class and implement the following method:

/ **
* Finds whose removal causes unrealistic destinations. Thus, the
* result must be a set of airports that, if removed, cause at least one pair of
* other airports to have no path between them.
*
* @param airports set of airports.
* @return set of critical airports. Can it be empty?
* airports without a path between them in the input. Must not be
* {@code null}.
* /
public static set findCriticalAirports (Set airports) {
// TODO Implement me!
}

/************* the airport class is ***********************/

package ads.set3.airports;

import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;

/**
* Models an airport. For them to be identifiable, all airports have an
* IATA code and
* two airports are considered equal if their IATA codes match. Since this class
* implements {@link #equals(Object)} and {@link #hashCode()}, it can be used in
* hash-based data structures, such as {@link HashSet}.
*
*


* Each airport has a (possibly empty) set of designations that can be reached
* directly (that is, there are direct flights from this airport to all
* designation airports). If there is a direct flight from this airport to
* another airport, there will be a direct return flight as well.
*


*/
public final class Airport implements Comparable {

   /** The airport's IATA designation. */
   private final String iataDesignation;
   /** Set of airports that can be reached from this airport. */
   private final Set destinations = new HashSet<>();

   /**
   * Creates a new airport with no connected airports.
   *
   * @param iataCode the airport's non-{@code null} IATA designation.
   * @throw IllegalArgumentException if the code is invalid.
   */
   public Airport(String iataCode) {
       ensureValidIataDesignation(iataCode);
       this.iataDesignation = iataCode;
   }

   /**
   * Throws an {@link IllegalArgumentException} if the given String is not a valid
   * IATA designation.
   */
   public static void ensureValidIataDesignation(String iata) {
       if (iata == null) {
           throw new IllegalArgumentException("IATA code cannot be null.");
       }

       if (!Pattern.matches("[a-zA-Z]{3}", iata)) {
           throw new IllegalArgumentException("IATA codes must consist of three characters.");
       }
   }

   /**
   * Returns this airport's IATA designation.
   */
   public String getIataDesignation() {
       return iataDesignation;
   }

   /**
   * Returns the airport's set of destinations that can be reached directly, to be
   * modified at will.
   */
   public Set getDestinations() {
       return destinations;
   }

   @Override
   public boolean equals(Object obj) {
       if (obj instanceof Airport) {
           return ((Airport) obj).getIataDesignation().equals(this.getIataDesignation());
       } else {
           return false;
       }
   }

   @Override
   public int hashCode() {
       return getIataDesignation().hashCode();
   }

   @Override
   public int compareTo(Airport o) {
       return iataDesignation.compareTo(o.iataDesignation);
   }

}

/**********************************************************/

/******* I tried with this code but I still ve a problem with arrive methode , doesnt give me the path between the airports*****/

/********** this verboten parameter means the airports that is removed from the set *****/

0 0
Add a comment Improve this question Transcribed image text
Answer #1
        public static Set<Airport> findCriticalAirports(Set<Airport> airports) {

                Set<Airport> result = new HashSet<>();
                
                Iterator<Airport> iterator = airports.iterator();
                while(iterator.hasNext()) {

                        Airport currentAirport = iterator.next();
                        
                        // we will think that a airport forms a group of its own.
                        HashMap<Airport, Integer> groupParent = new HashMap<>();
                        ArrayList<Airport> otherAirports = new ArrayList<>(airports);
                        otherAirports.remove(currentAirport);
                        
                        int count = 0;

                        for(Airport a: otherAirports) {
                                groupParent.put(a, count++);
                        }

                        for(Airport s: otherAirports) {
                                for(Airport d: s.getDestinations()) {
                                        if(!d.equals(currentAirport)) {

                                                int a = groupParent.get(s);
                                                int b = groupParent.get(d);
                                                
                                                if(a != b) {
                                                        groupParent.put(s, Math.min(a, b));
                                                        groupParent.put(d, Math.min(a, b));
                                                }
                                        }
                                }
                        }
                        
                        if(new HashSet<>(groupParent.values()).size() > 1) {
                                result.add(currentAirport);
                        }
                
                }
                
                return result;
        }
                

Finds airports whose removal causes unreachable destinations. Thus, the 04 result must be a set of airports that, if one is r


Please upvote, as i have given the exact answer as asked in question. Still in case of any issues in code, let me know in comments. Thanks!

Add a comment
Know the answer?
Add Answer to:
I need Help PLZ ( Java Code ). Today 14.06.2019 I have to hand in my...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need Help PLZ ( Java Code ). Tomorrow 05.06.2019 I have to hand in my homework. reachability Actually, you find f...

    I need Help PLZ ( Java Code ). Tomorrow 05.06.2019 I have to hand in my homework. reachability Actually, you find flying very good, but you do not trust the whole new-fangled flying stuff and the infrastructure it has built up. As a diehard medieval metal fan you prefer to travel from A to B but rather the good old catapult. Since one can not easily take the favorite cat on vacation with it (cats do not get drafts, which...

  • I need help with my homework. The task: Actually, you find flying very good, but you...

    I need help with my homework. The task: Actually, you find flying very good, but you do not trust the whole new-fangled flying stuff and the infrastructure it has built up. As a diehard medieval metal fan you prefer to travel from A to B but rather the good old catapult. Since one can not easily take the favorite cat on vacation with it (cats do not get drafts, which is why ICEs are also eliminated), they let themselves be...

  • This is my code that i need to finish. In BoxRegion.java I have no idea how...

    This is my code that i need to finish. In BoxRegion.java I have no idea how to create the constructor. I tried to use super(x,y) but It is hard to apply. And Also In BoxRegionHashTable, I don't know how to create displayAnnotation BoxRegion.java ------------------------------------------------ public final class BoxRegion { final Point2D p1; final Point2D p2; /** * Create a new 3D point with given x, y and z values * * @param x1, y1 are the x,y coordinates for point...

  • Hello in C#. I need help understanding and knwoing what i missed in my program. The...

    Hello in C#. I need help understanding and knwoing what i missed in my program. The issue is, the program is supposed to have user input for 12 family members and at the end of the 12 it asks for user to input a name to search for. When i put a correct name, it always gives me a relative not found message. WHat did i miss. And can you adjust the new code so im able to see where...

  • I need help with adding comments to my code and I need a uml diagram for...

    I need help with adding comments to my code and I need a uml diagram for it. PLs help.... Zipcodeproject.java package zipcodesproject; import java.util.Scanner; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Zipcodesproject { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input=new Scanner(System.in); BufferedReader reader; int code; String state,town; ziplist listOFCodes=new ziplist(); try { reader = new BufferedReader(new FileReader("C:UsersJayDesktopzipcodes.txt")); String line = reader.readLine(); while (line != null) { code=Integer.parseInt(line); line =...

  • I need help with the following Java code Consider a class Fraction of fractions. Each fraction...

    I need help with the following Java code Consider a class Fraction of fractions. Each fraction is signed and has a numerator and a denominator that are integers. Your class should be able to add, subtract, multiply, and divide two fractions. These methods should have a fraction as a parameter and should return the result of the operation as a fraction. The class should also be able to find the reciprocal of a fraction, compare two fractions, decide whether two...

  • Java Programming: Hi, I need help Modifying my code that will throw an IllegalArgumentException. for the...

    Java Programming: Hi, I need help Modifying my code that will throw an IllegalArgumentException. for the following data entry error conditions: A number less than 1 or greater than 12 has been entered for the month A negative integer has been entered for the year utilizes a try and catch clause to display an appropriate message when either of these data entry errors exceptions occur. Thank you let me know if you need more info import java.util.*; //Class definition public...

  • Can someone help me with this code, I not really understanding how to do this? import...

    Can someone help me with this code, I not really understanding how to do this? import java.util.ArrayList; import java.util.HashMap; import java.util.Map; /** * @version Spring 2019 * @author Kyle */ public class MapProblems { /** * Modify and return the given map as follows: if the key "a" has a value, set the key "b" to * have that value, and set the key "a" to have the value "". Basically "b" is confiscating the * value and replacing it...

  • Need Help ASAP!! Below is my code and i am getting error in (public interface stack)...

    Need Help ASAP!! Below is my code and i am getting error in (public interface stack) and in StackImplementation class. Please help me fix it. Please provide a solution so i can fix the error. thank you.... package mazeGame; import java.io.*; import java.util.*; public class mazeGame {    static String[][]maze;    public static void main(String[] args)    {    maze=new String[30][30];    maze=fillArray("mazefile.txt");    }    public static String[][]fillArray(String file)    {    maze = new String[30][30];       try{...

  • *JAVA* Can somebody take a look at my current challenge? I need to throw a different...

    *JAVA* Can somebody take a look at my current challenge? I need to throw a different exception when a)(b is entered. It should throw "Correct number of parenthesis but incorrect syntax" The code is as follows. Stack class: public class ArrayStack<E> {    private int top, size;    private E arrS[];    private static final int MAX_STACK_SIZE = 10;    public ArrayStack() {        this.arrS = (E[]) new Object[MAX_STACK_SIZE];        this.top = size;        this.size = 0;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT