Hi @all
folgendes Anfängerproblem quält mich:
ich habe ein Objekt book.java erstellt
dann soll man drei Bücher mit Titel, Autor, ISBN und Preis eingeben.
klappt auch.
1.Schritt soll sein ja nach Eingabe von 1-4 ( 1= Titel, 2= Autor, 3= ISBN und 4=Preis) die Bücher zu sortieren.
2. Schritt soll sein ja nach Eingabe von 1 (Aufsteigend) und 2 (Absteigend) zu sortieren.
mir ist absolut unklar wie ich da anfangen soll.
bisheriger "Fortschritt":
Vielen Dank im vorraus
folgendes Anfängerproblem quält mich:
ich habe ein Objekt book.java erstellt
dann soll man drei Bücher mit Titel, Autor, ISBN und Preis eingeben.
klappt auch.
1.Schritt soll sein ja nach Eingabe von 1-4 ( 1= Titel, 2= Autor, 3= ISBN und 4=Preis) die Bücher zu sortieren.
2. Schritt soll sein ja nach Eingabe von 1 (Aufsteigend) und 2 (Absteigend) zu sortieren.
mir ist absolut unklar wie ich da anfangen soll.
bisheriger "Fortschritt":
Java:
package grundlagenuebungen;
import javax.swing.JOptionPane;
public class BookSorter
{
public static void main (String [] args )
{
String Titel1 = JOptionPane.showInputDialog (null,"Bitte geben Sie Titel 1 ein: ");
String Autor1 = JOptionPane.showInputDialog (null,"Bitte geben Sie Autor 1 ein: ");
String ISBN1 = JOptionPane.showInputDialog (null,"Bitte geben Sie ISBN 1 ein: ");
String Preis1 = JOptionPane.showInputDialog (null,"Bitte geben Sie Preis 1 ein: ");
String Titel2 = JOptionPane.showInputDialog (null,"Bitte geben Sie Titel 2 ein: ");
String Autor2 = JOptionPane.showInputDialog (null,"Bitte geben Sie Autor 2 ein: ");
String ISBN2 = JOptionPane.showInputDialog (null,"Bitte geben Sie ISBN 2 ein: ");
String Preis2 = JOptionPane.showInputDialog (null,"Bitte geben Sie Preis 2 ein: ");
String Titel3 = JOptionPane.showInputDialog (null,"Bitte geben Sie Titel 3 ein: ");
String Autor3 = JOptionPane.showInputDialog (null,"Bitte geben Sie Autor 3 ein: ");
String ISBN3 = JOptionPane.showInputDialog (null,"Bitte geben Sie ISBN 3 ein: ");
String Preis3 = JOptionPane.showInputDialog (null,"Bitte geben Sie Preis 3 ein: ");
long ISBN11 = Long.parseLong (ISBN1);
long ISBN22 = Long.parseLong (ISBN2);
long ISBN33 = Long.parseLong (ISBN3);
double Preis11 = Double.parseDouble (Preis1);
double Preis22 = Double.parseDouble (Preis2);
double Preis33 = Double.parseDouble (Preis3);
Book Buch1 = new Book ();
Buch1.Titel = Titel1;
Buch1.Autor = Autor1;
Buch1.ISBN = ISBN11;
Buch1.Preis = Preis11;
Book Buch2 = new Book ();
Buch2.Titel = Titel2;
Buch2.Autor = Autor2;
Buch2.ISBN = ISBN22;
Buch2.Preis = Preis22;
Book Buch3 = new Book ();
Buch3.Titel = Titel3;
Buch3.Autor = Autor3;
Buch3.ISBN = ISBN33;
Buch3.Preis = Preis33;
String Buch11 = ("Titel: " + Titel1 + " Autor: " + Autor1 + " ISBN: " + ISBN1 + " Preis: " + Preis1 );
String Buch22 = ("Titel: " + Titel2 + " Autor: " + Autor2 + " ISBN: " + ISBN2 + " Preis: " + Preis2 );
String Buch33 = ("Titel: " + Titel3 + " Autor: " + Autor3 + " ISBN: " + ISBN3 + " Preis: " + Preis3 );
JOptionPane.showMessageDialog (null,"Ihre Auswahl für Buch Nr. 1: " + Buch11);
JOptionPane.showMessageDialog (null,"Ihre Auswahl für Buch Nr. 2: " + Buch22);
JOptionPane.showMessageDialog (null,"Ihre Auswahl für Buch Nr. 3: " + Buch33);
String Sortierung = JOptionPane.showInputDialog (null, "Bitte geben Sie ein ob nach Titel (1), Autor (2), ISBN (3) oder Preis (4) sortiert werden soll");
String AufAbSortierung = JOptionPane.showInputDialog (null, "Bitte geben Sie an ob aufsteigend (1) oder absteigend (2) sortiert werden soll");
Zuletzt bearbeitet von einem Moderator: