Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package oop3;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.layout.StackPane;
- import javafx.stage.Stage;
- /**
- *
- * @author spinx
- */
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- //
- public class App {
- public static void one(){
- System.out.println("HELLOO");
- }
- public static void main(String[] args) {
- List<Category> kategorijos = new ArrayList<Category>();
- try {
- File f = new File("C:\\Users\\Mantas\\IdeaProjects\\GUI1\\src\\com\\pakas\\kategorijos.txt");
- Scanner sc = new Scanner(f);
- while(sc.hasNextLine()){
- String line = sc.nextLine();
- String[] details = line.split(";");
- int id = Integer.parseInt(details[0]);
- String name = details[1];
- Category kategorija = new Category(name, id);
- kategorijos.add(kategorija);
- }
- for(Category kategorija: kategorijos){
- System.out.println(kategorija.getCategoryName());
- System.out.println(kategorija.getCategoryId());
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- try {
- File f = new File("C:\\Users\\Mantas\\IdeaProjects\\GUI1\\src\\com\\pakas\\patiekalai.txt");
- Scanner sc = new Scanner(f);
- while(sc.hasNextLine()){
- String line = sc.nextLine();
- String[] details = line.split(";");
- int id = Integer.parseInt(details[0]);
- int categoryId = Integer.parseInt(details[1]);
- String name = details[2];
- double price = Double.parseDouble(details[3]);
- String info = details[4];
- String image = details[5];
- Meal meal = new Meal(id,categoryId,name,price,info,image);
- for (Category k: kategorijos){
- if(k.getCategoryId() == categoryId){
- k.addMeal(meal);
- }
- }
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- }
- class Category {
- private String name;
- private int id;
- private List<Meal> allMeals = new ArrayList<Meal>();
- public Category(String name, int id){
- this.name = name;
- this.id = id;
- this.allMeals = allMeals;
- }
- public String getCategoryName() {
- return name;
- }
- public int getCategoryId() {
- return id;
- }
- public String toString(){
- return this.id + " " + this.name;
- }
- //del to tau reikia naujo metodo
- public void addMeal(Meal meal){
- this.allMeals.add(meal);
- }
- }
- class Meal {
- private int id;
- private int categoryId;
- private String name;
- private double price;
- private String info;
- private String image;
- public Meal(int id, int categoryId,String name,double price,String info,String image){
- this.id = id;
- this.categoryId = categoryId;
- this.name = name;
- this.price = price;
- this.info = info;
- this.image = image;
- }
- public int getId() {
- return id;
- }
- public int getCategoryId(){
- return categoryId;
- }
- public String getName(){
- return name;
- }
- public double getPrice(){
- return price;
- }
- public String getInfo(){
- return info;
- }
- public String getImage(){
- return image;
- }
- public String toString(){
- return this.id + " " + this.categoryId+ " " + this.name+ " " + this.price+ " " + this.info+ " " + this.image;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement