Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Jedzie:
- package zad3;
- public interface Jedzie {
- public void jedz(int ile);
- }
- Pływa:
- package zad3;
- public interface Plywa {
- public void plyn();
- }
- Pociąg:
- package zad3;
- public class Pociag extends Pojazd implements Jedzie{
- public Pociag(String nazwa, int predkosc) {
- super(nazwa, predkosc);
- }
- public void jedz(int ile) { /// ten argument tu nic nie robi!!!! ale musi być bo interfejs go ma!!! Co za badziew...
- System.out.println("nazwa pojazdu: " + getNazwa());
- System.out.println("dlugosc trasy: nie wiem skąd mam to wziąć :(");
- }
- public void info() {
- System.out.println(getClass());
- System.out.println("nazwa: " + getNazwa());
- System.out.println("predkosc: " + getPredkosc());
- jedz(0);
- System.out.println("");
- }
- }
- Pojazd:
- package zad3;
- public abstract class Pojazd {
- private String nazwa;
- private int predkosc;
- public Pojazd(String nazwa, int predkosc){
- this.nazwa = nazwa;
- this.predkosc = predkosc;
- }
- public String getNazwa() {
- return nazwa;
- }
- public int getPredkosc() {
- return predkosc;
- }
- public void przyspiesz(int ile){
- predkosc += ile;
- }
- public void zwolnij(int ile){
- predkosc -= ile;
- }
- public abstract void info();
- }
- Samochód:
- package zad3;
- public class Samochod extends Pojazd implements Jedzie{
- private String marka;
- private int przebieg;
- public Samochod(String nazwa, int predkosc) {
- super(nazwa, predkosc);
- }
- public String getMarka() {
- return marka;
- }
- public void setMarka(String marka) {
- this.marka = marka;
- }
- public int getPrzebieg() {
- return przebieg;
- }
- public void setPrzebieg(int przebieg) {
- this.przebieg = przebieg;
- }
- public void jedz(int ile) {
- this.przebieg += ile;
- System.out.println("nazwa pojazdu: " + getNazwa());
- System.out.println("dlugosc trasy: " + getPrzebieg());
- }
- public void info() {
- System.out.println(getClass());
- System.out.println("nazwa: " + getNazwa());
- System.out.println("predkosc: " + getPredkosc());
- jedz(0);
- System.out.println("");
- }
- }
- Statek:
- package zad3;
- public class Statek extends Pojazd implements Plywa{
- public Statek(String nazwa, int predkosc) {
- super(nazwa, predkosc);
- }
- public void plyn() {
- System.out.println("nazwa pojazdu: " + getNazwa());
- System.out.println("dlugosc trasy: nie wiem skąd mam to wziąć :(");
- }
- public void info() {
- System.out.println(getClass());
- System.out.println("nazwa: " + getNazwa());
- System.out.println("predkosc: " + getPredkosc());
- plyn();
- System.out.println("");
- }
- }
- Zad3.java:
- package zad3;
- public class Zad3{
- public static void main(String[] args) {
- Pojazd pojazdy[] = new Pojazd[6];
- pojazdy[0] = new Pociag("ZS", 25);
- pojazdy[1] = new Statek("ASD", 20);
- pojazdy[2] = new Samochod("XD", 30);
- pojazdy[3] = new Pociag("ZASDS", 55);
- pojazdy[4] = new Statek("ASASDFD", 50);
- pojazdy[5] = new Samochod("XWQERD", 70);
- for(int i = 0; i < 6; i++){
- pojazdy[i].info();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement