Creazione auto
This commit is contained in:
parent
ca4b362789
commit
afb1ffd370
53
Auto.cs
53
Auto.cs
@ -2,4 +2,57 @@ namespace concessionaria;
|
|||||||
|
|
||||||
class Auto {
|
class Auto {
|
||||||
|
|
||||||
|
readonly string targa, marca, modello;
|
||||||
|
private readonly int cavalli;
|
||||||
|
private int prezzo;
|
||||||
|
private int bollo;
|
||||||
|
|
||||||
|
public Auto(string targa, string marca, string modello, int cavalli, int prezzo) {
|
||||||
|
this.targa = targa;
|
||||||
|
this.marca = marca;
|
||||||
|
this.modello = modello;
|
||||||
|
this.cavalli = cavalli;
|
||||||
|
this.prezzo = prezzo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPrezzo(int p_prezzo) {
|
||||||
|
this.prezzo = p_prezzo;
|
||||||
|
}
|
||||||
|
public void SetBollo() {
|
||||||
|
const CAVALLI_MAX = 250;
|
||||||
|
if (cavalli > CAVALLI_MAX) {
|
||||||
|
this.bollo = (this.cavalli * 100) + ((this.cavalli - CAVALLI_MAX) * 20);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.bollo = this.cavalli * 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetTarga() {
|
||||||
|
return this.targa;
|
||||||
|
}
|
||||||
|
public string GetMarca() {
|
||||||
|
return this.marca;
|
||||||
|
}
|
||||||
|
public string GetModello() {
|
||||||
|
return this.modello;
|
||||||
|
}
|
||||||
|
public int GetCavalli() {
|
||||||
|
return this.cavalli;
|
||||||
|
}
|
||||||
|
public int GetPrezzo() {
|
||||||
|
return this.prezzo;
|
||||||
|
}
|
||||||
|
public int GetBollo() {
|
||||||
|
return this.bollo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StampaDatiAuto() {
|
||||||
|
Console.WriteLine($"Targa: {this.targa}");
|
||||||
|
Console.WriteLine($"Marca: {this.marca}");
|
||||||
|
Console.WriteLine($"Modello: {this.modello}");
|
||||||
|
Console.WriteLine($"Cavalli: {this.Cavalli}");
|
||||||
|
Console.WriteLine($"Prezzo: {this.prezzo}");
|
||||||
|
Console.WriteLine($"Bollo: {this.bollo}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
147
Program.cs
147
Program.cs
@ -1,9 +1,144 @@
|
|||||||
namespace concessionaria;
|
namespace concessionaria;
|
||||||
|
|
||||||
class Program
|
class Program {
|
||||||
{
|
static void Main(string[] args) {
|
||||||
static void Main(string[] args)
|
Console.Clear();
|
||||||
{
|
int scelta, dimensione;
|
||||||
Console.WriteLine("Hello, World!");
|
Auto[] listaAuto;
|
||||||
|
do {
|
||||||
|
Console.WriteLine("Inserire una scelta");
|
||||||
|
Console.WriteLine("1. Crea concessionaria");
|
||||||
|
Console.WriteLine("2. Stampa dati auto");
|
||||||
|
Console.WriteLine("3. Promozione primavera");
|
||||||
|
Console.WriteLine("0. Esci");
|
||||||
|
Console.Write("Scelta: "):
|
||||||
|
scelta = Convert.ToInt32(Console.ReadLine());
|
||||||
|
|
||||||
|
switch (scelta) {
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Console.Clear();
|
||||||
|
do {
|
||||||
|
Console.Write("Quante auto sono presenti? ");
|
||||||
|
dimensione = Convert.ToInt32(Console.ReadLine());
|
||||||
|
if (dimensione <= 0) {
|
||||||
|
Console.WriteLine("Non è possibile considerare un numero di auto minore o uguale a zero");
|
||||||
|
Pausa();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (dimensione <= 0);
|
||||||
|
|
||||||
|
listaAuto = new Auto[dimensione];
|
||||||
|
|
||||||
|
for (int i = 0; i < dimensione; i++) {
|
||||||
|
Console.WriteLine($"Inserimento dati auto n. {i + 1}");
|
||||||
|
listaAuto[i] = CreaAuto();
|
||||||
|
}
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
Console.Clear();
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
Console.Clear();
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Console.WriteLine("Opzione non valida.");
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
static void Pausa() {
|
||||||
|
Console.WriteLine("Premere un tasto per continuare. . .");
|
||||||
|
Console.ReadKey();
|
||||||
|
Console.Clear();
|
||||||
|
}
|
||||||
|
static Auto CreaAuto() {
|
||||||
|
string targa, marca, modello;
|
||||||
|
int cavalli, bollo;
|
||||||
|
double prezzo;
|
||||||
|
bool controlloTarga;
|
||||||
|
Auto auto;
|
||||||
|
|
||||||
|
do {
|
||||||
|
Console.Write("Inserire la targa: ");
|
||||||
|
targa = Console.ReadLine();
|
||||||
|
controlloTarga = ControlloTarga(targa)
|
||||||
|
if (!controlloTarga) {
|
||||||
|
Console.WriteLine("Targa non valida.");
|
||||||
|
Pausa();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (!controlloTarga);
|
||||||
|
|
||||||
|
Console.Write("Inserire la marca: ");
|
||||||
|
marca = Console.ReadLine();
|
||||||
|
|
||||||
|
Console.Write("Inserire il modello: ");
|
||||||
|
modello = Console.ReadLine();
|
||||||
|
|
||||||
|
do {
|
||||||
|
Console.Write("Inserire i cavalli: ");
|
||||||
|
cavalli = Convert.ToInt32(Console.ReadLine());
|
||||||
|
if (cavalli <= 0) {
|
||||||
|
Console.WriteLine("Numero di cavalli non valido.");
|
||||||
|
Pausa();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (cavalli <= 0);
|
||||||
|
|
||||||
|
do {
|
||||||
|
Console.Write("Inserire il prezzo: ");
|
||||||
|
prezzo = Convert.ToDouble(Console.ReadLine());
|
||||||
|
if (prezzo <= 0) {
|
||||||
|
Console.WriteLine("Prezzo non valido.");
|
||||||
|
Pausa();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (prezzo <= 0);
|
||||||
|
|
||||||
|
auto = new Auto(targa, marca, modello, cavalli, prezzo);
|
||||||
|
auto.SetBollo();
|
||||||
|
|
||||||
|
return auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ControlloTarga(string targa) {
|
||||||
|
//Formato targa accettato: AB123CD
|
||||||
|
|
||||||
|
bool ritorno = true;
|
||||||
|
const int LUNGHEZZA = 7;
|
||||||
|
|
||||||
|
if (targa.length != LUNGHEZZA) {
|
||||||
|
ritorno = false; //la targa non è della lunghezza corretta
|
||||||
|
}
|
||||||
|
if (ritorno) {
|
||||||
|
for (int i = 0; i < 2 && ritorno; i++) {
|
||||||
|
if (!(char.IsLetter(targa[i]))) {
|
||||||
|
ritorno = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ritorno) {
|
||||||
|
for (int i = 2; i < 5 && ritorno; i++) {
|
||||||
|
if (!(char.IsNumber(targa[i]))) {
|
||||||
|
ritorno = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ritorno) {
|
||||||
|
for (int i = 5; i < 7 && ritorno; i++) {
|
||||||
|
if (!(char.IsLetter(targa[i]))) {
|
||||||
|
ritorno = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
// <autogenerated />
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]
|
||||||
22
obj/Debug/net9.0/concessionaria.AssemblyInfo.cs
Normal file
22
obj/Debug/net9.0/concessionaria.AssemblyInfo.cs
Normal 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("concessionaria")]
|
||||||
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ca4b362789dad1cbc5d9a0db3e554b0bda371265")]
|
||||||
|
[assembly: System.Reflection.AssemblyProductAttribute("concessionaria")]
|
||||||
|
[assembly: System.Reflection.AssemblyTitleAttribute("concessionaria")]
|
||||||
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|
||||||
|
// Generato dalla classe WriteCodeFragment di MSBuild.
|
||||||
|
|
||||||
1
obj/Debug/net9.0/concessionaria.AssemblyInfoInputs.cache
Normal file
1
obj/Debug/net9.0/concessionaria.AssemblyInfoInputs.cache
Normal file
@ -0,0 +1 @@
|
|||||||
|
fecafa3580f7139cbcf70eca70c2db5701c55070a48f9eac1ef173aaa4e989a8
|
||||||
@ -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 = concessionaria
|
||||||
|
build_property.ProjectDir = /home/Verde/git/concessionaria/
|
||||||
|
build_property.EnableComHosting =
|
||||||
|
build_property.EnableGeneratedComInterfaceComImportInterop =
|
||||||
|
build_property.EffectiveAnalysisLevelStyle = 9.0
|
||||||
|
build_property.EnableCodeStyleSeverity =
|
||||||
8
obj/Debug/net9.0/concessionaria.GlobalUsings.g.cs
Normal file
8
obj/Debug/net9.0/concessionaria.GlobalUsings.g.cs
Normal 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;
|
||||||
BIN
obj/Debug/net9.0/concessionaria.assets.cache
Normal file
BIN
obj/Debug/net9.0/concessionaria.assets.cache
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user