C#-Assignment 2

Jisu Lee·2022년 11월 3일
0

C# 코드 모음집

목록 보기
2/5
post-thumbnail

다음은 작고 소중한 두 번째 과제(Blooming Patios)입니다.

class MainClass {
  public static void Main (string[] args) {
    //The user inputs the length, width, and depth into the system
    Console.WriteLine("Enter the dimensions of the patio in feet: ");
    Console.WriteLine("Length: ");
		string strLength = Console.ReadLine();
		Console.WriteLine("Width: ");
		string strWidth = Console.ReadLine();
		Console.WriteLine("Depth: ");
		string strDepth = Console.ReadLine();
    
    //System displays error if the user doesn't input a number
    double DValid;
    if (!Double.TryParse(strLength,out DValid))
    {
			Console.WriteLine("Patio dimension must be a number!");
			return;
		}
    
    if (!Double.TryParse(strWidth,out DValid))
    {
			Console.WriteLine("Patio dimension must be a number!");
			return;
		}
    
    if (!Double.TryParse(strDepth,out DValid))
    {
			Console.WriteLine("Patio dimension must be a number!");
			return;
		}

    //System converts the strings into doubles
    double DLength = Convert.ToDouble(strLength);
		double DWidth = Convert.ToDouble(strWidth);
    double DDepth = Convert.ToDouble(strDepth);

    //System displays error if the user doesn't input a positive number
    bool isSignValid = (DLength > 0 && DWidth >0 && DDepth >0);
		if (isSignValid == false)
		{
			Console.WriteLine("Please enter a positive number");
			return;
		}

    //The user inputs the finish type into the system
    Console.WriteLine("Concrete surface can be Flat, Broomed, Stamped" );
    Console.WriteLine("Finish (enter a valid finish type): ");
		string strFinish = Console.ReadLine();

    //System displays error message if the finish type is invalid
    if (strFinish!="Stamped" && strFinish!="Broomed" && strFinish!="Flat")
    {
			Console.WriteLine("Invalid string type requested");
			return;
		}

    //System calculates the patio, volume, #of buggy trips, pouring time, and the additional time for the project
    double DPatio = DLength*DWidth;
    double DVolume = DLength*DWidth*DDepth;
    double DBuggy_Trips = Math.Ceiling(DVolume/9);
    double DPouring_Time = DBuggy_Trips*5;
    double DAdditional_Time=70;

    //Assign different additional time for each finish types
    double DFinish_Time=0;
        
		if (strFinish=="Stamped")
		{
			DFinish_Time=0.2;
		}
		else if (strFinish=="Broomed")
		{
			DFinish_Time=0.1;
		}
		else if (strFinish=="Flat")
		{
			DFinish_Time=0;
		}

    //System calculates the total time of the project
    double DTotal_Time=DPouring_Time+ DFinish_Time*DPatio+ DAdditional_Time;

    //Output of the system
    Console.WriteLine("BloomingPatios Project Estimate");
    Console.WriteLine("---------------------------------------");
    Console.WriteLine("Patio Dimensions (L,W,D) : " +DLength+", "+DWidth+", "+DDepth);
    Console.WriteLine("Concrete Finish : "+strFinish);
    Console.WriteLine("Patio Area: " +DPatio+ " sqft");
    Console.WriteLine("Concrete Needed: " +DVolume+ " cubic ft");
    Console.WriteLine("Number of Buggy Trips: " +DBuggy_Trips);
    Console.WriteLine("Total Project Time: " +DTotal_Time+ " minutes");
    
    }
}

결과값은 다음과 같습니다. 사용자가 폭, 넓이, 깊이를 입력하고 concrete surface의 종류를 입력하면 전체 면적과 콘크리트가 필요한 넓이 및 전체 프로젝트 시간을 도출합니다.

숫자가 아닌 string 혹은 공백이 입력되면 오류 문구를 나타내기도 합니다.

지정된 string이 아닌 다른 값을 입력했을 때도 오류를 띄웁니다.

0개의 댓글