Kurs:Java (Kjell)/Code-Rubrik/Mikrowellenherd

Quellcode Bearbeiten

package kapitel_13;

import java.io.*;

// http://www.gailer-net.de/tutorials/java/Notes/chap13/progExercises13.html

class Mikrowellenherd {

	public static void main(String[] args) throws IOException {
		
	    BufferedReader stdin = new BufferedReader ( new InputStreamReader( System.in ) );
		
	    String inData;
		int    anzahl;
		double zeit;
		
	    System.out.println("Anzahl der Posten? 1, 2, 3 oder mehr?");
	    inData    = stdin.readLine();
	    anzahl    = Integer.parseInt( inData );
	    
	    System.out.println("Erhitzungszeit für einen Posten?");
	    inData    = stdin.readLine();
	    zeit      = Double.parseDouble( inData );
		
	    // 4 x if
	    if (anzahl == 1)
	    
	    	zeit = zeit + 0.0;
	    
	    if (anzahl == 2)
	    	
	    	zeit = zeit + (0.5 * zeit);
	    
	    if (anzahl == 3)
		
	    	zeit = 2 * zeit;
	    	
	    if (anzahl > 3)
	    	
	    	zeit = 0.0;
	    
	    // Ausgabe
	    
	    if (zeit == 0.0)
	    	
	    	System.out.println("Das Erhitzen von mehr als drei Posten wird nicht empfohlen.");
	    
	    else
	    	
	    	System.out.println("Empfohlene Erhitzungszeit " + zeit);
	    	
	}

}