-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLampadina.java
76 lines (44 loc) · 1.33 KB
/
Lampadina.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.util.Scanner;
public class Lampadina {
String stato;
int numeroClick;
int numeroMassimo;
public Lampadina(String stato) {
this.stato = stato;
this.numeroClick = 0;
}
public String stato() {
return stato;
}
public void numeroClick() {
System.out.println("QUanti click sono consentiti?");
Scanner sc= new Scanner(System.in);
numeroMassimo = sc.nextInt();
}
public void click(int scelta) {
if ((scelta == 1 || scelta == 2) && numeroClick < numeroMassimo) {
if (scelta == 1)
{stato = "on";
numeroClick += 1;}
else if (scelta == 2)
{stato = "off";
numeroClick += 1;}}
else if (numeroClick == numeroMassimo) {
stato = "down";
}}
public static void main(String[] args) {
// TODO Auto-generated method stub
int input = 1;
Lampadina x = new Lampadina("on");
x.numeroClick();
do {
System.out.println("cosa vuoi fare? Premi 1 per accendere 2 per spegnere 0 per terminare il programma");
Scanner sc= new Scanner(System.in);
input = sc.nextInt();
if (input == 1) {x.click(input); System.out.println(x.stato); }
else if (input == 2){x.click(input); System.out.println(x.stato); }
else if (input == 0){ System.out.println("ciao!"); }
else System.out.println("numero non valido");
}
while (input != 0);
}}