What's new

Help Deleted

Status
Not open for further replies.
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();
 
Last edited:
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();
Salamat po sapag pansin.


Kaya kang paps. Yung pag papalit ng color user input po yun. No need ng mag cide ng mga color.
 
yung code na goto userIn; lagay mo after ng switch para di paulit-ulit
tsaka nagana ba yun? same kasi name ng variable mo userIn din

1 at 4 lang ata tama,,
sa 1, instead na "Result:" dapat "- - Ink Info - -"
 
Last edited:
Paano ka magpapalit ng color kung hindi ka hihingi ng new color from the user?
yung "Green", palitan mo yun ng variable na may value from the user.
Example lang yun, meaning gawa ka method na merong string parameter
 
[XX='mrHazan, c: 456632, m: 489435'][/XX] onga while (userIn != 0) na lang.. kaso baka di pa naturo loops
 
[XX='mrHazan, c: 456635, m: 489435'][/XX] baka isipin ng prof pinagawa pag may methods at parameter na haha
 
Nakalagay naman ata sa instruction sa kanila na gumawa ng methods as member ng struct na BoardMarker
 
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");
        
    }
}
 
Lods. Gusto koto aralin sayo para matama ko yung akin. Pede ba palagyan ng comments kung hindi ka busy?. Salamat po.
 
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");
       
    }
}
Ayan pong PT2 ang pinapagawa.
 

Attachments

Ang problema kolng jan. Is kapag yung inkiConten ay Zero na and then pag mag papalit ako ng kulay dapat hindi makakapag palit kase need muna mag refill kase zero na.
 
[XX='G I N E B R A, c: 456801, m: 1031988'][/XX] mali ata intindi mo, sabi sa tanong "Note: You cannot change the color if the ink is not empty"
ibig sabihin kailangan muna ubusin bago magpalit,
bawal magpalit pag may laman pa
 
[XX='G I N E B R A, c: 456801, m: 1031988'][/XX] kaya andon na yung sagot sa code ni mrHazan sa ChangeColor() if else
 
Status
Not open for further replies.

Similar threads

Back
Top