Rubrica
This commit is contained in:
10
Rubrica/.classpath
Normal file
10
Rubrica/.classpath
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
||||||
28
Rubrica/.project
Normal file
28
Rubrica/.project
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>Rubrica</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
<filteredResources>
|
||||||
|
<filter>
|
||||||
|
<id>1758261738047</id>
|
||||||
|
<name></name>
|
||||||
|
<type>30</type>
|
||||||
|
<matcher>
|
||||||
|
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||||
|
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||||
|
</matcher>
|
||||||
|
</filter>
|
||||||
|
</filteredResources>
|
||||||
|
</projectDescription>
|
||||||
73
Rubrica/src/RubricaMain.java
Normal file
73
Rubrica/src/RubricaMain.java
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
interface Ragazza {
|
||||||
|
String getNome();
|
||||||
|
String getTelefono();
|
||||||
|
}
|
||||||
|
class RigaRubrica implements Ragazza {
|
||||||
|
private String nome;
|
||||||
|
private String numeroTel;
|
||||||
|
|
||||||
|
public RigaRubrica(String nome, String numeroTel) {
|
||||||
|
this.nome = nome;
|
||||||
|
this.numeroTel = numeroTel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNome() {
|
||||||
|
return nome;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTelefono() {
|
||||||
|
return numeroTel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return nome + " - " + numeroTel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Classe Rubrica
|
||||||
|
class Rubrica {
|
||||||
|
private Ragazza[] ragazze = new Ragazza[100];
|
||||||
|
private int count = 0;
|
||||||
|
|
||||||
|
public void inserisci(Ragazza r) {
|
||||||
|
if (count >= 100) {
|
||||||
|
System.out.println("Errore: Rubrica piena. Non puoi inserire più di 100 ragazze.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ragazze[count++] = r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stampa() {
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
System.out.println(ragazze[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Main
|
||||||
|
public class RubricaMain {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Rubrica rubrica = new Rubrica();
|
||||||
|
|
||||||
|
for (int i = 1; i <= 10; i++) {
|
||||||
|
String nome = "r" + i;
|
||||||
|
String numero = generaNumeroTelefono();
|
||||||
|
RigaRubrica riga = new RigaRubrica(nome, numero);
|
||||||
|
rubrica.inserisci(riga);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mostra la rubrica
|
||||||
|
rubrica.stampa();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Metodo per generare numero telefonico casuale
|
||||||
|
public static String generaNumeroTelefono() {
|
||||||
|
StringBuilder sb = new StringBuilder("+39");
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
long cifra = (int)(Math.random() * 10); // 0-9
|
||||||
|
sb.append(cifra);
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user