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 figury.zad6;
- import java.util.LinkedList;
- /**
- *
- * @author bomba
- */
- public class Obraz {
- private final LinkedList<Trójkąt> TroList = new LinkedList<>();
- private final LinkedList<Czworokąt> CzoList = new LinkedList<>();
- public void dodajCzworokąt(Czworokąt ABCD){
- CzoList.add(ABCD);
- }
- public void dodajTrójkąt(Trójkąt ABC){
- TroList.add(ABC);
- }
- public void wypiszCzworokąt(int index){
- try{
- Czworokąt ABCD = CzoList.get(index);
- System.out.println(ABCD);
- }
- catch(IndexOutOfBoundsException e){
- System.out.println("Czworokąt z podanym indexem nie istnieje");
- }
- }
- public void wypiszTrójkąt(int index){
- try{
- Trójkąt ABC = TroList.get(index);
- System.out.println(ABC);
- }
- catch(IndexOutOfBoundsException e){
- System.out.println("Trójkąt z podanym indexem nie istnieje");
- }
- }
- public void przesunCzworokąt(int dx, int dy, int index){
- try{
- Czworokąt ABCD = CzoList.get(index);
- ABCD.przesun(dx, dy);
- CzoList.remove(index);
- CzoList.add(index, ABCD);
- }
- catch(IndexOutOfBoundsException e){
- System.out.println("Czworokąt o podanym indexie nie istnieje");
- }
- }
- public void przesunTrójkąt(int dx, int dy, int index){
- try{
- Trójkąt ABC = TroList.get(index);
- ABC.przesun(dx, dy);
- TroList.remove(index);
- TroList.add(index, ABC);
- }
- catch(IndexOutOfBoundsException e){
- System.out.println("Trójkąt o podanym indexie nie istnieje");
- }
- }
- public void przesunWszystkieCzworokąty(int dx, int dy){
- for(int i=0; i<CzoList.size(); i++){
- Czworokąt ABCD = CzoList.get(i);
- ABCD.przesun(dx, dy);
- CzoList.remove(i);
- CzoList.add(i, ABCD);
- }
- }
- public void przesunWszystkieTrójkąty(int dx, int dy){
- for(int i=0; i<TroList.size(); i++){
- Trójkąt ABC = TroList.get(i);
- ABC.przesun(dx, dy);
- TroList.remove(i);
- TroList.add(i, ABC);
- }
- }
- public void wypiszWszystkieCzworokąty(){
- if(!CzoList.isEmpty())
- for(int i=0; i<CzoList.size(); i++) System.out.println(CzoList.get(i));
- else System.out.println("Lista jest pusta");
- }
- public void wypiszWszystkieTrójkąty(){
- if(!TroList.isEmpty())
- for(int i=0; i<TroList.size(); i++) System.out.println(TroList.get(i));
- else System.out.println("Lista jest pusta");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement