0% found this document useful (0 votes)
2 views

17# Object Methods Object Oriented Programming

The document contains C# code for two classes, Character and Student, within the 'darklter' namespace. The Character class includes methods for introducing the character and displaying their stats, while the Student class provides methods for introducing the student and evaluating their grades based on midterm and final scores. Each class is instantiated in a Program class to demonstrate their functionality.

Uploaded by

Lesunter KLter
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

17# Object Methods Object Oriented Programming

The document contains C# code for two classes, Character and Student, within the 'darklter' namespace. The Character class includes methods for introducing the character and displaying their stats, while the Student class provides methods for introducing the student and evaluating their grades based on midterm and final scores. Each class is instantiated in a Program class to demonstrate their functionality.

Uploaded by

Lesunter KLter
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

17# Object Methods Object Oriented Programming

/////////////////
//Character.cs//
//\\\\\\\\\\\\\\

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace darklter
{
internal class Character
{
public string name, dialog;
public int hp, mp, lvl;

public Character(string name, string dialog, int hp, int mp, int lvl)
{
this.name = name;
this.dialog = dialog;
this.hp = hp;
this.mp = mp;
this.lvl = lvl;
}

public void introduce()


{
Console.WriteLine("I'am " + name);
}

public void sayDialog()


{
Console.WriteLine(name + " : " + dialog);
}
}
}

///////////////
//Program.cs//
//\\\\\\\\\\\\

using System;
namespace darklter
{
class Program
{
static void Main(string[] args)
{
Character c = new Character("David", "Hello World", 100, 50, 1);
c.introduce();
c.sayDialog();
}
}
}
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||

/////////////////
//Character.cs//
//\\\\\\\\\\\\\\

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace darklter
{
internal class Character
{
public string name, dialog;
public int hp, mp, lvl;

public Character(string name, string dialog, int hp, int mp, int lvl)
{
this.name = name;
this.dialog = dialog;
this.hp = hp;
this.mp = mp;
this.lvl = lvl;
}

public string introduce()


{
return "I'am " + name;
}

public string sayDialog()


{
return name + " : " + dialog;
}

public void checkStats()


{
Console.WriteLine("Name : " + name);
Console.WriteLine("Lvl : " + lvl);
Console.WriteLine("HP : " + hp);
Console.WriteLine("MP : " + mp);
}
}
}

///////////////
//Program.cs//
//\\\\\\\\\\\\

using System;
namespace darklter
{
class Program
{
static void Main(string[] args)
{
Character c = new Character("David", "Hello World", 100, 50, 1);
c.checkStats();
}
}
}

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||

/////////////////
// Student.cs //
//\\\\\\\\\\\\\\

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace darklter
{
internal class Student
{
public string firstName, lastName;
public string course, year, section;
public float midtermGrade, finalGrade;

public Student(string firstName, string lastName, string course, string


year, string section, float midtermGrade, float finalGrade)
{
this.firstName = firstName;
this.lastName = lastName;
this.course = course;
this.year = year;
this.section = section;
this.midtermGrade = midtermGrade;
this.finalGrade = finalGrade;
}

public void introduceSelf()


{
Console.WriteLine("Full Name : " + firstName + " " + lastName);
Console.WriteLine();
Console.WriteLine("Course : " + course);
Console.WriteLine("Year : " + year);
Console.WriteLine("Section : " + section);
Console.WriteLine();
}

public void evaluateGrade()


{
float average = (midtermGrade + finalGrade) / 2;

Console.WriteLine("Average : " + average);

if (average > 100) Console.WriteLine("Invalid Grade");


else if (average >= 98) Console.WriteLine("With Highest Honors");
else if (average >= 95) Console.WriteLine("With High Honors");
else if (average >= 90) Console.WriteLine("With Honors");
else if (average >= 75) Console.WriteLine("Passed");
else Console.WriteLine("Failed");
}
}
}

///////////////
//Program.cs//
//\\\\\\\\\\\\

using System;
namespace darklter
{
class Program
{
static void Main(string[] args)
{
Student s1 = new Student("David", "Sdpt", "BSIT", "2", "E", 90, 90);
s1.introduceSelf();
s1.evaluateGrade();

Console.WriteLine();

Student s2 = new Student("Alenere", "Sdpt", "BSCS", "2", "A", 95, 98);


s2.introduceSelf();
s2.evaluateGrade();
}
}
}

You might also like