Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.Talar;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.Scanner;
- public class Kolekcja {
- public int rozmiar;
- Czolgi[] zbior;
- public int zapelnienie = 0;
- public Kolekcja(int maxValue){
- this.rozmiar = maxValue;
- zbior = new Czolgi[rozmiar];
- }
- public void dodajCzolg(Czolgi c){
- for(int i = 0; i < zbior.length; i++){
- if(zbior[i] == null){
- zbior[i] = c;
- zapelnienie++;
- break;
- }
- }
- }
- public void wyswietlIndeksy(){
- for(int i = 0; i < zbior.length; i++){
- if(zbior[i]!=null) System.out.print(i + " - " + zbior[i].nazwa + '\n');
- }
- }
- public void wyswietlWszystko(){
- for(int i = 0; i < zbior.length; i++){
- if(zbior[i] != null){
- zbior[i].wyswietlDane();
- }
- }
- }
- public void usunCzolg(){
- Scanner inp = new Scanner(System.in);
- this.wyswietlIndeksy();
- System.out.print("Wprowadź indeks do usunięcia: "); int indeks = inp.nextInt();
- if(indeks < zbior.length && indeks >= 0){
- zbior[indeks] = null;
- zapelnienie--;
- }
- }
- public void edytujCzolg(){
- Scanner inp = new Scanner(System.in);
- this.wyswietlIndeksy();
- System.out.print("Wprowadź indeks do edycji: "); int indeks = inp.nextInt();
- if(indeks < zbior.length && indeks >= 0){
- zbior[indeks].ustawWartosci();
- }
- }
- public void edytujCeny(double modyfikator){
- for(int i = 0; i < zbior.length; i++){
- if(zbior[i] != null){
- zbior[i].cena *= modyfikator;
- }
- }
- }
- public void zapisDoPliku(String nazwaPliku) throws IOException{
- String defaultPath = "/Users/talar/IdeaProjects/Lab07/src/com/Talar/";
- FileWriter zapis = new FileWriter(defaultPath+nazwaPliku + ".txt", true);
- for(int i = 0; i < zbior.length; i++){
- if(zbior[i] != null){
- zapis.write(zbior[i].nazwa + "; " + zbior[i].typ + "; " + zbior[i].cena
- + "; " + zbior[i].pancerz_przod + "; " + zbior[i].kaliber + "; " + zbior[i].skutecznosc + "; \n");
- }
- }
- zapis.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement