Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package oop3;
  7.  
  8. import javafx.application.Application;
  9. import javafx.event.ActionEvent;
  10. import javafx.event.EventHandler;
  11. import javafx.scene.Scene;
  12. import javafx.scene.control.Button;
  13. import javafx.scene.layout.StackPane;
  14. import javafx.stage.Stage;
  15.  
  16. /**
  17. *
  18. * @author spinx
  19. */
  20. import java.io.File;
  21. import java.io.FileNotFoundException;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. import java.util.Scanner;
  25.  
  26. //
  27. public class App {
  28.  
  29. public static void one(){
  30. System.out.println("HELLOO");
  31. }
  32.  
  33. public static void main(String[] args) {
  34.  
  35. List<Category> kategorijos = new ArrayList<Category>();
  36.  
  37. try {
  38. File f = new File("C:\\Users\\Mantas\\IdeaProjects\\GUI1\\src\\com\\pakas\\kategorijos.txt");
  39. Scanner sc = new Scanner(f);
  40.  
  41. while(sc.hasNextLine()){
  42. String line = sc.nextLine();
  43. String[] details = line.split(";");
  44. int id = Integer.parseInt(details[0]);
  45. String name = details[1];
  46. Category kategorija = new Category(name, id);
  47. kategorijos.add(kategorija);
  48. }
  49.  
  50. for(Category kategorija: kategorijos){
  51. System.out.println(kategorija.getCategoryName());
  52. System.out.println(kategorija.getCategoryId());
  53. }
  54.  
  55. } catch (FileNotFoundException e) {
  56. e.printStackTrace();
  57. }
  58.  
  59.  
  60. try {
  61. File f = new File("C:\\Users\\Mantas\\IdeaProjects\\GUI1\\src\\com\\pakas\\patiekalai.txt");
  62. Scanner sc = new Scanner(f);
  63.  
  64. while(sc.hasNextLine()){
  65. String line = sc.nextLine();
  66. String[] details = line.split(";");
  67. int id = Integer.parseInt(details[0]);
  68. int categoryId = Integer.parseInt(details[1]);
  69. String name = details[2];
  70. double price = Double.parseDouble(details[3]);
  71. String info = details[4];
  72. String image = details[5];
  73. Meal meal = new Meal(id,categoryId,name,price,info,image);
  74.  
  75. for (Category k: kategorijos){
  76. if(k.getCategoryId() == categoryId){
  77. k.addMeal(meal);
  78. }
  79. }
  80. }
  81.  
  82.  
  83. } catch (FileNotFoundException e) {
  84. e.printStackTrace();
  85. }
  86.  
  87.  
  88.  
  89.  
  90. }
  91. }
  92.  
  93. class Category {
  94.  
  95. private String name;
  96. private int id;
  97. private List<Meal> allMeals = new ArrayList<Meal>();
  98. public Category(String name, int id){
  99. this.name = name;
  100. this.id = id;
  101. this.allMeals = allMeals;
  102. }
  103. public String getCategoryName() {
  104. return name;
  105. }
  106. public int getCategoryId() {
  107. return id;
  108. }
  109. public String toString(){
  110. return this.id + " " + this.name;
  111. }
  112. //del to tau reikia naujo metodo
  113. public void addMeal(Meal meal){
  114. this.allMeals.add(meal);
  115. }
  116. }
  117. class Meal {
  118. private int id;
  119. private int categoryId;
  120. private String name;
  121. private double price;
  122. private String info;
  123. private String image;
  124.  
  125. public Meal(int id, int categoryId,String name,double price,String info,String image){
  126.  
  127. this.id = id;
  128. this.categoryId = categoryId;
  129. this.name = name;
  130. this.price = price;
  131. this.info = info;
  132. this.image = image;
  133. }
  134.  
  135. public int getId() {
  136. return id;
  137. }
  138. public int getCategoryId(){
  139. return categoryId;
  140. }
  141. public String getName(){
  142. return name;
  143. }
  144. public double getPrice(){
  145. return price;
  146. }
  147. public String getInfo(){
  148. return info;
  149. }
  150. public String getImage(){
  151. return image;
  152. }
  153. public String toString(){
  154. return this.id + " " + this.categoryId+ " " + this.name+ " " + this.price+ " " + this.info+ " " + this.image;
  155. }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement