View difference between Paste ID: bUn4mPu4 and R61VKPWF
SHOW: | | - or go back to the newest paste.
1
import javax.swing.*;
2
3
public class Televisore {
4
	private int numcanali;
5
	private String[] stazioni;
6
	
7
	public Televisore() {
8
		int i = Integer.parseInt(JOptionPane.showInputDialog("Quanti canali ha il televisore?"));
9
		i++;
10
		String[] arr = new String[i];
11
		
12
		numcanali = i;
13
		stazioni = arr;
14
	}
15
	
16
	public int quantiCanali() {
17
		return numcanali;
18
	}
19
	
20
	public void associa() {
21
		for(int i = 1; i < numcanali; i++) {
22
			String s = JOptionPane.showInputDialog("Inserire la stazione da associare al canale n°:" + i);
23
			stazioni[i] = s;
24
			}
25
	}
26
	
27
	public void qualeStazione() {
28
		int i = Integer.parseInt(JOptionPane.showInputDialog("Di quale canale si vuole conoscere la stazione associata?"));
29
		if (stazioni[i] != "") 
30
			JOptionPane.showMessageDialog(null, stazioni[i]);
31
		else
32
			JOptionPane.showMessageDialog(null, "il canale scelto è insesistente!");
33
	}
34
}