Hello forum, Vaironl here.
I have to do an assignment for school and I was about 3 hours designing the prototype and everything was going right but I had to add arrays and a for loop to my system and after that everything just got ugly. Therefore I started from reading a file and for some reason everything works fine except printing the variable I get from the file.... Is confusing but here it is.
This is a custom class BTW.
import java.util.*;
import java.io.*;
public class read {
//variables
private File file = new File("C:\\Users\\Vairon\\Documents\\Learning Java\\ReadingFiles\\src\\snakes.txt");
private String[] name = new String[4];
private String snake; private boolean power; private int age; private double weight;
//method1
public void readf(){
try{
Scanner scanner = new Scanner(file);
while(scanner.hasNextLine()){
name[0]= scanner.next();//add stuff after each name
name[1]= scanner.next();
name[2]= scanner.next();
name[3]= scanner.next();
System.out.println("Success \n \n");
}
}
catch(FileNotFoundException e){
e.printStackTrace();
}
}
/*
public void convert(String snake, boolean power, int age, double weight){
snake = name[0];
power = Boolean.parseBoolean(name[1]);
age = Integer.parseInt(name[2]);
weight = Double.parseDouble(name[3]);
}
*/
public void convert(String snake){
snake = name[0];
}
public String getName(){
return snake;
}
public void showName(){
System.out.printf(" name is %s",snake);
}
}