|
|
Line 1: |
Line 1: |
− | ==Kode fra Onsdag d. 22. November==
| |
− | <source lang=Csharp>
| |
− | using System;
| |
− | using System.Collections.Generic;
| |
− | using System.Linq;
| |
− | using System.Text;
| |
− | using System.Threading.Tasks;
| |
| | | |
− | namespace OOP2
| |
− | {
| |
− | class Machine
| |
− | {
| |
− | //Some code
| |
− | }
| |
− |
| |
− | class Vehicle : Machine
| |
− | {
| |
− | protected string brand;
| |
− | private double topSpeed;
| |
− |
| |
− | public string getBrand()
| |
− | {
| |
− | return brand;
| |
− | }
| |
− |
| |
− | public void setBrand(string s)
| |
− | {
| |
− | this.brand = s;
| |
− | }
| |
− | }
| |
− |
| |
− | class Car : Vehicle
| |
− | {
| |
− | private int numberOfDoors;
| |
− |
| |
− | //Getters and Setters
| |
− | }
| |
− |
| |
− | class Motorcycle : Vehicle
| |
− | {
| |
− | private double handlebarWidth;
| |
− |
| |
− | public Motorcycle()
| |
− | {
| |
− | brand = "Harley";
| |
− | }
| |
− | //Getters and Setters
| |
− | }
| |
− | }
| |
− |
| |
− |
| |
− | namespace OOP2
| |
− | {
| |
− | class Spaceship
| |
− | {
| |
− | private double speed = 40;
| |
− | protected int barrelSize = 20;
| |
− |
| |
− | public virtual int FireWeapon()
| |
− | {
| |
− | Console.WriteLine("You fired " + barrelSize + " shots!");
| |
− | return 0;
| |
− | }
| |
− | }
| |
− |
| |
− | class HeavySpaceship : Spaceship
| |
− | {
| |
− | private int secondBarrelSize = 10;
| |
− |
| |
− | }
| |
− | }
| |
− |
| |
− |
| |
− | class Pupil
| |
− | {
| |
− | protected string name;
| |
− | protected int age;
| |
− | protected double average;
| |
− |
| |
− | public Pupil(string name, int age, double average)
| |
− | {
| |
− | this.name = name;
| |
− | this.age = age;
| |
− | this.average = average;
| |
− | }
| |
− | }
| |
− |
| |
− | class UnivertyPupil : Pupil
| |
− | {
| |
− | public UnivertyPupil(string uName, int age, double average) : base(uName, age, average)
| |
− | {
| |
− | }
| |
− | }
| |
− | </source>
| |
− |
| |
− | ==Opgavebeskrivelse Onsdag==
| |
− | I skal lave en Zoologisk Have applikation
| |
− | Der SKAL være disse to klasser:
| |
− | Zoo
| |
− | Animal
| |
− |
| |
− | Jeg skal være i stand til at spørge et objekt af classen Zoo om at give mig et array med alle dyr i parken.
| |
− |
| |
− | Som øvelse, så skal hver art af dyr være sin egen unikke klasse.
| |
− |
| |
− | Tilføj features efter eget ønske (spørg om alle dyr med en bestemt højde, alle dyr med vinger, alle dyr som hedder "Georg")
| |