我无法让两个班级正确沟通。我需要有两个课程,否则这不会有问题。
问题:
编写一个控制台应用程序,要求用户输入批发价格,然后显示加价百分比价格。您需要格式化每一行,以便它们都可以显示在单个命令屏幕上。 创建一个类/对象来完成计算的实际工作(业务层)。本练习中不需要数据类。为业务层使用实例化对象。
我知道我错过了什么,但我不确定它是什么。
我有什么:
namespace ConsoleApplication1
{
class BusinessClass
{
static void Main(string[] args)
{
MarkupClass item1 = new MarkupClass();
Console.WriteLine("what is the whole sale cost: ");
item1.wholeSaleCost = decimal.Parse(Console.ReadLine());
}
}
class MarkupClass
{
private decimal markupPercent = 1.05m;
public decimal wholeSaleCost;
public decimal DoCalculations(decimal wholeSaleCostIn)
{
while (markupPercent < 1.11m)
{
decimal finalCost;
finalCost = wholeSaleCostIn * markupPercent;
Console.WriteLine("The wholesale price is: {0} and the final selling price is {1}", wholeSaleCostIn, finalCost);
markupPercent = markupPercent += 0.01m;
}
return markupPercent;
}
}
}
如果这只是一个课程就很容易,但问题需要两个课程。
答案 0 :(得分:0)
您需要阅读并理解有关面向对象编程基础知识的更多信息
暂时尝试执行并理解该程序。我做了你期待的改变。我没有做太多修改,但这应该可以开始。
using System;
namespace ConsoleApplication1
{
class BusinessClass
{
static void Main(string[] args)
{
MarkupClass item1 = new MarkupClass();
Console.WriteLine("what is the whole sale cost: ");
decimal wholeSaleCost = decimal.Parse(Console.ReadLine());
decimal markupPercent = item1.DoCalculations(wholeSaleCost);
Console.WriteLine("Final % is : {0}",markupPercent);
}
}
class MarkupClass
{
private decimal markupPercent = 1.05m;
public decimal wholeSaleCost;
public decimal DoCalculations(decimal wholeSaleCostIn)
{
while (markupPercent < 1.11m)
{
decimal finalCost;
finalCost = wholeSaleCostIn * markupPercent;
Console.WriteLine("The wholesale price is: {0} and the final selling price is {1}", wholeSaleCostIn, finalCost);
markupPercent += 0.01m;
}
return markupPercent;
}
}
}
答案 1 :(得分:-1)
你想调用DoCalculations
函数来执行计算
MarkupClass item1 = new MarkupClass();
Console.WriteLine("what is the whole sale cost: ");
string input = Console.ReadLine(); //getting value in string format
decimal input_decimal = Decimal.Parse(input); // caste string input into decimal
item1.wholeSaleCost = item1.DoCalculations(input_decimal); // pass it to DoCalculations to do calculation