Advertisement
Guest User

Untitled

a guest
Jan 13th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.14 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import javafx.application.Application;
  4. import javafx.scene.image.Image;
  5. import javafx.stage.Stage;
  6. import javafx.event.ActionEvent;
  7. import javafx.event.EventHandler;
  8. import javafx.scene.input.MouseEvent;
  9. import javafx.scene.Scene;
  10. import javafx.scene.control.*;
  11. import javafx.scene.layout.GridPane;
  12. import javafx.scene.layout.BorderPane;
  13. import javafx.geometry.Insets;
  14.  
  15.  
  16. public class Save extends Application{
  17.  
  18.  
  19. public void start( Stage stage ) {
  20. stage.getIcons().add(new Image("Globe.png"));
  21. stage.setTitle("");
  22.  
  23. Animal cat = new Animal();
  24. Animal dog = new Animal();
  25.  
  26. GridPane gridPane = new GridPane();
  27. gridPane.setPadding( new Insets(65, 65, 65 , 65) );
  28. gridPane.setVgap(10); // gap between cells
  29. gridPane.setHgap(10); // gap between cells
  30.  
  31. Button button = new Button( "Step" );
  32. GridPane.setConstraints( button, 0, 1 );
  33. gridPane.getChildren().add(new Label("Press:"));
  34. gridPane.getChildren().add( button );
  35.  
  36.  
  37. button.setOnAction( new EventHandler<ActionEvent>() {
  38. @Override
  39. public void handle( ActionEvent e ) {
  40.  
  41. AnimalState.stateAnimal();
  42.  
  43. }
  44. });
  45.  
  46. button.addEventHandler( MouseEvent.MOUSE_ENTERED,
  47. new EventHandler<MouseEvent>() {
  48. @Override
  49. public void handle(MouseEvent e) {
  50. }
  51. });
  52.  
  53. ScrollPane scrollPane = new ScrollPane();
  54. scrollPane.setContent( gridPane );
  55.  
  56. stage.setScene( new Scene( new BorderPane( scrollPane, null, null, null,
  57. null ) ) );
  58.  
  59. stage.show();
  60. }
  61.  
  62. public static void main( String[] args ) {
  63. launch( args );
  64. }
  65. }
  66.  
  67. public class Animal
  68. {
  69. public static String NAME = "Cat";
  70. public int ID = hashCode();
  71. public static int ADULT_WEIGHT = 10;
  72. public static float FOOD_QUANTITY_REQUIRED_PER_HOUR = 2;
  73. public static int MAX_STARVING_HOURS_BEFORE_DEATH = 24 ;
  74. public static int hoursSinceLastMeal = 3;
  75. public static int energyPercent = 87;
  76. public static int MAX_ENERGY_PERCENT = 120;
  77. public static int STANDARD_SPEED = 2;
  78. public static int MAX_SPEED = 10;
  79. public static int MAX_STAMINA = 23;
  80. public static int AVERAGE_SCION_COUNT_IN_LITTER = 3;
  81. public static int MAX_SCION_COUNT_IN_LITTER = 6;
  82. public static int MAX_AGE = 15;
  83. public static int MIN_BREEDING_AGE = 3;
  84. public static int MAX_BREEDING_AGE = 12;
  85. public static int MAX_AGE_IN_NEST = 1;
  86. public static int MIN_SELF_GOVERNMENT_AGE = 3;
  87. public static int age = 17;
  88. public static String GENDER = "male";
  89. public static boolean isProliferating = false;
  90. public static boolean isFeedingNewborns = true;
  91. public static String TIME_OF_BIRTH = "1999.03.08";
  92. public static String TIME_OF_DEATH;
  93. public static int weight = 3;
  94. public static float ENERGETIC_EFFICIENCY_PER_KILO = 3;
  95.  
  96.  
  97. public int getId() {
  98. return hashCode();
  99. }
  100.  
  101. public Animal() {
  102. new AnimalSpecification( NAME, ID, ADULT_WEIGHT,
  103. FOOD_QUANTITY_REQUIRED_PER_HOUR, MAX_STARVING_HOURS_BEFORE_DEATH,
  104. MAX_ENERGY_PERCENT, STANDARD_SPEED, MAX_SPEED, MAX_STAMINA,
  105. AVERAGE_SCION_COUNT_IN_LITTER, MAX_SCION_COUNT_IN_LITTER, MAX_AGE,
  106. MIN_BREEDING_AGE, MAX_BREEDING_AGE, MAX_AGE_IN_NEST,
  107. MIN_SELF_GOVERNMENT_AGE, GENDER, TIME_OF_BIRTH, TIME_OF_DEATH,
  108. ENERGETIC_EFFICIENCY_PER_KILO);
  109. new AnimalState( ID, hoursSinceLastMeal, energyPercent, age,
  110. isProliferating, isFeedingNewborns, weight, NAME );
  111. }
  112.  
  113. }
  114.  
  115. import java.util.*;
  116. import java.io.*;
  117. import java.io.FileNotFoundException;
  118.  
  119. public class AnimalState {
  120.  
  121. private static final String FILENAME = "contacts.txt";
  122. public String str;
  123. private static int i = 1;
  124.  
  125. public static int ID;
  126. public static int hoursSinceLastMeal;
  127. public static int energyPercent;
  128. public static int age;
  129. public static boolean isProliferating;
  130. public static boolean isFeedingNewborns;
  131. public static int weight;
  132. public static String NAME;
  133.  
  134. public AnimalState( int ID, int hoursSinceLastMeal, int energyPercent, int age, boolean isProliferating, boolean isFeedingNewborns, int weight, String NAME){
  135. this.ID = ID;
  136. this.hoursSinceLastMeal = hoursSinceLastMeal;
  137. this.energyPercent = energyPercent;
  138. this.age = age;
  139. this.isProliferating = isProliferating;
  140. this.isFeedingNewborns = isFeedingNewborns;
  141. this.weight = weight;
  142. this.NAME = NAME;
  143. String.format("%s %s %s %s %s %s %s", ID, hoursSinceLastMeal, energyPercent, age, isProliferating, isFeedingNewborns, weight, NAME);
  144.  
  145. BufferedWriter bw = null;
  146. FileWriter fw = null;
  147.  
  148.  
  149. try {
  150.  
  151. fw = new FileWriter(FILENAME, true);
  152. bw = new BufferedWriter(fw);
  153. bw.write(NAME + "Log:n");
  154. bw.write("Hours Since Last Meal - " + hoursSinceLastMeal + "n");
  155. bw.write("Enery Percent - " + energyPercent + "n");
  156. bw.write("Age - " + age + "n");
  157. bw.write("Proliferating - " + isProliferating + "n");
  158. bw.write("Feeding Newborns - " + isFeedingNewborns + "n");
  159. bw.write("Weight - " + weight + "n");
  160. bw.write("________________________________________________nn");
  161. }
  162. catch(IOException ex){
  163. ex.printStackTrace();
  164. }finally {
  165. try {
  166. if (bw != null)
  167. bw.close();
  168. if (fw != null)
  169. fw.close();
  170. } catch (IOException ex) {
  171. ex.printStackTrace();
  172. }
  173. }
  174.  
  175. }
  176.  
  177. public static void stateAnimal(){
  178.  
  179. BufferedWriter bw = null;
  180. FileWriter fw = null;
  181.  
  182. try {
  183.  
  184. String str2 = String.valueOf(isProliferating);
  185. String str3 = String.valueOf(isFeedingNewborns);
  186.  
  187. fw = new FileWriter(FILENAME, true);
  188. bw = new BufferedWriter(fw);
  189.  
  190. bw.write("Step №" + i + "n");
  191.  
  192. bw.write( "ID = " + ID + ": " );
  193. bw.write( hoursSinceLastMeal + ", " );
  194. bw.write( energyPercent + ", " );
  195. bw.write( age + ", " );
  196. bw.write( str2 + ", " );
  197. bw.write( str3 + ", " );
  198. bw.write( weight + "n");
  199. bw.write("-------------------------------------nn");
  200.  
  201. ++i;
  202.  
  203. }
  204. catch(IOException ex){
  205. ex.printStackTrace();
  206. }finally {
  207. try {
  208. if (bw != null)
  209. bw.close();
  210. if (fw != null)
  211. fw.close();
  212. } catch (IOException ex) {
  213. ex.printStackTrace();
  214. }
  215. }
  216. }
  217.  
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement