如何使用数据字段创建Java类 [英] How to create a Java class with data fields

查看:88
本文介绍了如何使用数据字段创建Java类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在上一个提供给我一个项目的编程班,但我不知道从哪里开始,并希望有人可以将我推向正确的方向。我只是发布项目的一部分,以便有人可以向我展示一些代码,以了解一下我之前参加过编程课程的情况如何完成工作,但是我没有实践。

I am in a programming class that has provided me with a project but I have no idea where to start and was hoping someone could push me in the right direction. I am only posting part of the project so that someone can show me a bit of the code to get an idea of how its done as I have taken a programming class before but I am out of practice.


创建一个称为Registrar的应用程序,该应用程序具有以下类:

Create an application called Registrar that has the following classes:

Student类,该类至少存储以下数据字段对于学生:

A Student class that minimally stores the following data fields for a student:


  • 姓名

  • 学生证编号

  • 学分数量

还应提供以下方法:


  • 初始化名称和ID字段的构造函数

  • 返回学生姓名字段的方法

  • 设置和获取积分总数的方法

我删除了大部分问题,因为我不是要得到完整的答案,而是要得到这个小样本以尝试继续下去。在项目的其余部分。
对于第二部分,我如何在第二个程序上创建名称和ID并将其检索到带有类的第一个程序中也遇到了麻烦。

I have removed most of the question as I am not trying to get the full answer but to just get this little sample to try to get going on the rest of the project. I am also having trouble with the 2nd part as to how I can create names and ID's on a second program and retrieve them into the first program with the classes.

推荐答案

以下是您需要做的事情的翻译,黑体字是关键词,当您用Google搜索时,很可能会返回与您正在做的事情有关的信息。 / p>

Here is a bit of an translation for what you need to do, the words in bold are keywords that, when googled, will most likely return information relevant to what you are doing.


一个学生类,该类至少为学生存储以下数据字段:

A Student class that minimally stores the following data fields for a student:

这基本上是指创建具有以下属性

This basically means to create a class which has the following properties:


•名称
•学生证号
•学分数量

• Name • Student id number • Number of credits

认真思考这些数据将是什么类型?您需要创建哪种类型来存储某人的姓名?还是他们的ID?记住,这些都是 properties

Think hard about what types of data those would be? What type do you need to create to store somebody's name? Or their Id? Remember, these are all properties


用于初始化名称和ID字段的构造函数

A constructor that initializes the name and id fields

Google 构造函数,并了解它们的工作方式,当学习源讨论如何初始化 properties <时应特别注意/ strong>在构造函数内部。

Google constructor and learn all about how they work, pay special attention when a learning source discusses how to initialize properties inside of the constructor.


返回学生姓名字段的方法

A method that returns the student name field

研究方法,以及如何创建一种方法来返回您的属性学生姓名。了解如何实际使用此方法。

Research about methods and how you can create one to return your property Student Name. Learn how you will actually use this method.


设置和获取积分总数的方法

Methods to set and retrieve the total number of credits

研究字母和字母设置器,并了解它们如何与课程 属性

Research Getters and Setters and understand how they interact with a classes properties

Google是运气最好的朋友,是您在编程中最好的朋友/情人。

Best of luck buddy, google is your best friend/lover in programming..

这篇关于如何使用数据字段创建Java类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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