Czesc, mam zadanie do wykonania, wklejam odrazu jego tresc:
-
Zdefiniować klasę Books. Utworzyć 10-elementową tablicę obiektów klasy do przechowywania in- formacji o książkach (author, title, year). Klasa musi zawierać metody Set i Get dla wszystkich pól
danych oraz funkcje wczytującą i wyświetlającą dane. Program powinien w pętli wpisywać dane do
tablicy obiektów i w kolejnej pętli wypisać informacje dla wszystkich pozycji na ekranie.
Dopiero zaczynam z nauka obiektowosci, dlatego zadanie wykonalem, jednak nie jestem pewien czy dobrze, na pewno da sie lepiej. Nie do konca rozumiem tresc zadania. Gdyby ktos mogl rzucic okiem na moj kod i powiedziec czy jest ok i pokrywa sie z trescia czy moze cos poprawic, moze ktos doradzi jak ulepszyc zadanie. Z gory dzieki.
using System;
namespace cwiczenie
{
class Program
{
static void Main(string[] args)
{
Books zad = new Books("Noname","No title",0);
zad.Read();
zad.Print();
Console.ReadKey();
}
}
class Books
{
private object[] tab = new object[10];
private string author;
private string title;
private int year;
public string GetAuthor() { return author; }
public string GetTitle() { return title; }
public int GetYear() { return year; }
public void SetAuthor(string a) { author = a; }
public void SetTitile(string t) { title = t; }
public void SetYear(int y) { year = y; }
public Books(string a, string t, int y)
{
author = a;
title = t;
year = y;
}
public void Read()
{
for (int i = 0; i < 1; i++)
{
Console.Write("Podaj autora ksiazki: ");
tab[0] = Console.ReadLine();
Console.Write("Podaj tytul ksiazki: ");
tab[1] = Console.ReadLine();
Console.Write("Podaj rok wydania ksiazki: ");
tab[2] = Console.ReadLine();
Console.Write("Informacje: ");
tab[3] = Console.ReadLine();
Console.Write("Informacje: ");
tab[4] = Console.ReadLine();
Console.Write("Informacje: ");
tab[5] = Console.ReadLine();
Console.Write("Informacje: ");
tab[6] = Console.ReadLine();
Console.Write("Informacje: ");
tab[7] = Console.ReadLine();
Console.Write("Informacje: ");
tab[8] = Console.ReadLine();
Console.Write("Informacje: ");
tab[9] = Console.ReadLine();
}
}
public void Print()
{
for(int i=0; i<1;i++)
{
Console.WriteLine("Autor: " + tab[0]);
Console.WriteLine("Tytul: " + tab[1]);
Console.WriteLine("Rok wydania: " + tab[2]);
Console.WriteLine("Dodatkowe informacje: " + tab[3]);
Console.WriteLine("Dodatkowe informacje: " + tab[4]);
Console.WriteLine("Dodatkowe informacje: " + tab[5]);
Console.WriteLine("Dodatkowe informacje: " + tab[6]);
Console.WriteLine("Dodatkowe informacje: " + tab[7]);
Console.WriteLine("Dodatkowe informacje: " + tab[8]);
Console.WriteLine("Dodatkowe informacje: " + tab[9]);
}
}
}
}