r/learncsharp • • May 28 '19

C# classes/constructors/interfaces

Hello, I have project to do on C# the project looks like 3 classes that need to inheritance each other also 1 interface and some other methods if someone think he can help me out i'll appreciate it.

===================================================================== so i had to make program for controlling parking lot.it should get,save and shows the information.

i will try to explain it as simple as i can. First i have to create 3 classes : Cars , LightTrucks , HeavyTrucks they both should contain: type , brand , model; in constructor

actually the input should be like this: parkinglot parkingname1 2 2 2 parkinglot parkingname2 2 1 1 Car Kia Seed Lighttruck Citroen Jumper Car VW Polo Lighttruck Ford Tranzit Heavytruck MAN TGM18 Car Audi А6 Heavytruck Volvo FM12 Print something1 End

and the Output should be: parked cars in parkinglot something1: Brand Kia, Model Seed Brand VW, Model Polo Brand Citroen, Model Jumper Brand Ford, Model Tranzit Brand MAN, Model TGM18 Brand Volvo, model FM12 Parkinglot something1 has the following locations: Car 2, busy 2 Lighttrucks 2, busy 2 Heavytrucks 2, busy 2 Parkinglot something2 has the following locations: Car 2, busy 1 Lighttruck 1, busy 1 Heavytruck 1, busy 1

///////////////////////////////////// so what should it do create parking lot with command parkinglot name 2 2 2 (first 2 = car ; second Lighttruck ; third Heavytruck)

after i create 1 or more parkinglots i should be able to enter cars,lighttrucks or heavytrucks.

like: car Audi A6 Lighttruck Citroen Jumper Heavytruck Volvo FM12

and then Enter "End" to stop the program or Enter Print parkinglot name like "Print something1" and the program should print "parked cars in parkinglot something1: Brand Audi, Model A6 ; Brand Citroen, Model Jumper ; HeavyTruck Brand Volvo, Model FM12 ; Parkinglot something1 has the following locations: cars 2 , busy 1 ; lighttrucks 2 , busy 1 ; heavytrucks 2 ,busy 1"

0 Upvotes

17 comments sorted by

8

u/wiwalsh May 28 '19

A) homework B) what? I read the whole thing and I have no idea what you are trying to do. C) its homework, go to your notes and teacher/professor.

4

u/[deleted] May 28 '19

as above, I know it sounds like you being fobbed off, but someone has set this work in the expectation that you can do it .
if you cant , you need to talk to them, other wise you wont be able to do the next piece of work, and the next and the next .....

-2

u/symplaren May 28 '19

3

u/[deleted] May 28 '19

just try it , get some bits wrong and learn why you got it wrong. You need to go through the process to get the result

1

u/symplaren May 28 '19

i am trying from hours just i don't know how to do it

1

u/Broer1 May 29 '19

Welcome in our world. Sometimes we try for days without a clue until we have the right idea after immense reading and trying.

1

u/imguralbumbot May 28 '19

Hi, I'm a bot for linking direct images of albums with only 1 image

https://i.imgur.com/4f5uBiK.png

Source | Why? | Creator | ignoreme| deletthis

2

u/jamietwells May 28 '19

Yeah, that's not going to make sense to anyone.

Find a human around you, explain the problem to them. Then, when that human says: 'ok, I understand the problem' then write your explanation down exactly as you explained it to that human.

If the human says 'wtf are you talking about' then try to rephrase your explanation.

1

u/CrimsonWolfSage May 28 '19

So far, I'm not seeing any code and not the right details to help much.

Homework asks for a Parking Lot

  • Parking Lot [ Just one? Spaces?]

  • Cars [ Type {Cars , LightTrucks , HeavyTrucks}, Model, Brand

  • Interaction { CLI, Parkinglot1 car type model, END}

There's some confusion, but I'm pretty sure that a basic structure is forming here.

class Vehicle { var type, var model }
class Car: Vehicle {}
class LightTruck: Vehicle{}
class HeavyTruck: Vehicle {}
interface IPark { Add(), Remove() }

You can share your progress with a Code Sharing site, otherwise we will need some clearer examples of what you want to do, and what you have tried to help more.

1

u/symplaren May 28 '19

https://codeshare.io/5Ro91B

i am at the start so far, i know how should be like when it's done but i don't know how to do some stuffs by myself :/

1

u/CrimsonWolfSage May 28 '19 edited May 28 '19

Slowly reading code between tasks. I'll update this with feedback as I go.

General Notes:

  • Naming Conventions & Meaningful Names

  • DRY: Don't Repeat Yourself ( If you typed it 2~3 times, probably a better way )

  • Structure:

  • -> Remove Unused Imports/Using Libraries

  • -> Layout Rabbit Hole: C Dev Guidelines

class Program

  • --> demo is unclear, input is clearer

  • Line 17: var input = Console.ReadLine()

  • --> Create Variables before the loop

  • Line 19: if( condition ) { break; }

  • --> Put condition in the loop While( condition )

  • Line 24: same as 17

  • --> Create Variables before the loop

  • Line 25-39: Parsing Block Don't Repeat Yourself

  • Line 27: ICar = new car("Type","Brand","Model");

  • --> Instantiate class Car, not interface ICar

  • --> The car class knows it is a car, not sure why you pass the type into it and save it.

  • Line 28: This line repeats for every type, it could be done once for every type.

interface ICar

  • 3 shared properties to get allows every vehicle type to share this behavior, but that's not a good way to use it.

  • interfaces provide a "contract" that every object using the interface agrees on.

  • ICar shoud contain Behaviors every car, and truck will use. In this case, Park() and Exit() might be a common use case for every vehicle to agree on, as well as Location() or Spot() to list where it is located in your Parking Lot.

  • The common properties, or values is a good candidate for Inheritance, where every car, truck can be a Vehicle with certain base details and behaviors.

class Car : ICar

  • Line 75: public Cars(string type,string brand,string model)

  • --> The car class knows it's a car

  • --> Type isn't used anywhere

  • Line 90: return $"Марка {this.Brand}, Модел {this.Model}";

  • -->only uses Brand & Model, no reason for Type in class

  • Copy Pasta for all ICar vehicles...

  • --> Suggest Inheritance: Base Class for shared data and methods that rarely/never changes

1

u/symplaren May 28 '19

there should not be Location() Spot() or Exit() all i have to do is create park like that.

parkinglot something1 2 2 2 the 2's are for the car,lighttruck,heavytruck and i have to type some cars below that and cars go for the first 2 places ; lighttrucks for the other 2 places and heavytrucks for the last 2 places thats it what i have to do looks simple but can't find the logic

1

u/CrimsonWolfSage May 28 '19 edited May 28 '19

I'm glad you could help clarify this detail. So we need to contain this kind of data structure for your parked cars

xCarCarLightLightHeavyHeavy
Parking Lot 1Kia SeedVw PoloCitroen JumperFord TranzitMAN TGM18Volvo FM12
Parking Lot 2

A query/report might look a bit like this in this example.

xCarCarLightLightHeavyHeavy
Parking Lot 1BusyBusyBusyBusyBusyBusy
Parking Lot 2FreeFreeFreeFreeFreeFree

Output to user

  • Cars Used: 2 Available: 2

  • Light Trucks Used: 2 Available: 2

  • Heavy Trucks Used: 2 Available: 2

1

u/symplaren May 29 '19

i mean yes i just need more then 2 or less then 2 places for every type normal car,lighttruck and heavytruck and when i type like heavtruck MAN TGM18 should go automaticly in heavy slot of the park i created first but i dont know how to do it