- Joined
- Nov 18, 2017
- Posts
- 6,076
- Reaction
- 5,972
- Points
- 2,079
- Age
- 23
Deleted
Last edited:
Salamat po sapag pansin.Yun nga. Bawal ka magchange ng color in ink kung may laman pang ink.
And since parang OOP nalang din ang dating niyan.
Gawa ka ng methods sa object mo para call ka nalang sa switch-case mo.
i.e
color1.ChangeInk("Green");
color1.Refill();
using System;
public struct BoardMarker
{
public string inkColor;
public int inkContent;
public BoardMarker(string _inkColor, int _inkContent)
{
inkColor = _inkColor;
inkContent = _inkContent;
}
public void DisplayInfo()
{
Console.WriteLine("\n\n\n");
Console.WriteLine("Ink Color: " + inkColor);
Console.WriteLine("Ink Content: " + inkContent);
Console.WriteLine("\n\n\n");
}
public void ChangeColor()
{
if(inkContent > 0)
{
Console.WriteLine("\n\n\nNot empty! Cannot change the color of the ink...\n\n\n");
}
else
{
Console.Write("New Color: ");
inkColor = Console.ReadLine();
Console.WriteLine("\n\n\nSuccess! Changed ink color to " + inkColor + "\n\n\n");
}
}
public void Refill()
{
if(inkContent < 20)
{
inkContent = 20;
Console.WriteLine("\n\n\nInk refilled!\n\n\n");
}
else
{
Console.WriteLine("\n\n\nInk is full...\n\n\n");
}
}
public void Write()
{
if(inkContent > 0)
{
Console.WriteLine("\n\n\nInk deducted by 10.\n\n\n");
inkContent -= 10;
}
else
{
Console.WriteLine("\n\n\nCannot write! There's no ink. Please refill...\n\n\n");
}
}
}
public class Program
{
public static void Main()
{
BoardMarker bm = new BoardMarker("Black", 20); // Initial Values
string input;
do
{
Console.WriteLine("MENU");
Console.WriteLine("[1] Display Info");
Console.WriteLine("[2] Change Color");
Console.WriteLine("[3] Refill");
Console.WriteLine("[4] Write");
Console.Write("Input: ");
input = Console.ReadLine();
switch(input)
{
case "1":
bm.DisplayInfo();
break;
case "2":
bm.ChangeColor();
break;
case "3":
bm.Refill();
break;
case "4":
bm.Write();
break;
default:
break;
}
} while(input != "0");
}
}
Ayan pong PT2 ang pinapagawa.Since may gawa ka na. Ito yung approach ko. Pag-aralan mabuti para kahit gisahin ka ng teacher mo sa mga tanong masasagot mo.
C#:using System; public struct BoardMarker { public string inkColor; public int inkContent; public BoardMarker(string _inkColor, int _inkContent) { inkColor = _inkColor; inkContent = _inkContent; } public void DisplayInfo() { Console.WriteLine("\n\n\n"); Console.WriteLine("Ink Color: " + inkColor); Console.WriteLine("Ink Content: " + inkContent); Console.WriteLine("\n\n\n"); } public void ChangeColor() { if(inkContent > 0) { Console.WriteLine("\n\n\nNot empty! Cannot change the color of the ink...\n\n\n"); } else { Console.Write("New Color: "); inkColor = Console.ReadLine(); Console.WriteLine("\n\n\nSuccess! Changed ink color to " + inkColor + "\n\n\n"); } } public void Refill() { if(inkContent < 20) { inkContent = 20; Console.WriteLine("\n\n\nInk refilled!\n\n\n"); } else { Console.WriteLine("\n\n\nInk is full...\n\n\n"); } } public void Write() { if(inkContent > 0) { Console.WriteLine("\n\n\nInk deducted by 10.\n\n\n"); inkContent -= 10; } else { Console.WriteLine("\n\n\nCannot write! There's no ink. Please refill...\n\n\n"); } } } public class Program { public static void Main() { BoardMarker bm = new BoardMarker("Black", 20); // Initial Values string input; do { Console.WriteLine("MENU"); Console.WriteLine("[1] Display Info"); Console.WriteLine("[2] Change Color"); Console.WriteLine("[3] Refill"); Console.WriteLine("[4] Write"); Console.Write("Input: "); input = Console.ReadLine(); switch(input) { case "1": bm.DisplayInfo(); break; case "2": bm.ChangeColor(); break; case "3": bm.Refill(); break; case "4": bm.Write(); break; default: break; } } while(input != "0"); } }