Muss ein Programm schreiben. HILFE!

chinji

Grünschnabel
Hallo an alle :-)

wie bereits erwähnt muss ich ein Programm schreiben.
Aber ich bin noch ziemlich änfanger in java und weiß überhaupt nicht, wie ich das funktioniert.

Also das Programm soll so aussehen:

Produkt Nr. | ID | PW

1.............| 123 | passwort
2.............| 456 | passwort2
usw

wenn man nun die produkt nummer eingibt sollen die anderen 2 werte angezeigt werden..
die liste soll leicht upzudaten (für neue produkt nr.) sein.


wäre super, wenn mir jmd. helfen könnt oder en gutes tutorial, wo mir weiterhilft wäre klasse.

Danke für eure Hilfe,

gruß, chinji

\edit: ich soll das mit Arraylist schreiben :_-(
 
Zuletzt bearbeitet:
Die Funktionen sind noch nicht komplett .. Außerdem hab ichs schnell gemacht, da ich keine zeit mehr habe .. Ich hoffe es hilft dir ein wenig .. Gibst du ne 1 ein kommt Produkt1 usw..

Schönen Abend ;)


Code:
import java.io.*;
import java.util.*;

public class Produkte {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
			
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));	
		String aLine;
		
		ArrayList produkt1 = new ArrayList();
		ArrayList produkt2 = new ArrayList();
		
		produkt1.add(new Integer(1));
		produkt1.add(new Integer(123));
		produkt1.add(new String("passwort"));
		
		produkt2.add(new Integer(2));
		produkt2.add(new Integer(234));
		produkt2.add(new String("passwort2"));
			
		
		ArrayList produkte = new ArrayList();	
		
		produkte.add(produkt1);
		produkte.add(produkt2);
		
		
		try {
			while ((aLine = br.readLine()) != null) { 

				ArrayList einProdukt = getProdukt(produkte,Integer.parseInt(aLine));
				
				System.out.println(einProdukt.get(0)+","+einProdukt.get(1)+","+einProdukt.get(2));
				
				
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}
	
	private static ArrayList getProdukt(ArrayList produkte, int pNr)
	{
		// Liste durchsuchen
		
		Iterator it = produkte.iterator();
		
		while (it.hasNext()){
			ArrayList produkt = (ArrayList) it.next();
			if (((Integer)produkt.get(0)).intValue() == pNr){
				return produkt;
			}
		}
		
		return null;
	}

}
 
Zurück