Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.util.Scanner;
- public class DN08 {
- public static void main(String[] args)throws Exception{
- Planeti planeti = new Planeti("planeti.txt");
- System.out.println(planeti.seznam[1]);
- }
- }
- class Planeti{
- Planet[] seznam;
- Planeti(String vir)throws Exception{
- this.seznam = preberi(vir);
- }
- Planet [] preberi(String vir) throws Exception{
- Scanner sc = new Scanner(new File("src/" + vir));
- seznam = new Planet[9];
- int i = 0;
- int k = 0;
- while(sc.hasNextLine()){
- String vrstica = sc.nextLine();
- if(vrstica.indexOf(':') > 0){
- String[] podatki = vrstica.split(":");
- seznam[k] = new Planet(podatki[0],Integer.parseInt(podatki[1]));
- k++;
- }
- i++;
- }
- return seznam;
- }
- }
- class Planet{
- String ime;
- int radij;
- Planet(String ime, int radij){
- this.ime = ime;
- this.radij = radij;
- }
- double povrsina(){
- return Math.PI * Math.pow(radij,2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement