private void SetUpReportDatabase() { cellphone = new Assembly("CP-7734", "Cell Phone"); PiecePart display = new PiecePart("DS-1428", "LCD Display", 14.37); PiecePart speaker = new PiecePart("SP-92", "Speaker", 3.50); PiecePart microphone = new PiecePart("MC-28", "Microphone", 5.30); PiecePart cellRadio = new PiecePart("CR-56", "Cell Radio", 30); PiecePart frontCover = new PiecePart("FC-77", "Front Cover", 1.4); PiecePart backCover = new PiecePart("RC-77", "RearCover", 1.2); Assembly keypad = new Assembly("KP-62", "Keypad"); Assembly button = new Assembly("B52", "Button"); PiecePart buttonCover = new PiecePart("CV-15", "Cover", .5); PiecePart buttonContact = new PiecePart("CN-2", "Contact", 1.2); button.Add(buttonCover); button.Add(buttonContact); for (int i = 0; i < 15; i++) { keypad.Add(button); } cellphone.Add(display); cellphone.Add(speaker); cellphone.Add(microphone); cellphone.Add(cellRadio); cellphone.Add(frontCover); cellphone.Add(backCover); cellphone.Add(keypad); }
public void Assembly() { a.Add(p1); a.Add(p2); Assert.AreEqual(2, a.Parts.Count); PiecePart p = a.Parts[0] as PiecePart; Assert.AreEqual(p, p1); p = a.Parts[1] as PiecePart; Assert.AreEqual(p, p2); }
public static void Pianist() { var numberOfPieces = int.Parse(Console.ReadLine()); var listOfPieces = new List <PiecePart>(); while (listOfPieces.Count < numberOfPieces) { var currentPieceLine = Console.ReadLine().Split("|"); listOfPieces.Add(new PiecePart { Piece = currentPieceLine[0], Composer = currentPieceLine[1], Key = currentPieceLine[2] }); } var commandLine = Console.ReadLine(); while (commandLine != "Stop") { var splitCommand = commandLine.Split("|"); var command = splitCommand[0]; var pieceToActWith = new PiecePart(); switch (command) { case "Add": pieceToActWith.Piece = splitCommand[1]; pieceToActWith.Composer = splitCommand[2]; pieceToActWith.Key = splitCommand[3]; if (listOfPieces.Any(x => x.Piece == pieceToActWith.Piece)) { Console.WriteLine($"{pieceToActWith.Piece} is already in the collection!"); } else { Console.WriteLine($"{pieceToActWith.Piece} by {pieceToActWith.Composer} in {pieceToActWith.Key} added to the collection!"); listOfPieces.Add(pieceToActWith); } break; case "Remove": pieceToActWith.Piece = splitCommand[1]; if (listOfPieces.Any(x => x.Piece == pieceToActWith.Piece)) { Console.WriteLine($"Successfully removed {pieceToActWith.Piece}!"); var pieceToRemove = listOfPieces.First(x => x.Piece == pieceToActWith.Piece); listOfPieces.Remove(pieceToRemove); } else { Console.WriteLine($"Invalid operation! {pieceToActWith.Piece} does not exist in the collection."); } break; case "ChangeKey": pieceToActWith.Piece = splitCommand[1]; pieceToActWith.Key = splitCommand[2]; if (listOfPieces.Any(x => x.Piece == pieceToActWith.Piece)) { listOfPieces.First(x => x.Piece == pieceToActWith.Piece).Key = pieceToActWith.Key; Console.WriteLine($"Changed the key of {pieceToActWith.Piece} to {pieceToActWith.Key}!"); } else { Console.WriteLine($"Invalid operation! {pieceToActWith.Piece} does not exist in the collection."); } break; } commandLine = Console.ReadLine(); } foreach (var listOfPiece in listOfPieces.OrderBy(x => x.Piece).ThenBy(x => x.Composer)) { Console.WriteLine($"{listOfPiece.Piece} -> Composer: {listOfPiece.Composer}, Key: {listOfPiece.Key}"); } }
public void SetUp() { p1 = new PiecePart("997624", "MyPart", 3.20); p2 = new PiecePart("7734", "Hell", 666); a = new Assembly("5879", "MyAssembly"); }
public void Visit(PiecePart pp) { visitedParts.Add(pp); }
public void Visit(PiecePart pp) { cost += pp.Cost; }