我目前正在进行下面列出的项目。到目前为止,我在从我的程序访问我的课程有困难。我不知道是我错过了什么,还是我只是一时糊涂。我将包括到目前为止我想出的代码。
你将被评定为:
威基基希尔顿海滩租赁申请:
您将为Waikiki Hilton海滩租赁创建一个项目。在这里,希尔顿酒店的客人可以租用海滩设备,如浮筏、浮潜器、椅子、雨伞和划艇。
您的应用程序将得到客人的名字,项目租用,数量的每一个项目租用和总分钟租用。客人可以想租多少就租多少,也可以多租几件。您可以假设所有项目都是在同一时间框架内租用的。所以一位客人可以租两把椅子,还有潜水用具--但都要65分钟。(不包括15张椅子和45张浮潜器)
您将创建三个类: BeachRentalsApp (将是程序的入口点)、一个用于创建出租对象的租房类( Rental )和一个包含客户信息的来宾类( guestclass )。
BeachRentalsApp -节目开始的地方。这应该会创建一个来宾对象。您的来宾对象包含来宾名称、合同号和一个出租对象数组。应用程序应该显示一条欢迎信息,然后获取客人信息以及租赁信息。在main()方法中显示和收集的所有信息都应该从BeachRentalsApp类中的方法中调用。
包含以下方法:
客人-一个包含客人信息的类。
物业:
构造函数:需要最少的来宾名称来实例化一个来宾对象。
方法:
租赁-描述租赁的类别
适当的构造函数。此类的用户需要最少的租用项才能实例化对象。
静态成员:
物业:
方法
代码:
namespace BeachRentalsApp
{
public class Program
{
public static void Main()
{
Welcome();
string[] RentalList = { "1. Floatation Rafts", "2. Snorkel Gear", "3. Chairs", "4. Umbrellas", "5. Paddle Boat" };
int LenOfArray = RentalList.Length;
for (int i = 0; i < LenOfArray; i++)
{
Console.WriteLine(RentalList[i]);
}
}
public static void Welcome()
{
Console.WriteLine("******************************************");
Console.WriteLine("Welcome to Waikiki Hilton Beach Rentals!");
Console.WriteLine("******************************************");
Console.WriteLine(" ");
Console.WriteLine("You will be asked to enter your name and ");
Console.WriteLine("pick the equipment you would like to rent.");
Console.WriteLine("We hope that you enjoy your stay at Waikiki");
Console.WriteLine("and look forward to serving you again soon!");
Console.WriteLine(" ");
Console.WriteLine("Enter your name to start renting Equipment: ");
string GName = Console.ReadLine();
Console.Clear();
Console.WriteLine("Thank you {0}! Please take a look at equipment selection!", GName);
}
}
class Rentals
{
public int FloatationPrice = 15;
public int SnorkelPrice = 25;
public int ChairPrice = 8;
public int UmbrellaPrice = 10;
public int PaddlePrice = 40;
public int RentTime = 65;
public Rentals()
{
string[] RentalSelection = new string[5];
RentalSelection[0] = "";
RentalSelection[1] = "";
RentalSelection[2] = "";
RentalSelection[3] = "";
RentalSelection[4] = "";
Console.Write("Which equipment would you like to rent?");
RentalSelection[0] = Console.ReadLine();
Console.Write("Would you like to rent more items?");
}
}
}发布于 2019-04-01 23:02:11
对象是包含关于某一项的描述性数据的类。例如,Guest对象将有一些东西,如名称、包含它们的出租列表的数据结构。等。
因此,您应该从创建由赋值定义的Guest对象和由外派定义的租房对象开始。
假设您已经创建了您的对象,您需要访问它们,您是如何做到这一点的:
public static void Main()
{
Welcome(); // Get rid of getting their name in welcome, do it here
Console.WriteLine("Guest name");
String guestName = Console.readLine();
String guestContractNumber = Console.readLine();
if (guestContractNumber.equals("")
{
// Generate a random guestContract number if they didn't provide one
}
// The guest object is created below.
Guest guest = new Guest(guestName, guestContractNumber);
// The rental object is supposed to have the rental types
Rental rental = new Rental();
}我希望这能让你走上正轨。要创建对象(类),您需要:
TestClass testClass = new TestClass();现在您可以访问对象:
testClass.doSomething();如果需要在创建类之前访问类中的数据,则可以在数据成员之前使用静态关键字:
class TestClass
{
public static String testString = "Rental items 1... 2..etc";
}现在你可以做的就是:
TestClass.testString 以获取testString的值。
如果你还需要帮助,我会尽力帮忙的,祝你好运。
https://stackoverflow.com/questions/55464556
复制相似问题