Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.Scanner;
  3.  
  4. public class DN08 {
  5. public static void main(String[] args)throws Exception{
  6. Planeti planeti = new Planeti("planeti.txt");
  7. System.out.println(planeti.seznam[1]);
  8. }
  9. }
  10.  
  11. class Planeti{
  12. Planet[] seznam;
  13.  
  14. Planeti(String vir)throws Exception{
  15. this.seznam = preberi(vir);
  16. }
  17.  
  18. Planet [] preberi(String vir) throws Exception{
  19. Scanner sc = new Scanner(new File("src/" + vir));
  20. seznam = new Planet[9];
  21. int i = 0;
  22. int k = 0;
  23. while(sc.hasNextLine()){
  24. String vrstica = sc.nextLine();
  25. if(vrstica.indexOf(':') > 0){
  26. String[] podatki = vrstica.split(":");
  27. seznam[k] = new Planet(podatki[0],Integer.parseInt(podatki[1]));
  28. k++;
  29. }
  30. i++;
  31. }
  32. return seznam;
  33. }
  34. }
  35.  
  36. class Planet{
  37. String ime;
  38. int radij;
  39.  
  40. Planet(String ime, int radij){
  41. this.ime = ime;
  42. this.radij = radij;
  43. }
  44.  
  45. double povrsina(){
  46. return Math.PI * Math.pow(radij,2);
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement