Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import javafx.application.Application;
- import javafx.scene.image.Image;
- import javafx.stage.Stage;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.scene.input.MouseEvent;
- import javafx.scene.Scene;
- import javafx.scene.control.*;
- import javafx.scene.layout.GridPane;
- import javafx.scene.layout.BorderPane;
- import javafx.geometry.Insets;
- public class Save extends Application{
- public void start( Stage stage ) {
- stage.getIcons().add(new Image("Globe.png"));
- stage.setTitle("");
- Animal cat = new Animal();
- Animal dog = new Animal();
- GridPane gridPane = new GridPane();
- gridPane.setPadding( new Insets(65, 65, 65 , 65) );
- gridPane.setVgap(10); // gap between cells
- gridPane.setHgap(10); // gap between cells
- Button button = new Button( "Step" );
- GridPane.setConstraints( button, 0, 1 );
- gridPane.getChildren().add(new Label("Press:"));
- gridPane.getChildren().add( button );
- button.setOnAction( new EventHandler<ActionEvent>() {
- @Override
- public void handle( ActionEvent e ) {
- AnimalState.stateAnimal();
- }
- });
- button.addEventHandler( MouseEvent.MOUSE_ENTERED,
- new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent e) {
- }
- });
- ScrollPane scrollPane = new ScrollPane();
- scrollPane.setContent( gridPane );
- stage.setScene( new Scene( new BorderPane( scrollPane, null, null, null,
- null ) ) );
- stage.show();
- }
- public static void main( String[] args ) {
- launch( args );
- }
- }
- public class Animal
- {
- public static String NAME = "Cat";
- public int ID = hashCode();
- public static int ADULT_WEIGHT = 10;
- public static float FOOD_QUANTITY_REQUIRED_PER_HOUR = 2;
- public static int MAX_STARVING_HOURS_BEFORE_DEATH = 24 ;
- public static int hoursSinceLastMeal = 3;
- public static int energyPercent = 87;
- public static int MAX_ENERGY_PERCENT = 120;
- public static int STANDARD_SPEED = 2;
- public static int MAX_SPEED = 10;
- public static int MAX_STAMINA = 23;
- public static int AVERAGE_SCION_COUNT_IN_LITTER = 3;
- public static int MAX_SCION_COUNT_IN_LITTER = 6;
- public static int MAX_AGE = 15;
- public static int MIN_BREEDING_AGE = 3;
- public static int MAX_BREEDING_AGE = 12;
- public static int MAX_AGE_IN_NEST = 1;
- public static int MIN_SELF_GOVERNMENT_AGE = 3;
- public static int age = 17;
- public static String GENDER = "male";
- public static boolean isProliferating = false;
- public static boolean isFeedingNewborns = true;
- public static String TIME_OF_BIRTH = "1999.03.08";
- public static String TIME_OF_DEATH;
- public static int weight = 3;
- public static float ENERGETIC_EFFICIENCY_PER_KILO = 3;
- public int getId() {
- return hashCode();
- }
- public Animal() {
- new AnimalSpecification( NAME, ID, ADULT_WEIGHT,
- FOOD_QUANTITY_REQUIRED_PER_HOUR, MAX_STARVING_HOURS_BEFORE_DEATH,
- MAX_ENERGY_PERCENT, STANDARD_SPEED, MAX_SPEED, MAX_STAMINA,
- AVERAGE_SCION_COUNT_IN_LITTER, MAX_SCION_COUNT_IN_LITTER, MAX_AGE,
- MIN_BREEDING_AGE, MAX_BREEDING_AGE, MAX_AGE_IN_NEST,
- MIN_SELF_GOVERNMENT_AGE, GENDER, TIME_OF_BIRTH, TIME_OF_DEATH,
- ENERGETIC_EFFICIENCY_PER_KILO);
- new AnimalState( ID, hoursSinceLastMeal, energyPercent, age,
- isProliferating, isFeedingNewborns, weight, NAME );
- }
- }
- import java.util.*;
- import java.io.*;
- import java.io.FileNotFoundException;
- public class AnimalState {
- private static final String FILENAME = "contacts.txt";
- public String str;
- private static int i = 1;
- public static int ID;
- public static int hoursSinceLastMeal;
- public static int energyPercent;
- public static int age;
- public static boolean isProliferating;
- public static boolean isFeedingNewborns;
- public static int weight;
- public static String NAME;
- public AnimalState( int ID, int hoursSinceLastMeal, int energyPercent, int age, boolean isProliferating, boolean isFeedingNewborns, int weight, String NAME){
- this.ID = ID;
- this.hoursSinceLastMeal = hoursSinceLastMeal;
- this.energyPercent = energyPercent;
- this.age = age;
- this.isProliferating = isProliferating;
- this.isFeedingNewborns = isFeedingNewborns;
- this.weight = weight;
- this.NAME = NAME;
- String.format("%s %s %s %s %s %s %s", ID, hoursSinceLastMeal, energyPercent, age, isProliferating, isFeedingNewborns, weight, NAME);
- BufferedWriter bw = null;
- FileWriter fw = null;
- try {
- fw = new FileWriter(FILENAME, true);
- bw = new BufferedWriter(fw);
- bw.write(NAME + "Log:n");
- bw.write("Hours Since Last Meal - " + hoursSinceLastMeal + "n");
- bw.write("Enery Percent - " + energyPercent + "n");
- bw.write("Age - " + age + "n");
- bw.write("Proliferating - " + isProliferating + "n");
- bw.write("Feeding Newborns - " + isFeedingNewborns + "n");
- bw.write("Weight - " + weight + "n");
- bw.write("________________________________________________nn");
- }
- catch(IOException ex){
- ex.printStackTrace();
- }finally {
- try {
- if (bw != null)
- bw.close();
- if (fw != null)
- fw.close();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- }
- public static void stateAnimal(){
- BufferedWriter bw = null;
- FileWriter fw = null;
- try {
- String str2 = String.valueOf(isProliferating);
- String str3 = String.valueOf(isFeedingNewborns);
- fw = new FileWriter(FILENAME, true);
- bw = new BufferedWriter(fw);
- bw.write("Step №" + i + "n");
- bw.write( "ID = " + ID + ": " );
- bw.write( hoursSinceLastMeal + ", " );
- bw.write( energyPercent + ", " );
- bw.write( age + ", " );
- bw.write( str2 + ", " );
- bw.write( str3 + ", " );
- bw.write( weight + "n");
- bw.write("-------------------------------------nn");
- ++i;
- }
- catch(IOException ex){
- ex.printStackTrace();
- }finally {
- try {
- if (bw != null)
- bw.close();
- if (fw != null)
- fw.close();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement