Posts

Showing posts from May, 2021

Java - Implementation of Thread using Thread

Java - Implementation of Thread using Thread CODE import java . util . Random ; public class Main { public static void main ( String [] args ) throws InterruptedException { SampleThread t1 = new SampleThread ( 10 ); t1 . start (); t1 . join (); System . out . println ( "Input: " + t1 . Input ); System . out . println ( "Output: " + t1 . Output ); } } class SampleThread extends Thread { public int Input ; public int Output ; public SampleThread ( int input ) { this . Input = input ; } public void run () { Output = Input + 10 ; } }

C# - Deck of Cards Program

C# - Deck of Cards Program CODE using System ; using System . Collections . Generic ; using System . Linq ; class Program { static void Main () { Deck d = new Deck (); Console . WriteLine ( d . ToString ()); } } enum Suit { Club = 1 , Diamond = 2 , Heart = 3 , Spades = 4 , } enum CardNumber { Ace = 1 , Two = 2 , Three = 3 , Four = 4 , Five = 5 , Six = 6 , Seven = 7 , Eight = 8 , Nine = 9 , Ten = 10 , Jack = 11 , Queen = 12 , King = 13 , } class Card { private Suit suit ; private CardNumber cardNumber ; public Card ( Suit suit , CardNumber cardNumber ) { this . suit = suit ; this . cardNumber = cardNumber ; } public override string ToString () { return suit + " - " + cardNumber ; } ...

C# - A Simple Clock Implementation

C# - A Simple Clock Implementation CODE using System ; class Program { public static void Main ( string [] args ) { Clock c = new Clock ( 10 , 5 , 0 ); Console . WriteLine ( c . ToString ()); c . Tick (); Console . WriteLine ( c . ToString ()); c . AddSeconds ( 65 ); Console . WriteLine ( c . ToString ()); c . AddSeconds ( 3600 * 24 ); Console . WriteLine ( c . ToString ()); } } class Clock { private int hours ; private int minutes ; private int seconds ; public Clock ( int hours , int minutes , int seconds ) { this . hours = hours ; this . minutes = minutes ; this . seconds = seconds ; if ( hours > 23 || minutes > 59 || seconds > 59 || hours < 0 || minutes < 0 || seconds < 0 ) throw new Exception ( "Please enter a valid time....