2024年问大家个JAVA编程的问题
class Base {
protected String name;
protected int age;
public Base() {
}
public void SetName(String na) {
name = na;
}
public void SetAge(int a) {
age = a;
}
public String GetName() {
return name;//无返回值
}
public int GetAge() {
return age;//无返回值
}
}
class Engineer extends Base {
protected String major;
protected String prof;
public void SetMajor(String maj) {
major = maj;
}
public void Setprof(String pr) {
prof = pr;
}
public String GetMajor() {
return major;//
}
public String GetProf() {
return prof;
}
}
public class Engieer2 {
public static void main(String args[]) {
Engineer eng = new Engineer();
eng.SetName("李四");
eng.SetAge(40);
eng.SetMajor("计算机");
eng.Setprof("高级教师");
System.out.println(eng.GetName());
System.out.println(eng.GetAge());
System.out.println(eng.GetMajor());
System.out.println(eng.GetProf());
}
}
文件名命名为:Engineer2.java 直接运行
你的程序的问题:1.成员变量的get和set方法自己不知道他们到底什麽用的
2.类层别混乱
大概就上面两个问题,你对照下我上面代码然后自己再仔细的琢磨琢磨,不懂的再问!
#include
#include
#define STU_NUM 10 /*宏定义学生的数量*/
struct student /*定义一个结构体用来存放学生学号、三门课成绩、总分及平均成绩*/
{
char stu_id[20]; /*学生学号;*/
float score[3]; /*三门课成绩;*/
float total; /*总成绩;*/
float aver; /*平均成绩;*/
};
/*排序用一个函数来实现*/
void SortScore(student *stu,int n)
{
student stud;
for(int i = 0; i
for(int j = i+1 ; j
{
if(stu[i].total
{
stud = stu[i];
stu[i] = stu[j];
stu[j] = stud;
}
}
}
int main( )
{
student stu[STU_NUM]; /*创建结构体数组中有10个元素,分别用来保存这10个人的相关信息。*/
/*输入这十个学生的相关信息*/
for(int i = 0; i
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!