-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
76 lines (60 loc) · 2.1 KB
/
Program.cs
File metadata and controls
76 lines (60 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
namespace Object_Oriented_Programming_In_CSharp {
public class Program {
static void Main(string[] args) {
Arrow arrow = GetArrow();
Console.WriteLine($"That arrow costs {arrow.Cost} gold.");
}
static Arrow GetArrow() {
ArrowHead arrowhead = GetArrowheadType();
Fletching fletching = GetFletchingType();
float length = GetLength();
return new Arrow(arrowhead, fletching, length);
}
static ArrowHead GetArrowheadType() {
while (true) {
Console.Write("Arrowhead type (steel, wood, obsidian): ");
string input = (Console.ReadLine() ?? "").Trim().ToLower();
switch (input) {
case "steel":
return ArrowHead.Steel;
case "wood":
return ArrowHead.Wood;
case "obsidian":
return ArrowHead.Obsidian;
default:
Console.WriteLine("Invalid choice. Try again.");
break;
}
}
}
static Fletching GetFletchingType() {
while (true) {
Console.Write("Fletching type (plastic, turkey, goose): ");
string input = (Console.ReadLine() ?? "").Trim().ToLower();
switch (input) {
case "plastic":
return Fletching.Plastic;
case "turkey":
return Fletching.TurkeyFeathers;
case "goose":
return Fletching.GooseFeathers;
default:
Console.WriteLine("Invalid choice. Try again.");
break;
}
}
}
static float GetLength() {
while (true) {
Console.Write("Arrow length (60 to 100): ");
if (float.TryParse(Console.ReadLine(), out float length)) {
// Fixed: Using C# logical AND (&&)
if (length >= 60 && length <= 100)
return length;
}
Console.WriteLine("Invalid length. Try again.");
}
}
}
}