• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Program : Package installer  RSS feed

 
Aisha Bhatia
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


May you please help in writing a java program which should accept an array of strings defining dependencies. Each string contains the name of a package followed by a colon and space, then any dependencies required by that package. For simplicity we’ll assume a package can have at most one dependency. The program should output a comma separated list of package names in the order of install, such that a package’s dependency will always precede that package. The program should reject as invalid a dependency specification that contains cycles.

Example of valid input KittenService: Leetmeme: Cyberportal Cyberportal: Ice CamelCaser: KittenService Fraudstream: Leetmeme Ice:

A valid output for the above would be:

KittenService, Ice, Cyberportal, Leetmeme, CamelCaser, Fraudstream

Example of input that should be rejected (contains cycles) KittenService: Leetmeme: Cyberportal Cyberportal: Ice CamelCaser: KittenService Fraudstream: Ice: Leetmeme


am planning to take the input in a map. May you please explain me what logic should I apply.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

How would you do that on paper? When you have worked that out you can turn that to code quite easily.

You appear to have arrived in the wrong forum; I shall try moving you.
 
Aisha Bhatia
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah I want to code. I was new to Java ranch and don;t know where to post .
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot do anything in code until you know what you are going to do. Write down the algorithm for your task.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!