不确定哪个方面是错误的 [英] Not sure which aspect is wrong

查看:73
本文介绍了不确定哪个方面是错误的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定在这种情况下我做错了什么,只需要一些帮助。以下是作业说明:



使用以下规范创建一个名为Course的新类:



类型为String的三个公共字段,如课程名称,教授该课程的讲师姓名和课程提供(课程是在线提供还是现场提供)



两个类型为整数的公共字段,如课程编号和部分。



一种公共方法,可根据用户输入的课程部分设置课程。此方法将课程部分作为参数,并使用if / else语句检查课程部分。在此作业中,假设如果课程部分大于或等于200,则课程设置将设置为等于在线,否则,将设置为等于现场。



向用户询问有关课程的信息,如姓名,编号,部分以及教授该课程的教师,如下面的屏幕所示:



用户单击显示课程信息按钮,您要执行以下操作:



创建新课程类的实例并设置类名称,编号等类字段,部分和教师姓名等于用户输入的内容。



在列表框中显示课程字段的值。我希望您使用列表框,而不是文本框来显示此分配中的信息。因此,当用户在左侧的四个文本框中输入课程信息并单击显示课程信息按钮时,您应该会在列表框中看到这些课程信息,但首先您必须首先将课程字段设置为在上面的步骤i中提到。请参阅以下屏幕:



请注意,我在线提供课程。这是通过调用Course方法并将其传递给用户输入的课程部分来确定的。在上面的屏幕截图中,用户输入201作为课程部分。根据您应该在新课程中创建的方法,课程,因为输入的部分编号(201)大于或等于200,该方法将课程字段,提供,设置为在线。





我的代码:

I am not sure what I have done wrong in this instance, just need a little help. Here is what the assignment instructions are:

Create a new class called Course with the following specification:

Three public fields of type String like name of the course , name of the instructor teaching that course and offering of the course (whether the class is offered online or onsite)

Two public fields of type integers like course number, and section.

One public method that would set the course offering based on the course section that the user enters. This method would take the course section as a parameter, and would check on the course section using an if/else statement. In this assignment, let’s assume that if the course section is greater or equal to 200, then the course offering will be set equal to online, otherwise, it will be set equal to onsite.

Ask the user for information about a course like name, number, section and the instructor teaching that course as can be in the screen below:

When the user clicks on the Display Course information button, you want to do the following:

Create an instance of the new Course class and set the class fields like name, number, section and instructor name equal to what the user enters.

Display the values of the course fields in the list box. I want you to use a list box, not a textbox to display information in this assignment. So, when the user enters the course information in the four textboxes on the left, and clicks the "Display Course Information" button, you should see these course information displayed in the list box, but first you have to set the Course fields first as mentioned in step i above. See screen below:

Notice that I have online as the course offering. This was determined by calling the Course method and passing it the course section that the user entered. In the screen shot above, the user enters 201 for the course section. According to the method that you should create in the new class, Course, since the section number entered (201) is greater or equal to 200, the method set the Course field, offering, to online.


my code:

namespace WPFAssign3
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// 
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }





        private void infobtn_Click(object sender, RoutedEventArgs e)
        {

            int Section = int.Parse(txtsection.Text);

            Course myCourse = new Course();

            myCourse.instructor = txtinstructor.Text;
            myCourse.name = txtname.Text;
            myCourse.Number = int.Parse(txtnumber.Text);



            myCourse.SetOffering(Section);

            courselst.Items.Add(myCourse.name);
            courselst.Items.Add(myCourse.instructor);
            courselst.Items.Add(myCourse.Number);
            courselst.Items.Add(Section);
            courselst.Items.Add(myCourse.GetOffering());

        }

        private void clearbtn_Click(object sender, RoutedEventArgs e)
        {
            courselst.Items.Clear();
        }
    }
    class Course
    {
        public String name;
        public String instructor;
        private int Offering;
        public int Number;
        public int Section;

        public int GetOffering()
        {
            return Offering;
        }

        public void SetOffering(int Section);

        {
         if (Section < 200) 
           {
            Offering = "Onsite"
            }
           else
           { 
           Offering = "Online"
            }
         }
      
  
         
         
    }

        



 
    }
}





我尝试了什么:



我尝试了很多东西,但我似乎无法忍受到达我错误的地方。



What I have tried:

I've tried plenty of things, but I can't seem to get where I went wrong.

推荐答案

提供是一个 int - 所以你不能给它分配一个字符串:



Offering is an int - so you can't assign a string to it:

private int Offering;
...

public int GetOffering()
{
    return Offering;
}

public void SetOffering(int Section);
{
 if (Section < 200)
   {
    Offering = "Onsite"
    }
   else
   {
   Offering = "Online"
    }
 }

您可能希望将 int 更改为 string


引用:

我不知道是什么我在这个例子中做错了,

I am not sure what I have done wrong in this instance,

我要告诉你......我并不是以负面的方式表达这个......这里的错误是不是一个错误的...这是缺乏测试,观察,假设和试验。



你要么没有尝试运行你的代码并观察到哪里以及如何发生错误并尝试更改,设置断点以尝试找到代码中断的确切位置等。或者,如果您已经,由于未知原因您没有告诉我们。



这个过程叫做调试,除非你学会怎么做......那个需要时间......你永远不会成为程序员。



我想看到你进入你的代码,设置断点,在调试中运行代码模式,单步执行代码查看每个断点时的变量值,并在出现错误的代码中进行注释。



鉴于一个世界级的开发环境可用,免费(Visual Studio),它有很好的调试工具,我认为没有理由你不能......现在就忙。



当你遇到困难时,你会回到这里,提出具体问题,特定代码报价和错误描述。



发生的每一个错误在您的代码中有一些东西可以教你!

I am going to tell you ... and I don't mean this in a negative way ... that the "wrong" here is not a "wrong" ... it's a "lack" of testing, and observing, hypothesizing, and experimenting.

You either have not tried running your code and observing where and how errors occur and experimenting with changes, setting break-points to try and locate exactly where the code breaks, etc. Or, if you have done that, for unknown reasons you are not telling us about it.

The process is called "debugging," and, unless you learn how to do it ... and that takes time ... you will never become a programmer.

I'd like to see you go into your code, set break-points, run the code in debug mode, single-step through the code looking at the values of variables when you hit each break-point, and making comments in the code where errors occur.

Given that a world-class development environment is available, free (Visual Studio), and its got great tools for debugging, I see no reason you cannot ... get busy right now.

When you do get stuck, and you will, come back here with specific questions, and specific code quotes, and descriptions of errors.

Every error that occurs in your code has something to teach you !


这篇关于不确定哪个方面是错误的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆