用JAVA编写一个课程类Cource
答案:6 悬赏:80 手机版
解决时间 2021-03-28 17:31
- 提问者网友:眉目添风霜
- 2021-03-28 00:23
用JAVA编写一个课程类Cource
最佳答案
- 五星知识达人网友:山君与见山
- 2021-03-28 01:28
public class Course{
private Stirng courseId;//课程号
private Stirng courseName;//课程名
....//课程其他属性
}
public void setCourseId(String courseId){
this.courseId=courseId;
}
public String getCourseId(){
return this.courseId;
}
public void setCourseName(String courseName){
this.courseName=courseName;
}
public String getCourseName(){
return this.courseName;
}
private Stirng courseId;//课程号
private Stirng courseName;//课程名
....//课程其他属性
}
public void setCourseId(String courseId){
this.courseId=courseId;
}
public String getCourseId(){
return this.courseId;
}
public void setCourseName(String courseName){
this.courseName=courseName;
}
public String getCourseName(){
return this.courseName;
}
全部回答
- 1楼网友:爱难随人意
- 2021-03-28 08:12
public class Cource {
protected String cNumber;
protected String cName;
protected int cUnit;
public Cource(String cNumber,String cName,int cUnit)
{ this.cName=cName;
this.cNumber=cNumber;
this.cUnit=cUnit; }
public void setNumber(String number)
{cNumber=number;
}
public void setName(String name)
{cName=name; }
public void setUnit(int unit)
{ cUnit=unit; }
public String getNumber()
{return cNumber; }
public String getName()
{return cName;}
public int getUnit()
{return cUnit;}
public void printCourceInfo()
{
System.out.println("学科编号:"+cNumber);
System.out.println("学科名称:"+cName);
System.out.println("学科学分:"+cUnit);
}}
package javaapplication4;
public class Main {
public static void main(String[] args)
{
Cource java=new Cource("070401","java程序设计",4);
java.printCourceInfo();
} }
望采纳
protected String cNumber;
protected String cName;
protected int cUnit;
public Cource(String cNumber,String cName,int cUnit)
{ this.cName=cName;
this.cNumber=cNumber;
this.cUnit=cUnit; }
public void setNumber(String number)
{cNumber=number;
}
public void setName(String name)
{cName=name; }
public void setUnit(int unit)
{ cUnit=unit; }
public String getNumber()
{return cNumber; }
public String getName()
{return cName;}
public int getUnit()
{return cUnit;}
public void printCourceInfo()
{
System.out.println("学科编号:"+cNumber);
System.out.println("学科名称:"+cName);
System.out.println("学科学分:"+cUnit);
}}
package javaapplication4;
public class Main {
public static void main(String[] args)
{
Cource java=new Cource("070401","java程序设计",4);
java.printCourceInfo();
} }
望采纳
- 2楼网友:酒安江南
- 2021-03-28 06:57
class 课程{
private int cNumber;
private int cUnit;
private String cName;
private static int cToalNum=0;
课程(){
cToalNum++;
}
void setcNumber(int a){
cNumber=a;
}
public int getcNumber(){
return cNumber;
}
void setcUnit(int b){
cUnit=b;
}
public int getcUnit(){
return cUnit;
}
void setcName(String c){
cName=c;
}
public String getcName(){
return cName;
}
void printCourceInfo(){
System.out.println(cNumber+" "+cUnit+" " +cName);
System.out.println(cToalNum);
}
}
class Cource{
public static void main(String args[]){
课程 c1=new 课程();
c1.setcNumber(070401);
c1.setcUnit(3);
c1.setcName("Java程序设计");
c1.printCourceInfo();
}
}
2.编写上题中Cource类的测试程序。class Cource{
String name;
String sex;
int age;
String cource;
int result;
Cource(String a,String b,int c,String d,int e){
name=a;
sex=b;
age=c;
cource=d;
result=e;
}
void setCource(String kc){
cource=kc;
}
public String getCource(){
return cource;
}
public int setResult(int jg){
result=jg;
return result;
}
public boolean getResult(int result){
if(result==1||result==2||result==3||result==4)
return true;
else
return false;
}
void getDetails(){
System.out.println(name+sex+age+cource);
}
}
class Js{
public static void main(String args[]){
CourceJs1=new Cource("张三","男",12,"c语言课程设计",2);
Js1.setCource("数据结构");
Js1.setResult(0);
System.out.println(Js1.getResult(0));
Js1.getDetails();
}
}
private int cNumber;
private int cUnit;
private String cName;
private static int cToalNum=0;
课程(){
cToalNum++;
}
void setcNumber(int a){
cNumber=a;
}
public int getcNumber(){
return cNumber;
}
void setcUnit(int b){
cUnit=b;
}
public int getcUnit(){
return cUnit;
}
void setcName(String c){
cName=c;
}
public String getcName(){
return cName;
}
void printCourceInfo(){
System.out.println(cNumber+" "+cUnit+" " +cName);
System.out.println(cToalNum);
}
}
class Cource{
public static void main(String args[]){
课程 c1=new 课程();
c1.setcNumber(070401);
c1.setcUnit(3);
c1.setcName("Java程序设计");
c1.printCourceInfo();
}
}
2.编写上题中Cource类的测试程序。class Cource{
String name;
String sex;
int age;
String cource;
int result;
Cource(String a,String b,int c,String d,int e){
name=a;
sex=b;
age=c;
cource=d;
result=e;
}
void setCource(String kc){
cource=kc;
}
public String getCource(){
return cource;
}
public int setResult(int jg){
result=jg;
return result;
}
public boolean getResult(int result){
if(result==1||result==2||result==3||result==4)
return true;
else
return false;
}
void getDetails(){
System.out.println(name+sex+age+cource);
}
}
class Js{
public static void main(String args[]){
CourceJs1=new Cource("张三","男",12,"c语言课程设计",2);
Js1.setCource("数据结构");
Js1.setResult(0);
System.out.println(Js1.getResult(0));
Js1.getDetails();
}
}
- 3楼网友:舍身薄凉客
- 2021-03-28 05:21
编写Cource
public class Course {
private int cNumber;
private String cName;
private int cUnit;
public Course(int cNumber, String cName, int cUnit) {
this.cNumber = cNumber;
this.cName = cName;
this.cUnit = cUnit;
}
public void setcNumber(int cNumber) {
this.cNumber = cNumber;
}
public void setcName(String cName) {
this.cName = cName;
}
public void setcUnit(int cUnit) {
this.cUnit = cUnit;
}
public int getcNumber() {
return cNumber;
}
public String getcName() {
return cName;
}
public int getcUnit() {
return cUnit;
}
public void printCourseInfo() {
System.out.println("课程编号: " + cNumber + " 课程名" + cName + " 学分数" + cUnit);
}
}
编写测试类public class TestCourse{
public static void main(String[] args){
Course course=new Course(070401,"Java程序设计",4);
course.printCourseInfo();
}
}
代码是AndroidStudio里写的。测试不了~不过肯定没错的(吧~)
用IDE写的话可以直接生成get set 和构造函数的。这种代码都不怎么需要写的。不过如果是新手的话写多点没坏处。
- 4楼网友:几近狂妄
- 2021-03-28 02:27
首先课程类的单词错误应该是Course 这个类无外乎就是set get方法,只要写好课程编号(cNumber)、课程名(cName)和学分数(cUnit)这几个属性,其他的都可以用Eclipse自动生成,受人以鱼不如受人渔。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯