initial d
This commit is contained in:
commit
a00a6c6f54
33
.gitignore
vendored
Normal file
33
.gitignore
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
|
||||
# Created by https://www.gitignore.io/api/java
|
||||
# Edit at https://www.gitignore.io/?templates=java
|
||||
|
||||
### Java ###
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
# End of https://www.gitignore.io/api/java
|
||||
|
||||
|
||||
.idea/
|
12
kolos.iml
Normal file
12
kolos.iml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
41
src/Main.java
Normal file
41
src/Main.java
Normal file
@ -0,0 +1,41 @@
|
||||
import kolos.Zamowienie;
|
||||
import kolos.Pozycja;
|
||||
import kolos.StackClass;
|
||||
import kolos.Exceptions;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
Pozycja p1 = new Pozycja("Chleb", 1, 3.5);
|
||||
System.out.println(p1);
|
||||
|
||||
Pozycja p2 = new Pozycja("Cukier", 3, 4);
|
||||
System.out.print(p2);
|
||||
|
||||
Zamowienie z = new Zamowienie(20);
|
||||
z.dodajPozycje(p1);
|
||||
z.dodajPozycje(p2);
|
||||
System.out.println(z);
|
||||
|
||||
StackClass theStack = new StackClass();
|
||||
theStack.push(10);
|
||||
theStack.push(20);
|
||||
theStack.push(30);
|
||||
theStack.push(40);
|
||||
theStack.push(50);
|
||||
|
||||
while (!theStack.isEmpty())
|
||||
{
|
||||
Object value = theStack.pop();
|
||||
System.out.print(value);
|
||||
System.out.print(" ");
|
||||
}
|
||||
System.out.println("");
|
||||
}
|
||||
|
||||
|
||||
Exceptions wyjatki = new Exceptions();
|
||||
wyjatki.xd();
|
||||
}
|
23
src/kolos/Exceptions.java
Normal file
23
src/kolos/Exceptions.java
Normal file
@ -0,0 +1,23 @@
|
||||
package kolos;
|
||||
|
||||
public class Exceptions {
|
||||
|
||||
public void xd() {
|
||||
try {
|
||||
System.out.println("Test NumberFormatException");
|
||||
String str = "jedenaście";
|
||||
int i = Integer.parseInt(str);
|
||||
} catch (NumberFormatException e) {
|
||||
System.out.println("Złapano wyjątek...");
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println("Test ArithmeticException");
|
||||
int i = 10 / 0;
|
||||
} catch (ArithmeticException e) {
|
||||
System.out.println("Złapano wyjątek...");
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
}
|
26
src/kolos/Pozycja.java
Normal file
26
src/kolos/Pozycja.java
Normal file
@ -0,0 +1,26 @@
|
||||
package kolos;
|
||||
|
||||
public class Pozycja {
|
||||
private String nazwaTowaru;
|
||||
private int ileSztuk;
|
||||
private double cena;
|
||||
|
||||
public Pozycja(String nazwaTowaru, int ileSztuk, double cena) {
|
||||
this.nazwaTowaru = nazwaTowaru;
|
||||
this.ileSztuk = ileSztuk;
|
||||
this.cena = cena;
|
||||
}
|
||||
|
||||
public double obliczWartosc() {
|
||||
return this.ileSztuk * this.cena;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("%s, %.2f zł, %d szt. %.2f zł",
|
||||
this.nazwaTowaru,
|
||||
this.cena,
|
||||
this.ileSztuk,
|
||||
this.obliczWartosc()
|
||||
);
|
||||
}
|
||||
}
|
14
src/kolos/Stack.java
Normal file
14
src/kolos/Stack.java
Normal file
@ -0,0 +1,14 @@
|
||||
package kolos;
|
||||
|
||||
public interface Stack {
|
||||
|
||||
public int size();//zwraca liczbę obiektów na stosie
|
||||
public boolean isEmpty();//zwraca true, jeżeli stos jest pusty
|
||||
|
||||
//umieszczenie nowego obiektu na szczycie stosu;
|
||||
public void push(Object o);
|
||||
|
||||
//zdjęcie istniejącego obiektu ze szczytu stosu;
|
||||
public Object pop();
|
||||
|
||||
}
|
32
src/kolos/StackClass.java
Normal file
32
src/kolos/StackClass.java
Normal file
@ -0,0 +1,32 @@
|
||||
package kolos;
|
||||
|
||||
import kolos.Stack;
|
||||
|
||||
public class StackClass implements Stack {
|
||||
|
||||
private int size;
|
||||
private Object[] objects;
|
||||
|
||||
public StackClass() {
|
||||
size = 0;
|
||||
objects = new Object[100];
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return size == 0;
|
||||
}
|
||||
|
||||
public void push(Object o) {
|
||||
if (size < objects.length) {
|
||||
objects[size++] = o;
|
||||
}
|
||||
}
|
||||
|
||||
public Object pop() {
|
||||
return objects[--size];
|
||||
}
|
||||
}
|
49
src/kolos/Zamowienie.java
Normal file
49
src/kolos/Zamowienie.java
Normal file
@ -0,0 +1,49 @@
|
||||
package kolos;
|
||||
|
||||
import kolos.Pozycja;
|
||||
|
||||
public class Zamowienie {
|
||||
private Pozycja[] pozycje;
|
||||
private int ileDodanych;
|
||||
private int maksRozmiar;
|
||||
|
||||
public Zamowienie(int maksRozmiar) {
|
||||
this.ileDodanych = 0;
|
||||
this.maksRozmiar = maksRozmiar;
|
||||
this.pozycje = new Pozycja[maksRozmiar];
|
||||
}
|
||||
|
||||
public Zamowienie() {
|
||||
this(10);
|
||||
}
|
||||
|
||||
public void dodajPozycje(Pozycja p) {
|
||||
if (ileDodanych < maksRozmiar) {
|
||||
pozycje[ileDodanych] = p;
|
||||
ileDodanych++;
|
||||
}
|
||||
}
|
||||
|
||||
public double obliczWartosc() {
|
||||
double wartosc = 0;
|
||||
|
||||
for (int i = 0; i < ileDodanych; i++) {
|
||||
wartosc += pozycje[i].obliczWartosc();
|
||||
}
|
||||
|
||||
return wartosc;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer str = new StringBuffer("\nZamowienie: \n");
|
||||
|
||||
for (int i = 0; i < this.ileDodanych; i++) {
|
||||
str.append(this.pozycje[i].toString());
|
||||
str.append("\n");
|
||||
}
|
||||
|
||||
str.append(String.format("\nRazem: %.2f zł\n", this.obliczWartosc()));
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user