0

Error: Main method not found in class Pozycja, please define the main method as: public static void main(String[] args) or a

import java.io.*; import java.util.*; public class Pozycja { String nazwaTowaru; int ileSztuk; double cena; public Pozycja (String nazwaTowaru, int ileSztuk, double cena){ this.nazwaTowaru = nazwaTowaru; this.ileSztuk = ileSztuk; this.cena = cena; } public String getNazwaTowaru(){ return NazwaTowaru; } public int getIleSztuk(){ return ileSztuk; } public double getCena(){ return cena; } public double obliczWartosc(){ return this.ileSztuk*this.cena; /*? */ } public String toString(){ return String.format("%.20f",nazwaTowaru) + "; " + String.format("%.10f",cena) + " zł; " + String.format("%.4f",ileSztuk) + " szt; " + String.format("%.10f",obliczWartosc()) + " zł"; }/*? */ public class Zamowienie{ public Pozycja[] pozycje;/*? */ private int ileDodanych; private int maksRozmiar; public Zamowienie (){ this.maksRozmiar = 10; this.ileDodanych = 0; this.pozycje = new Pozycja[this.maksRozmiar]; } Zamowienie(int maksRozmiar){ this.maksRozmiar = maksRozmiar; } public void dodajPozycje(Pozycja p) { if(this.pozycje[ileDodanych] == null){ this.pozycje[ileDodanych] = new Pozycja(p.getNazwaTowaru(), p.getIleSztuk(), p.getCena()); this.ileDodanych++; } } public double obliczWartosc (){ double lacznie = 0.0; for(int i=0; i<ileDodanych; i++){ lacznie += pozycje[i].obliczWartosc(); } return lacznie; } public String toString(){ String napis = "\nZamówienie:\n"; for(int i=0; i<ileDanych; i++){

5th Jan 2020, 9:34 PM
Ivan
11 Antworten
+ 4
Ivan You need a main method to execute your code. So write another class: public class TestClass{ public static void main(String[] args){ //here you do all the stuff you want to do with the other classes } }
5th Jan 2020, 10:40 PM
Denise Roßberg
Denise Roßberg - avatar
+ 3
Your code has no main method this is needed as a starting point for your program to run
5th Jan 2020, 10:35 PM
D_Stark
D_Stark - avatar
+ 1
I structured your code a bit. You need to rework both toString() methods. https://code.sololearn.com/cznxQeT4b29T/?ref=app
5th Jan 2020, 11:37 PM
Denise Roßberg
Denise Roßberg - avatar
0
I don’t know how to insert the main method to make the code work. tried different options
5th Jan 2020, 10:38 PM
Ivan
0
Please help (
5th Jan 2020, 10:38 PM
Ivan
0
write another 3 class or write again? I tried a similar option, but failed. maybe did something wrong
5th Jan 2020, 10:43 PM
Ivan
0
No, you don't need to rewrite anything. Just add another class that contains the main method. It would be best if you save your code in the code playground and share the link here. It would also be helpful to explain your other classes as I don't speak polish. ;) I can look at it tomorrow afternoon/evening.
5th Jan 2020, 11:01 PM
Denise Roßberg
Denise Roßberg - avatar
0
ready, with english translation. thanks
5th Jan 2020, 11:21 PM
Ivan
- 1
Bjh
6th Jan 2020, 4:31 PM
Quentin Mengue
Quentin Mengue - avatar