Created
June 8, 2018 14:35
-
-
Save d630/893fd9fa61e4a1359f6af377ab807829 to your computer and use it in GitHub Desktop.
Ware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace csharp | |
{ | |
public class Program | |
{ | |
static string substituteFirstChar(string str) | |
{ | |
return char.ToUpper(str[0]) + str.Substring(1); | |
} | |
static void einkaufen(Ware[] ware) | |
{ | |
int input; | |
double input2; | |
for (int i = 0; i < ware.Length; i++) | |
{ | |
Console.WriteLine("\t\t{0}.\n\t\t\tName: {1}\n\t\t\tGewicht: {2}\n\t\t\tPreis: {3}\n\t\t\tHerkunft: {4}", | |
i, | |
ware[i].getName(), | |
ware[i].getGewicht(), | |
ware[i].getPreis(), | |
ware[i].getHerkunft()); | |
} | |
if (ware.Length == 1) | |
{ | |
input = 0; | |
} | |
else | |
{ | |
Console.Write("\t\tAuswahl: "); | |
input = int.Parse(Console.ReadLine()); | |
} | |
Console.Write("\t\tGramm: "); | |
input2 = (ware[input].getPreis()/ware[input].getGewicht()) * | |
double.Parse(Console.ReadLine()); | |
Console.WriteLine("\tPreis: " + input2.ToString()); | |
} | |
static void einlagern(Ware[] ware, string art) | |
{ | |
string name; | |
double gewicht; | |
double preis; | |
string herkunft; | |
Console.WriteLine("\t" + substituteFirstChar(art)); | |
for (int i = 0; i < ware.Length; i++) | |
{ | |
Console.Write("\t\tName: "); | |
name = Console.ReadLine(); | |
Console.Write("\t\tGewicht: "); | |
gewicht = double.Parse(Console.ReadLine()); | |
Console.Write("\t\tPreis: "); | |
preis = double.Parse(Console.ReadLine()); | |
Console.Write("\t\tHerkunft: "); | |
herkunft = Console.ReadLine(); | |
ware[i] = new Ware(name, art, gewicht, preis, herkunft); | |
} | |
} | |
static void Main(string[] args) | |
{ | |
Ware[][] arten = new Ware[2][]; | |
arten[0] = new Ware[1]; | |
arten[1] = new Ware[1]; | |
Console.WriteLine("Lager auffuellen"); | |
einlagern(arten[0], "obst"); | |
einlagern(arten[1], "gemuese"); | |
Console.WriteLine("Was wollen sie kaufen?"); | |
for (int i = 0; i < arten.Length; i++) | |
Console.WriteLine("\t{0}. {1}", i, substituteFirstChar(arten[i][0].getArt())); | |
Console.Write("\tAuswahl: "); | |
einkaufen(arten[int.Parse(Console.ReadLine())]); | |
Console.ReadKey(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace csharp | |
{ | |
public class Ware | |
{ | |
private string name; | |
private double gewicht; | |
private double preis; | |
private string herkunft; | |
private string art; | |
// | |
// constructor | |
// | |
public Ware(string name, string art, double gewicht, double preis, string herkunft) | |
{ | |
this.name = name; | |
this.gewicht = gewicht; | |
this.preis = preis; | |
this.herkunft = herkunft; | |
this.art = art; | |
} | |
// | |
// getter | |
// | |
public string getName() | |
{ | |
return this.name; | |
} | |
public double getGewicht() | |
{ | |
return this.gewicht; | |
} | |
public double getPreis() | |
{ | |
return this.preis; | |
} | |
public string getHerkunft() | |
{ | |
return this.herkunft; | |
} | |
public string getArt() | |
{ | |
return this.art; | |
} | |
// | |
// setter | |
// | |
public void setName(string name) | |
{ | |
this.name = name; | |
} | |
public void setGewicht(double gewicht) | |
{ | |
this.gewicht = gewicht; | |
} | |
public void setPreis(double preis) | |
{ | |
this.preis = preis; | |
} | |
public void setHerkunft(string herkunft) | |
{ | |
this.herkunft = herkunft; | |
} | |
public void setArt(string art) | |
{ | |
this.art = art; | |
} | |
// methods | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment