Stampa squadra singola + creazione squadre

This commit is contained in:
La Programmatrice Verde 2025-05-02 10:19:53 +02:00
parent 4a6a5d98b3
commit a3ad1bfab2
22 changed files with 454 additions and 6 deletions

View File

@ -1,5 +1,65 @@
namespace squadre_calcio; namespace squadre_calcio;
class Giocatore { class Giocatore {
string nome;
string cognome;
string eta;
string nomeRuolo;
string numeroMaglia;
public Giocatore(string p_nome, string p_cognome, string p_eta, string p_nomeRuolo, string p_numeroMaglia) {
this.nome = p_nome;
this.cognome = p_cognome;
this.eta = p_eta;
this.nomeRuolo = p_nomeRuolo;
this.numeroMaglia = p_numeroMaglia;
}
public string GetNome() {
return nome;
}
public string GetCognome() {
return cognome;
}
public string GetEta() {
return eta;
}
public string GetNomeRuolo() {
return nomeRuolo;
}
public string GetNumeroMaglia() {
return numeroMaglia;
}
public void SetNome(string p_nome) {
this.nome = p_nome;
}
public void SetCognome(string p_cognome) {
this.cognome = p_cognome;
}
public void SetEta(string p_eta) {
this.eta = p_eta;
}
public void SetNomeRuolo(string p_nomeRuolo) {
this.nomeRuolo = p_nomeRuolo;
}
public void SetNumeroMaglia(string p_numeroMaglia) {
this.numeroMaglia = p_numeroMaglia;
}
public void StampaGiocatore() {
Console.WriteLine($"Nome: {this.GetNome()}");
Console.WriteLine($"Cognome: {this.GetCognome()}");
Console.WriteLine($"Età: {this.GetEta()}");
Console.WriteLine($"Ruolo: {this.GetNomeRuolo()}");
Console.WriteLine($"Numero maglia: {this.GetNumeroMaglia()}");
}
} }

View File

@ -1,9 +1,242 @@
namespace squadre_calcio; using System.Net.NetworkInformation;
class Program namespace squadre_calcio;
{
static void Main(string[] args) class Program {
{ static void Main(string[] args) {
Console.WriteLine("Hello, World!"); Console.Clear();
int scelta;
Squadra[] squadre = null;
do {
Console.WriteLine("Scegliere un'opzione:");
Console.WriteLine("1. Inserisci un array di squadre");
Console.WriteLine("2. Stampa formazione di una squadra");
Console.WriteLine("3. Stampa tutte le squadre");
Console.WriteLine("4. Pulisci schermo");
Console.WriteLine("0. Esci");
Console.Write("Scelta: ");
scelta = Convert.ToInt32(Console.ReadLine());
switch (scelta) {
case 0:
break;
case 1:
squadre = CreaArraySquadre();
Pausa();
break;
case 2:
if (squadre == null) {
Console.WriteLine("Errore: è necessario creare l'array di squadre prima di poter stampare la formazione di una squadra");
}
else {
do {
Console.WriteLine("Per quale parametro scegliere la squadra? ");
Console.WriteLine("1. Nome");
Console.WriteLine("2. Città");
Console.WriteLine("3. Sponsor");
Console.WriteLine("4. Numero membri");
Console.Write("Scelta: ");
scelta = Convert.ToInt32(Console.ReadLine());
switch (scelta) {
case 1:
do {
Console.WriteLine("Scegliere un'opzione:");
for (int i = 0; i < squadre.Length; i++) {
Console.WriteLine($"{i}. {squadre[i].GetNome()}");
}
Console.Write("Scelta: ");
scelta = Convert.ToInt32(Console.ReadLine());
if (scelta < 0 || scelta >= squadre.Length) {
Console.WriteLine("Opzione non valida.");
Pausa();
}
}
while (scelta < 0 || scelta >= squadre.Length);
squadre[scelta].StampaSquadra();
scelta = -1;
break;
case 2:
do {
Console.WriteLine("Scegliere un'opzione:");
for (int i = 0; i < squadre.Length; i++) {
Console.WriteLine($"{i}. {squadre[i].GetCitta()}");
}
Console.Write("Scelta: ");
scelta = Convert.ToInt32(Console.ReadLine());
if (scelta < 0 || scelta >= squadre.Length) {
Console.WriteLine("Opzione non valida.");
Pausa();
}
}
while (scelta < 0 || scelta >= squadre.Length);
squadre[scelta].StampaSquadra();
scelta = -1;
break;
case 3:
do {
Console.WriteLine("Scegliere un'opzione:");
for (int i = 0; i < squadre.Length; i++) {
Console.WriteLine($"{i}. {squadre[i].GetSponsor()}");
}
Console.Write("Scelta: ");
scelta = Convert.ToInt32(Console.ReadLine());
if (scelta < 0 || scelta >= squadre.Length) {
Console.WriteLine("Opzione non valida.");
Pausa();
}
}
while (scelta < 0 || scelta >= squadre.Length);
squadre[scelta].StampaSquadra();
scelta = -1;
break;
case 4:
do {
Console.WriteLine("Scegliere un'opzione:");
for (int i = 0; i < squadre.Length; i++) {
Console.WriteLine($"{i}. {squadre[i].GetMembri().Length}");
}
Console.Write("Scelta: ");
scelta = Convert.ToInt32(Console.ReadLine());
if (scelta < 0 || scelta >= squadre.Length) {
Console.WriteLine("Opzione non valida.");
Pausa();
}
}
while (scelta < 0 || scelta >= squadre.Length);
squadre[scelta].StampaSquadra();
scelta = -1;
break;
default:
Console.WriteLine("Opzione non valida.");
Pausa();
break;
}
}
while(scelta != -1);
}
Pausa();
break;
case 3:
Pausa();
break;
case 4:
Console.Clear();
break;
default:
Console.WriteLine("Opzione non valida.");
Pausa();
break;
}
}
while (scelta != 0);
}
static void Pausa() {
Console.WriteLine("Premere un tasto per continuare. . .");
Console.ReadKey();
}
static Squadra[] CreaArraySquadre() {
Squadra[] ritorno;
int input;
string nome;
string citta;
string sponsor;
Giocatore[] membri;
do {
Console.Write("Quante squadre si vuole creare? ");
input = Convert.ToInt32(Console.ReadLine());
if (input <= 0) {
Console.WriteLine("Non è possibile creare meno di una squadra.");
Pausa();
}
}
while (input <= 0);
ritorno = new Squadra[input];
for (int i = 0; i < ritorno.Length; i++) {
Console.WriteLine($"Squadra n. {i + 1}:\n");
Console.Write("Nome della squadra: ");
nome = Console.ReadLine();
Console.Write("Città della squadra: ");
citta = Console.ReadLine();
Console.Write("Sponsor della squadra: ");
sponsor = Console.ReadLine();
membri = CreaArrayGiocatori();
ritorno[i] = new Squadra(nome, citta, sponsor, membri);
}
return ritorno;
}
static Giocatore[] CreaArrayGiocatori() {
Giocatore[] ritorno;
int input;
string nome;
string cognome;
string eta;
string nomeRuolo;
string numeroMaglia;
do {
Console.Write("Da quanti giocatori è formata la squadra? ");
input = Convert.ToInt32(Console.ReadLine());
if (input <= 0) {
Console.WriteLine("Non è possibile creare una squadra con meno di un giocatore.");
Pausa();
}
}
while (input <= 0);
ritorno = new Giocatore[input];
for (int i = 0; i < ritorno.Length; i++) {
Console.WriteLine($"Giocatore n. {i + 1}:\n");
Console.Write("Nome del giocatore: ");
nome = Console.ReadLine();
Console.Write("Cognome del giocatore: ");
cognome = Console.ReadLine();
do {
Console.Write("Età del giocatore: ");
input = Convert.ToInt32(Console.ReadLine());
if (input <= 0) {
Console.WriteLine("Non è possibile un giocatore con un'età inferiore a zero.");
Pausa();
}
}
while (input <= 0);
eta = Convert.ToString(input);
Console.Write("Ruolo del giocatore: ");
nomeRuolo = Console.ReadLine();
Console.Write("Numero di maglia del giocatore: ");
numeroMaglia = Convert.ToString(Convert.ToInt32(Console.ReadLine()));
ritorno[i] = new Giocatore(nome, cognome, eta, nomeRuolo, numeroMaglia);
}
return ritorno;
} }
} }

View File

@ -1,5 +1,59 @@
namespace squadre_calcio; namespace squadre_calcio;
class Squadra { class Squadra {
string nome;
string citta;
string sponsor;
Giocatore[] membri;
public Squadra(string p_nome, string p_citta, string p_sponsor, Giocatore[] p_membri) {
this.nome = p_nome;
this.citta = p_citta;
this.sponsor = p_sponsor;
this.membri = p_membri;
}
public string GetNome() {
return this.nome;
}
public string GetCitta() {
return this.citta;
}
public string GetSponsor() {
return this.sponsor;
}
public Giocatore[] GetMembri() {
return this.membri;
}
public void SetNome(string p_nome) {
this.nome = p_nome;
}
public void SetCitta(string p_citta) {
this.citta = p_citta;
}
public void SetSponsor(string p_sponsor) {
this.sponsor = p_sponsor;
}
public void SetMembri(Giocatore[] p_membri) {
this.membri = p_membri;
}
public void StampaSquadra() {
Console.WriteLine($"Nome squadra: {this.GetNome()}");
Console.WriteLine($"Città: {this.GetCitta()}");
Console.WriteLine($"Sponsor: {this.GetSponsor()}");
Console.WriteLine("Giocatori:\n");
for (int i = 0; i < this.membri.Length; i++) {
Console.WriteLine($"Giocatore n. {i + 1}");
this.membri[i].StampaGiocatore();
Console.WriteLine();
}
}
} }

BIN
bin/Debug/net9.0/squadre_calcio Executable file

Binary file not shown.

View File

@ -0,0 +1,23 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v9.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v9.0": {
"squadre_calcio/1.0.0": {
"runtime": {
"squadre_calcio.dll": {}
}
}
}
},
"libraries": {
"squadre_calcio/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,12 @@
{
"runtimeOptions": {
"tfm": "net9.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "9.0.0"
},
"configProperties": {
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}

View File

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]

BIN
obj/Debug/net9.0/apphost Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("squadre_calcio")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4a6a5d98b347235812fddc8fff8aea7d75c30d50")]
[assembly: System.Reflection.AssemblyProductAttribute("squadre_calcio")]
[assembly: System.Reflection.AssemblyTitleAttribute("squadre_calcio")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View File

@ -0,0 +1 @@
5f326c6e53b8d89f60c9948ebaf50f7c5d8d2489f1b66dea8290c4496d402d9b

View File

@ -0,0 +1,15 @@
is_global = true
build_property.TargetFramework = net9.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = squadre_calcio
build_property.ProjectDir = /home/Verde/git/squadre_calcio/
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
build_property.EffectiveAnalysisLevelStyle = 9.0
build_property.EnableCodeStyleSeverity =

View File

@ -0,0 +1,8 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

Binary file not shown.

View File

@ -0,0 +1 @@
76fe8bd22e03fb5b2ef7901ea2da8c1eed12fb460798b5df830373453934eedc

View File

@ -0,0 +1,14 @@
/home/Verde/git/squadre_calcio/bin/Debug/net9.0/squadre_calcio
/home/Verde/git/squadre_calcio/bin/Debug/net9.0/squadre_calcio.deps.json
/home/Verde/git/squadre_calcio/bin/Debug/net9.0/squadre_calcio.runtimeconfig.json
/home/Verde/git/squadre_calcio/bin/Debug/net9.0/squadre_calcio.dll
/home/Verde/git/squadre_calcio/bin/Debug/net9.0/squadre_calcio.pdb
/home/Verde/git/squadre_calcio/obj/Debug/net9.0/squadre_calcio.GeneratedMSBuildEditorConfig.editorconfig
/home/Verde/git/squadre_calcio/obj/Debug/net9.0/squadre_calcio.AssemblyInfoInputs.cache
/home/Verde/git/squadre_calcio/obj/Debug/net9.0/squadre_calcio.AssemblyInfo.cs
/home/Verde/git/squadre_calcio/obj/Debug/net9.0/squadre_calcio.csproj.CoreCompileInputs.cache
/home/Verde/git/squadre_calcio/obj/Debug/net9.0/squadre_calcio.dll
/home/Verde/git/squadre_calcio/obj/Debug/net9.0/refint/squadre_calcio.dll
/home/Verde/git/squadre_calcio/obj/Debug/net9.0/squadre_calcio.pdb
/home/Verde/git/squadre_calcio/obj/Debug/net9.0/squadre_calcio.genruntimeconfig.cache
/home/Verde/git/squadre_calcio/obj/Debug/net9.0/ref/squadre_calcio.dll

Binary file not shown.

View File

@ -0,0 +1 @@
acd6e17b0b38b627e410db35696bc694906eaca38ef9d5a46667d24df5053cf9

Binary file not shown.