c# Trying to understand another way this OOP can be programmed [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
-1
down vote

favorite












I am very new to C# and I am trying out OOP programming following a book. This is the current code I have and it works but I am wondering if this can be done another way.
I think that set and get methods can be done in another way



using System;

public class radio

private int count = 0;

public radio() count = 0;
public int Counts

set this.count = value;
get return this.count;



public class television

private int count = 0;

public television() count = 0;
public int Counts

set this.count = value;
get return this.count;



public class computer

public computer() count = 0;
private int count = 0;
public int Counts

set this.count = value;
get return this.count;



public class warehouse

radio r = new radio();
television tv = new television();
computer cp = new computer();

public warehouse()

r.Counts = 0;
tv.Counts = 0;
cp.Counts = 0;

public void addRadio()

Console.Write("Enter the number of Radio to add : ");
r.Counts += Convert.ToInt32(Console.ReadLine());


public void addTV()

Console.Write("Enter the number of TV to add : ");
tv.Counts += Convert.ToInt32(Console.ReadLine());


public void addComp()

Console.Write("Enter the number of Computers to add : ");
cp.Counts += Convert.ToInt32(Console.ReadLine());


public void showContents()

Console.WriteLine("The Number of radios are 0, TV are 1, Computer are 2,", r.Counts, tv.Counts, cp.Counts);




public class main

public static void Main()

warehouse wh1 = new warehouse();
wh1.addRadio();
wh1.addComp();
wh1.addTV();
wh1.showContents();




Would there be another way to code this by not creating a new instances of below inside warehouse class?



radio r = new radio();
television tv = new television();
computer cp = new computer();






share|improve this question













closed as unclear what you're asking by Dmitry, Mast, Graipher, Vogel612♦, Donald.McLean Jan 29 at 15:53


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 8




    Welcome to Code Review! You'll need to explain what you mean by "this" — what task does this code accomplish? See How to Ask.
    – 200_success
    Jan 18 at 23:15






  • 1




    While OP does not provide a detailed description of what he does, the code in question is not a rocket science either. I think it is fairly self-descriptive and I see no reason to close this question or down-vote it to oblivion.
    – Nikita B
    Jan 19 at 6:40






  • 1




    Welcome to Code Review! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. Please edit to the site standard, which is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
    – Toby Speight
    Jan 19 at 12:05
















up vote
-1
down vote

favorite












I am very new to C# and I am trying out OOP programming following a book. This is the current code I have and it works but I am wondering if this can be done another way.
I think that set and get methods can be done in another way



using System;

public class radio

private int count = 0;

public radio() count = 0;
public int Counts

set this.count = value;
get return this.count;



public class television

private int count = 0;

public television() count = 0;
public int Counts

set this.count = value;
get return this.count;



public class computer

public computer() count = 0;
private int count = 0;
public int Counts

set this.count = value;
get return this.count;



public class warehouse

radio r = new radio();
television tv = new television();
computer cp = new computer();

public warehouse()

r.Counts = 0;
tv.Counts = 0;
cp.Counts = 0;

public void addRadio()

Console.Write("Enter the number of Radio to add : ");
r.Counts += Convert.ToInt32(Console.ReadLine());


public void addTV()

Console.Write("Enter the number of TV to add : ");
tv.Counts += Convert.ToInt32(Console.ReadLine());


public void addComp()

Console.Write("Enter the number of Computers to add : ");
cp.Counts += Convert.ToInt32(Console.ReadLine());


public void showContents()

Console.WriteLine("The Number of radios are 0, TV are 1, Computer are 2,", r.Counts, tv.Counts, cp.Counts);




public class main

public static void Main()

warehouse wh1 = new warehouse();
wh1.addRadio();
wh1.addComp();
wh1.addTV();
wh1.showContents();




Would there be another way to code this by not creating a new instances of below inside warehouse class?



radio r = new radio();
television tv = new television();
computer cp = new computer();






share|improve this question













closed as unclear what you're asking by Dmitry, Mast, Graipher, Vogel612♦, Donald.McLean Jan 29 at 15:53


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 8




    Welcome to Code Review! You'll need to explain what you mean by "this" — what task does this code accomplish? See How to Ask.
    – 200_success
    Jan 18 at 23:15






  • 1




    While OP does not provide a detailed description of what he does, the code in question is not a rocket science either. I think it is fairly self-descriptive and I see no reason to close this question or down-vote it to oblivion.
    – Nikita B
    Jan 19 at 6:40






  • 1




    Welcome to Code Review! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. Please edit to the site standard, which is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
    – Toby Speight
    Jan 19 at 12:05












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I am very new to C# and I am trying out OOP programming following a book. This is the current code I have and it works but I am wondering if this can be done another way.
I think that set and get methods can be done in another way



using System;

public class radio

private int count = 0;

public radio() count = 0;
public int Counts

set this.count = value;
get return this.count;



public class television

private int count = 0;

public television() count = 0;
public int Counts

set this.count = value;
get return this.count;



public class computer

public computer() count = 0;
private int count = 0;
public int Counts

set this.count = value;
get return this.count;



public class warehouse

radio r = new radio();
television tv = new television();
computer cp = new computer();

public warehouse()

r.Counts = 0;
tv.Counts = 0;
cp.Counts = 0;

public void addRadio()

Console.Write("Enter the number of Radio to add : ");
r.Counts += Convert.ToInt32(Console.ReadLine());


public void addTV()

Console.Write("Enter the number of TV to add : ");
tv.Counts += Convert.ToInt32(Console.ReadLine());


public void addComp()

Console.Write("Enter the number of Computers to add : ");
cp.Counts += Convert.ToInt32(Console.ReadLine());


public void showContents()

Console.WriteLine("The Number of radios are 0, TV are 1, Computer are 2,", r.Counts, tv.Counts, cp.Counts);




public class main

public static void Main()

warehouse wh1 = new warehouse();
wh1.addRadio();
wh1.addComp();
wh1.addTV();
wh1.showContents();




Would there be another way to code this by not creating a new instances of below inside warehouse class?



radio r = new radio();
television tv = new television();
computer cp = new computer();






share|improve this question













I am very new to C# and I am trying out OOP programming following a book. This is the current code I have and it works but I am wondering if this can be done another way.
I think that set and get methods can be done in another way



using System;

public class radio

private int count = 0;

public radio() count = 0;
public int Counts

set this.count = value;
get return this.count;



public class television

private int count = 0;

public television() count = 0;
public int Counts

set this.count = value;
get return this.count;



public class computer

public computer() count = 0;
private int count = 0;
public int Counts

set this.count = value;
get return this.count;



public class warehouse

radio r = new radio();
television tv = new television();
computer cp = new computer();

public warehouse()

r.Counts = 0;
tv.Counts = 0;
cp.Counts = 0;

public void addRadio()

Console.Write("Enter the number of Radio to add : ");
r.Counts += Convert.ToInt32(Console.ReadLine());


public void addTV()

Console.Write("Enter the number of TV to add : ");
tv.Counts += Convert.ToInt32(Console.ReadLine());


public void addComp()

Console.Write("Enter the number of Computers to add : ");
cp.Counts += Convert.ToInt32(Console.ReadLine());


public void showContents()

Console.WriteLine("The Number of radios are 0, TV are 1, Computer are 2,", r.Counts, tv.Counts, cp.Counts);




public class main

public static void Main()

warehouse wh1 = new warehouse();
wh1.addRadio();
wh1.addComp();
wh1.addTV();
wh1.showContents();




Would there be another way to code this by not creating a new instances of below inside warehouse class?



radio r = new radio();
television tv = new television();
computer cp = new computer();








share|improve this question












share|improve this question




share|improve this question








edited Jan 19 at 5:18









t3chb0t

32.1k54195




32.1k54195









asked Jan 18 at 22:46









ben

261




261




closed as unclear what you're asking by Dmitry, Mast, Graipher, Vogel612♦, Donald.McLean Jan 29 at 15:53


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by Dmitry, Mast, Graipher, Vogel612♦, Donald.McLean Jan 29 at 15:53


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 8




    Welcome to Code Review! You'll need to explain what you mean by "this" — what task does this code accomplish? See How to Ask.
    – 200_success
    Jan 18 at 23:15






  • 1




    While OP does not provide a detailed description of what he does, the code in question is not a rocket science either. I think it is fairly self-descriptive and I see no reason to close this question or down-vote it to oblivion.
    – Nikita B
    Jan 19 at 6:40






  • 1




    Welcome to Code Review! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. Please edit to the site standard, which is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
    – Toby Speight
    Jan 19 at 12:05












  • 8




    Welcome to Code Review! You'll need to explain what you mean by "this" — what task does this code accomplish? See How to Ask.
    – 200_success
    Jan 18 at 23:15






  • 1




    While OP does not provide a detailed description of what he does, the code in question is not a rocket science either. I think it is fairly self-descriptive and I see no reason to close this question or down-vote it to oblivion.
    – Nikita B
    Jan 19 at 6:40






  • 1




    Welcome to Code Review! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. Please edit to the site standard, which is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
    – Toby Speight
    Jan 19 at 12:05







8




8




Welcome to Code Review! You'll need to explain what you mean by "this" — what task does this code accomplish? See How to Ask.
– 200_success
Jan 18 at 23:15




Welcome to Code Review! You'll need to explain what you mean by "this" — what task does this code accomplish? See How to Ask.
– 200_success
Jan 18 at 23:15




1




1




While OP does not provide a detailed description of what he does, the code in question is not a rocket science either. I think it is fairly self-descriptive and I see no reason to close this question or down-vote it to oblivion.
– Nikita B
Jan 19 at 6:40




While OP does not provide a detailed description of what he does, the code in question is not a rocket science either. I think it is fairly self-descriptive and I see no reason to close this question or down-vote it to oblivion.
– Nikita B
Jan 19 at 6:40




1




1




Welcome to Code Review! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. Please edit to the site standard, which is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
– Toby Speight
Jan 19 at 12:05




Welcome to Code Review! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. Please edit to the site standard, which is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
– Toby Speight
Jan 19 at 12:05










1 Answer
1






active

oldest

votes

















up vote
4
down vote



accepted










1) You should use PascalCase for classes and methods, see capitalisation conventions.



2) You can use auto-properties, if you do not need any additional logic in setter or getter.



3) You should probably use singular tense for Count.



4) Integer fields are equal to 0 by default, you do not have to set them in constructor explicitly.



If you take all this into consideration, your radio class should look like:



public class Radio

public int Count get; set;




A few alternative approaches:



1) Use single class for all your items:



class WarehouseItem

public string Name get; set;
public int Count get; set;


class Warehouse

private WarehouseItem computer;
private WarehouseItem television;

public Warehouse()

computer = new WarehouseItem Name = "Computer" ;
television = new WarehouseItem Name = "TV" ;


...



2) It will make more sense to use collections (such as List) to store warehouse items. I suggest you try implementing it yourself, once you are familiar with lists and arrays.






share|improve this answer





















  • Additionally, I suggest removing Count from WarehouseItem. It's not item's attribute. It's Warehouses concern to know the counts of each item, and that it will get through item Lists.
    – Nikhil Vartak
    Jan 21 at 12:50

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote



accepted










1) You should use PascalCase for classes and methods, see capitalisation conventions.



2) You can use auto-properties, if you do not need any additional logic in setter or getter.



3) You should probably use singular tense for Count.



4) Integer fields are equal to 0 by default, you do not have to set them in constructor explicitly.



If you take all this into consideration, your radio class should look like:



public class Radio

public int Count get; set;




A few alternative approaches:



1) Use single class for all your items:



class WarehouseItem

public string Name get; set;
public int Count get; set;


class Warehouse

private WarehouseItem computer;
private WarehouseItem television;

public Warehouse()

computer = new WarehouseItem Name = "Computer" ;
television = new WarehouseItem Name = "TV" ;


...



2) It will make more sense to use collections (such as List) to store warehouse items. I suggest you try implementing it yourself, once you are familiar with lists and arrays.






share|improve this answer





















  • Additionally, I suggest removing Count from WarehouseItem. It's not item's attribute. It's Warehouses concern to know the counts of each item, and that it will get through item Lists.
    – Nikhil Vartak
    Jan 21 at 12:50














up vote
4
down vote



accepted










1) You should use PascalCase for classes and methods, see capitalisation conventions.



2) You can use auto-properties, if you do not need any additional logic in setter or getter.



3) You should probably use singular tense for Count.



4) Integer fields are equal to 0 by default, you do not have to set them in constructor explicitly.



If you take all this into consideration, your radio class should look like:



public class Radio

public int Count get; set;




A few alternative approaches:



1) Use single class for all your items:



class WarehouseItem

public string Name get; set;
public int Count get; set;


class Warehouse

private WarehouseItem computer;
private WarehouseItem television;

public Warehouse()

computer = new WarehouseItem Name = "Computer" ;
television = new WarehouseItem Name = "TV" ;


...



2) It will make more sense to use collections (such as List) to store warehouse items. I suggest you try implementing it yourself, once you are familiar with lists and arrays.






share|improve this answer





















  • Additionally, I suggest removing Count from WarehouseItem. It's not item's attribute. It's Warehouses concern to know the counts of each item, and that it will get through item Lists.
    – Nikhil Vartak
    Jan 21 at 12:50












up vote
4
down vote



accepted







up vote
4
down vote



accepted






1) You should use PascalCase for classes and methods, see capitalisation conventions.



2) You can use auto-properties, if you do not need any additional logic in setter or getter.



3) You should probably use singular tense for Count.



4) Integer fields are equal to 0 by default, you do not have to set them in constructor explicitly.



If you take all this into consideration, your radio class should look like:



public class Radio

public int Count get; set;




A few alternative approaches:



1) Use single class for all your items:



class WarehouseItem

public string Name get; set;
public int Count get; set;


class Warehouse

private WarehouseItem computer;
private WarehouseItem television;

public Warehouse()

computer = new WarehouseItem Name = "Computer" ;
television = new WarehouseItem Name = "TV" ;


...



2) It will make more sense to use collections (such as List) to store warehouse items. I suggest you try implementing it yourself, once you are familiar with lists and arrays.






share|improve this answer













1) You should use PascalCase for classes and methods, see capitalisation conventions.



2) You can use auto-properties, if you do not need any additional logic in setter or getter.



3) You should probably use singular tense for Count.



4) Integer fields are equal to 0 by default, you do not have to set them in constructor explicitly.



If you take all this into consideration, your radio class should look like:



public class Radio

public int Count get; set;




A few alternative approaches:



1) Use single class for all your items:



class WarehouseItem

public string Name get; set;
public int Count get; set;


class Warehouse

private WarehouseItem computer;
private WarehouseItem television;

public Warehouse()

computer = new WarehouseItem Name = "Computer" ;
television = new WarehouseItem Name = "TV" ;


...



2) It will make more sense to use collections (such as List) to store warehouse items. I suggest you try implementing it yourself, once you are familiar with lists and arrays.







share|improve this answer













share|improve this answer



share|improve this answer











answered Jan 19 at 6:32









Nikita B

12.3k11652




12.3k11652











  • Additionally, I suggest removing Count from WarehouseItem. It's not item's attribute. It's Warehouses concern to know the counts of each item, and that it will get through item Lists.
    – Nikhil Vartak
    Jan 21 at 12:50
















  • Additionally, I suggest removing Count from WarehouseItem. It's not item's attribute. It's Warehouses concern to know the counts of each item, and that it will get through item Lists.
    – Nikhil Vartak
    Jan 21 at 12:50















Additionally, I suggest removing Count from WarehouseItem. It's not item's attribute. It's Warehouses concern to know the counts of each item, and that it will get through item Lists.
– Nikhil Vartak
Jan 21 at 12:50




Additionally, I suggest removing Count from WarehouseItem. It's not item's attribute. It's Warehouses concern to know the counts of each item, and that it will get through item Lists.
– Nikhil Vartak
Jan 21 at 12:50


Popular posts from this blog

Python Lists

Aion

JavaScript Array Iteration Methods