-
11-07-2013, 07:00 AM #21Junior Member
- Ngày tham gia
- Apr 2014
- Bài viết
- 0
Mã:package baitap; //tạo package nhân sự, trong có 2 class là sinh viên và giảng viên //class sinh viên gồm các thuộc tính: họ tên, lớp học, điểm toán, lý, hóa. //class giảng viên gồm các thuộc tính: họ tên, lớp dạy, năm sinh, lương. //tạo đối tượng học sinh a. //tạo đối tượng giảng viên b. //các giá trị của thuộc tính a và b nhập vào từ bàn phím. //xử lý dữ liệu báo ra thông tin của a và b, tính và báo ra điểm trung bình của a, //xếp loại học lực, báo b có dạy a hay không! //các thuộc tính để private, sử dụng phương thức getter, setter. //lập trình hướng đối tượng! class sinhvien{ private string hotensv; private string lophoc; private float diemtoan, diemly,diemhoa; // dat va lay ho ten public void sethotensv(string ht){ this.hotensv=ht; } public string gethotensv(){ return hotensv; } // dat va lay lop public void setlophoc(string l){ this.lophoc=l; } public string getlophoc(){ return lophoc; } //dat va lay diem toan public void setdiemtoan(float dt){ this.diemtoan=dt; } public float getdiemtoan(){ return diemtoan; } //dat va lay diem ly public void setdiemly(float dl){ this.diemly=dl; } public float getdiemly(){ return diemly; } //dat va lay diem hoa public void setdiemhoa(float dh){ this.diemhoa=dh; } public float getdiemhoa(){ return diemhoa; } public float tinhdiemtb(float dt, float dl, float dh){ float dtb; dtb=(dt+dl+dh)/3; return dtb; } public void xeploaisv(float dtb){ if(dtb>=8.0){ system.out.println("xep loai hoc luc gioi"); } else if(dtb>=6.5){ system.out.println("xep loai hoc luc kha"); } else if(dtb>=5.0){ system.out.println("xep loai hoc luc trung binh"); } else system.out.println("xep loai hoc luc yeu"); } public void insv(){ system.out.println(" ho ten sv:"+this.hotensv+" lop hoc:"+this.lophoc+" diem toan:"+this.diemtoan+" diem ly:"+this.diemly+" diem hoa:"+this.diemhoa); } } class giangvien{ private string lopday,hotengv; private int namsinh; private float luong; // dat lop day va lay lop day public void setlopday(string ld){ this.lopday= ld; } public string getlopdaysv(){ return lopday; } // dat lop day va lay ho ten public void sethotengv(string htgv){ this.hotengv= htgv; } public string gethoten(){ return hotengv; } // dat lop day va lay nam sinh public void setnamsinhgv(int ns){ this.namsinh= ns; } public int getnamsinh(){ return namsinh; } // dat lop day va lay luong public void setluong(float l){ this.luong= l; } public float getluong(){ return luong; } public void ingv(){ system.out.println(" ho ten gv:"+this.hotengv+" lop day:"+this.lopday+" nam sinh:"+this.namsinh+" luong:"+this.luong); } } public class mainsetandget { public static void main(string[] args) { sinhvien sv= new sinhvien(); sv.sethotensv("nguyen a"); sv.setlophoc("cntt"); sv.setdiemtoan(8.0f); sv.setdiemly(9.5f); sv.setdiemhoa(8.0f); sv.insv(); float dtb; dtb= sv.tinhdiemtb(sv.getdiemtoan(), sv.getdiemly(), sv.getdiemhoa()); system.out.println("diem trung binh sinh vien la:"+dtb); sv.xeploaisv(dtb); giangvien gv= new giangvien(); gv.sethotengv("nguyen b"); gv.setlopday("xay dung"); gv.setnamsinhgv(1989); gv.setluong(4000000.0f); gv.ingv(); if(sv.getlophoc().equals(gv.getlopdaysv())) { system.out.println("co day sinh vien"); } else system.out.println("khong day sinh vien"); } }
-
11-07-2013, 07:00 AM #22Junior Member
- Ngày tham gia
- Jan 2015
- Bài viết
- 0
mong các bạn chỉ bảo giúp. cảm ơn!
class sinhvien
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>
show spoiler
hide spoiler
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote>
Mã nguồn PHP:[color=#000000]
package nhansu[/color][color=#007700]; [/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]util[/color][color=#007700].[/color][color=#0000bb]scanner[/color][color=#007700]; public class [/color][color=#0000bb]sinhvien [/color][color=#007700]{ private [/color][color=#0000bb]string hoten[/color][color=#007700], [/color][color=#0000bb]lophoc[/color][color=#007700]; private [/color][color=#0000bb]float toan[/color][color=#007700], [/color][color=#0000bb]ly[/color][color=#007700], [/color][color=#0000bb]hoa[/color][color=#007700]; public [/color][color=#0000bb]string gethoten[/color][color=#007700]() { return [/color][color=#0000bb]hoten[/color][color=#007700]; } public [/color][color=#0000bb]void sethoten[/color][color=#007700]([/color][color=#0000bb]string hoten[/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]hoten [/color][color=#007700]= [/color][color=#0000bb]hoten[/color][color=#007700]; } public [/color][color=#0000bb]string getlophoc[/color][color=#007700]() { return [/color][color=#0000bb]lophoc[/color][color=#007700]; } public [/color][color=#0000bb]void setlophoc[/color][color=#007700]([/color][color=#0000bb]string lophoc[/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]lophoc [/color][color=#007700]= [/color][color=#0000bb]lophoc[/color][color=#007700]; } public [/color][color=#0000bb]float gettoan[/color][color=#007700]() { return [/color][color=#0000bb]toan[/color][color=#007700]; } public [/color][color=#0000bb]void settoan[/color][color=#007700]([/color][color=#0000bb]float toan[/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]toan [/color][color=#007700]= [/color][color=#0000bb]toan[/color][color=#007700]; } public [/color][color=#0000bb]float getly[/color][color=#007700]() { return [/color][color=#0000bb]ly[/color][color=#007700]; } public [/color][color=#0000bb]void setly[/color][color=#007700]([/color][color=#0000bb]float ly[/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]ly [/color][color=#007700]= [/color][color=#0000bb]ly[/color][color=#007700]; } public [/color][color=#0000bb]float gethoa[/color][color=#007700]() { return [/color][color=#0000bb]hoa[/color][color=#007700]; } public [/color][color=#0000bb]void sethoa[/color][color=#007700]([/color][color=#0000bb]float hoa[/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]hoa [/color][color=#007700]= [/color][color=#0000bb]hoa[/color][color=#007700]; } public [/color][color=#0000bb]void nhaptt[/color][color=#007700]() { [/color][color=#0000bb]scanner scan [/color][color=#007700]= new [/color][color=#0000bb]scanner[/color][color=#007700]([/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]in[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
ho ten sv:"[/color][color=#007700]); [/color][color=#0000bb]hoten [/color][color=#007700]= [/color][color=#0000bb]scan[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
lop cua sv:"[/color][color=#007700]); [/color][color=#0000bb]lophoc [/color][color=#007700]= [/color][color=#0000bb]scan[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
diem toan:"[/color][color=#007700]); [/color][color=#0000bb]toan [/color][color=#007700]= [/color][color=#0000bb]scan[/color][color=#007700].[/color][color=#0000bb]nextfloat[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
diem ly:"[/color][color=#007700]); [/color][color=#0000bb]ly [/color][color=#007700]= [/color][color=#0000bb]scan[/color][color=#007700].[/color][color=#0000bb]nextfloat[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
diem hoa:"[/color][color=#007700]); [/color][color=#0000bb]hoa [/color][color=#007700]= [/color][color=#0000bb]scan[/color][color=#007700].[/color][color=#0000bb]nextfloat[/color][color=#007700](); } public [/color][color=#0000bb]float diemtb[/color][color=#007700]() { return (float) ([/color][color=#0000bb]toan [/color][color=#007700]+ [/color][color=#0000bb]ly [/color][color=#007700]+ [/color][color=#0000bb]hoa[/color][color=#007700]) / [/color][color=#0000bb]3[/color][color=#007700]; } public [/color][color=#0000bb]string xeploai[/color][color=#007700]() { if ([/color][color=#0000bb]diemtb[/color][color=#007700]() >= [/color][color=#0000bb]8[/color][color=#007700]) { return [/color][color=#dd0000]"gioi"[/color][color=#007700]; } else { if ([/color][color=#0000bb]diemtb[/color][color=#007700]() >= [/color][color=#0000bb]7[/color][color=#007700]) { return [/color][color=#dd0000]"kha"[/color][color=#007700]; } else { if ([/color][color=#0000bb]diemtb[/color][color=#007700]() >= [/color][color=#0000bb]5[/color][color=#007700]) { return [/color][color=#dd0000]"trung binh"[/color][color=#007700]; } else { return [/color][color=#dd0000]"yeu"[/color][color=#007700]; } } } } public [/color][color=#0000bb]void hientt[/color][color=#007700]() { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
" [/color][color=#007700]+ [/color][color=#0000bb]hoten [/color][color=#007700]+ [/color][color=#dd0000]"\t" [/color][color=#007700]+ [/color][color=#0000bb]lophoc [/color][color=#007700]+ [/color][color=#dd0000]"\t" [/color][color=#007700]+ [/color][color=#0000bb]toan [/color][color=#007700]+ [/color][color=#dd0000]"\t" [/color][color=#007700]+ [/color][color=#0000bb]ly [/color][color=#007700]+ [/color][color=#dd0000]"\t" [/color][color=#007700]+ [/color][color=#0000bb]hoa [/color][color=#007700]+ [/color][color=#dd0000]"\t" [/color][color=#007700]+ [/color][color=#0000bb]diemtb[/color][color=#007700]() + [/color][color=#dd0000]"\t" [/color][color=#007700]+ [/color][color=#0000bb]xeploai[/color][color=#007700]()); }}[/color]
</div>
</div>
class giangvien
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>
show spoiler
hide spoiler
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote>
Mã nguồn PHP:[color=#000000]
package nhansu[/color][color=#007700]; [/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]util[/color][color=#007700].[/color][color=#0000bb]scanner[/color][color=#007700]; public class [/color][color=#0000bb]giangvien [/color][color=#007700]{ private [/color][color=#0000bb]string hoten[/color][color=#007700], [/color][color=#0000bb]lopday[/color][color=#007700]; private [/color][color=#0000bb]int namsinh[/color][color=#007700], [/color][color=#0000bb]luong[/color][color=#007700]; public [/color][color=#0000bb]void nhaptt[/color][color=#007700]() { [/color][color=#0000bb]scanner scan [/color][color=#007700]= new [/color][color=#0000bb]scanner[/color][color=#007700]([/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]in[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
ho ten giang vien:"[/color][color=#007700]); [/color][color=#0000bb]hoten [/color][color=#007700]= [/color][color=#0000bb]scan[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
day lop:"[/color][color=#007700]); [/color][color=#0000bb]lopday [/color][color=#007700]= [/color][color=#0000bb]scan[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
nam sinh:"[/color][color=#007700]); do { [/color][color=#0000bb]namsinh [/color][color=#007700]= [/color][color=#0000bb]scan[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); if ([/color][color=#0000bb]namsinh [/color][color=#007700]< [/color][color=#0000bb]0[/color][color=#007700]) { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap lai nam sinh"[/color][color=#007700]); } } while ([/color][color=#0000bb]namsinh [/color][color=#007700]< [/color][color=#0000bb]0[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
luong giang vien:"[/color][color=#007700]); do { [/color][color=#0000bb]luong [/color][color=#007700]= [/color][color=#0000bb]scan[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); if ([/color][color=#0000bb]luong [/color][color=#007700]< [/color][color=#0000bb]0[/color][color=#007700]) [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap lai luong"[/color][color=#007700]); } while ([/color][color=#0000bb]luong [/color][color=#007700]< [/color][color=#0000bb]0[/color][color=#007700]); } public [/color][color=#0000bb]void hientt[/color][color=#007700]() { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
" [/color][color=#007700]+ [/color][color=#0000bb]hoten [/color][color=#007700]+ [/color][color=#dd0000]"\t" [/color][color=#007700]+ [/color][color=#0000bb]lopday [/color][color=#007700]+ [/color][color=#dd0000]"\t" [/color][color=#007700]+ [/color][color=#0000bb]namsinh [/color][color=#007700]+ [/color][color=#dd0000]"\t" [/color][color=#007700]+ [/color][color=#0000bb]luong[/color][color=#007700]); } public [/color][color=#0000bb]string gethoten[/color][color=#007700]() { return [/color][color=#0000bb]hoten[/color][color=#007700]; } public [/color][color=#0000bb]string getlopday[/color][color=#007700]() { return [/color][color=#0000bb]lopday[/color][color=#007700]; } public [/color][color=#0000bb]int getnamsinh[/color][color=#007700]() { return [/color][color=#0000bb]namsinh[/color][color=#007700]; } public [/color][color=#0000bb]int getluong[/color][color=#007700]() { return [/color][color=#0000bb]luong[/color][color=#007700]; }}[/color]
</div>
</div>
main
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>
show spoiler
hide spoiler
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote>
Mã nguồn PHP:[color=#000000]
package nhansu[/color][color=#007700];[/color][color=#ff8000]//tạo package nhân sự, trong có 2 class là sinh viên và giảng viên//class sinh viên gồm các thuộc tính: họ tên, lớp học, điểm toán, lý, hóa.//class giảng viên gồm các thuộc tính: họ tên, lớp dạy, năm sinh, lương.//tạo đối tượng học sinh a.//tạo đối tượng giảng viên b.//các giá trị của thuộc tính a và b nhập vào từ bàn phím.//xử lý dữ liệu báo ra thông tin của a và b, tính và báo ra điểm trung bình của a,//xếp loại học lực, báo b có dạy a hay không!//các thuộc tính để private, sử dụng phương thức getter, setter.//lập trình hướng đối tượng![/color][color=#007700]public class [/color][color=#0000bb]main [/color][color=#007700]{ public static [/color][color=#0000bb]void main[/color][color=#007700]([/color][color=#0000bb]string[/color][color=#007700][] [/color][color=#0000bb]args[/color][color=#007700]) { [/color][color=#0000bb]sinhvien a[/color][color=#007700]=new [/color][color=#0000bb]sinhvien[/color][color=#007700](); [/color][color=#0000bb]giangvien b[/color][color=#007700]=new [/color][color=#0000bb]giangvien[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
nhap thong tin sinh vien"[/color][color=#007700]); [/color][color=#0000bb]a[/color][color=#007700].[/color][color=#0000bb]nhaptt[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
nhap thong tin giang vien"[/color][color=#007700]); [/color][color=#0000bb]b[/color][color=#007700].[/color][color=#0000bb]nhaptt[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"
thong tin sinh vien da nhap:"[/color][color=#007700]); [/color][color=#0000bb]a[/color][color=#007700].[/color][color=#0000bb]hientt[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"
thong tin giang vien da nhap"[/color][color=#007700]); [/color][color=#0000bb]b[/color][color=#007700].[/color][color=#0000bb]hientt[/color][color=#007700](); if(([/color][color=#0000bb]b[/color][color=#007700].[/color][color=#0000bb]getlopday[/color][color=#007700]()).[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#0000bb]a[/color][color=#007700].[/color][color=#0000bb]getlophoc[/color][color=#007700]())){ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"
giang vien "[/color][color=#007700]+[/color][color=#0000bb]b[/color][color=#007700].[/color][color=#0000bb]gethoten[/color][color=#007700]()+[/color][color=#dd0000]" day sinh vien "[/color][color=#007700]+[/color][color=#0000bb]a[/color][color=#007700].[/color][color=#0000bb]gethoten[/color][color=#007700]()); } else { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"
giang vien "[/color][color=#007700]+[/color][color=#0000bb]b[/color][color=#007700].[/color][color=#0000bb]gethoten[/color][color=#007700]()+[/color][color=#dd0000]" khong day sinh vien "[/color][color=#007700]+[/color][color=#0000bb]a[/color][color=#007700].[/color][color=#0000bb]gethoten[/color][color=#007700]()); } }}[/color]
</div>
</div>
-
11-26-2013, 07:00 AM #23Silver member
- Ngày tham gia
- Aug 2014
- Bài viết
- 0
cho hỏi phương thức kiểm tra b có dạy a ko mình viết trong class giảng viên có được ko ạ? thanks!
-
11-26-2013, 07:00 AM #24Junior Member
- Ngày tham gia
- Jan 2015
- Bài viết
- 0
bạn nào lập trình android thì chú ý việc sử dụng getter và setter nhé.
tips: http://developer.android.com/training/articles/perf-tips.html#getterssetters
-
12-16-2013, 07:00 AM #25Junior Member
- Ngày tham gia
- Jul 2014
- Bài viết
- 0
anh tiasangmoi92: cho em hỏi một chút:
ở phần class giangvien do 1 giảng viên có thể dạy nhiều lớp nên em tạo ra 3 phương thức này:
private string [] lopday =new string [10];
public string[] getlopday() {
return lopday;
}
public void setlopday(string[] lopday) {
this.lopday = lopday;
}
public void input(){
scanner inp =new scanner(system.in);
system.out.println("nhap so lop day:");
int n = inp.nextint();
system.out.println(" nhap ten lop day:");
for(int i=0;i<n;i++){
system.out.println("lop["+i+"]:");
lopday=inp.nextline();
inp.nextline();
}
}
nhưng đến lúc việc xử lí nhập xuất thì không biết như thế nào?
giả sử giảng viên dạy 3 lớp, lúc nhập thì được nhưng đến lúc xuất ra thì em gọi ở hàm main bằng phương thức getlopday(); thì lại không in ra đc. mong bác chỉ giúp/
-
12-24-2013, 07:00 AM #26Junior Member
- Ngày tham gia
- Mar 2014
- Bài viết
- 0
Gửi bởi mr_gru
Mã nguồn PHP:[color=#000000]
[/color][color=#007700]for([/color][color=#0000bb]int i[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700];[/color][color=#0000bb]i[/color][color=#007700]<[/color][color=#0000bb]n[/color][color=#007700];[/color][color=#0000bb]i[/color][color=#007700]++){[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"lop["[/color][color=#007700]+[/color][color=#0000bb]i[/color][color=#007700]+[/color][color=#dd0000]"]:"[/color][color=#007700]);[/color][color=#0000bb]lopday[/color][color=#007700]=[/color][color=#0000bb]inp[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]();[/color][color=#0000bb]inp[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]();}[/color]
Mã nguồn PHP:[color=#000000]
lopday[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]][/color]
-
12-24-2013, 07:00 AM #27Junior Member
- Ngày tham gia
- Jul 2014
- Bài viết
- 0
Gửi bởi tiasangmoi92
Mã:for(int i= 0;i<3;i++){ system.out.println("show ra danh sach lop"+b.getlopday()[i]); }
-
01-21-2014, 07:00 AM #28Junior Member
- Ngày tham gia
- Mar 2015
- Bài viết
- 0
giảng viên:
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>
show spoiler
hide spoiler
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote>
Mã nguồn PHP:[color=#000000]
[/color][color=#007700]public class [/color][color=#0000bb]giangvien [/color][color=#007700]{ private [/color][color=#0000bb]string hoten[/color][color=#007700]; private [/color][color=#0000bb]string lopday[/color][color=#007700]; private [/color][color=#0000bb]int namsinh[/color][color=#007700]; private [/color][color=#0000bb]float luong[/color][color=#007700]; public [/color][color=#0000bb]void sethoten[/color][color=#007700]([/color][color=#0000bb]string hoten[/color][color=#007700]){ [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]hoten [/color][color=#007700]= [/color][color=#0000bb]hoten[/color][color=#007700]; } public [/color][color=#0000bb]string gethoten[/color][color=#007700](){ return [/color][color=#0000bb]hoten[/color][color=#007700]; } public [/color][color=#0000bb]void setlopday[/color][color=#007700]([/color][color=#0000bb]string lopday[/color][color=#007700]){ [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]lopday [/color][color=#007700]= [/color][color=#0000bb]lopday[/color][color=#007700]; } public [/color][color=#0000bb]string getlopday[/color][color=#007700](){ return [/color][color=#0000bb]lopday[/color][color=#007700]; } public [/color][color=#0000bb]void setnamsinh[/color][color=#007700]([/color][color=#0000bb]int namsinh[/color][color=#007700]){ [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]namsinh [/color][color=#007700]= [/color][color=#0000bb]namsinh[/color][color=#007700]; } public [/color][color=#0000bb]int getnamsinh[/color][color=#007700](){ return [/color][color=#0000bb]namsinh[/color][color=#007700]; } public [/color][color=#0000bb]void setluong[/color][color=#007700]([/color][color=#0000bb]float luong[/color][color=#007700]){ [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]luong [/color][color=#007700]= [/color][color=#0000bb]luong[/color][color=#007700]; } public [/color][color=#0000bb]float getluong[/color][color=#007700](){ return [/color][color=#0000bb]luong[/color][color=#007700]; }}[/color]
</div>
</div>
sinh viên:
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>
show spoiler
hide spoiler
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote>
Mã nguồn PHP:[color=#000000]
[/color][color=#007700]public class [/color][color=#0000bb]sinhvien [/color][color=#007700]{ private [/color][color=#0000bb]string hoten[/color][color=#007700]; private [/color][color=#0000bb]string lophoc[/color][color=#007700]; private [/color][color=#0000bb]float toan[/color][color=#007700], [/color][color=#0000bb]ly[/color][color=#007700], [/color][color=#0000bb]hoa[/color][color=#007700]; public [/color][color=#0000bb]void sethoten[/color][color=#007700]([/color][color=#0000bb]string hoten[/color][color=#007700]){ [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]hoten [/color][color=#007700]= [/color][color=#0000bb]hoten[/color][color=#007700]; } public [/color][color=#0000bb]string gethoten[/color][color=#007700](){ return [/color][color=#0000bb]hoten[/color][color=#007700]; } public [/color][color=#0000bb]void setlophoc[/color][color=#007700]([/color][color=#0000bb]string lophoc[/color][color=#007700]){ [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]lophoc [/color][color=#007700]= [/color][color=#0000bb]lophoc[/color][color=#007700]; } public [/color][color=#0000bb]string getlophoc[/color][color=#007700](){ return [/color][color=#0000bb]lophoc[/color][color=#007700]; } public [/color][color=#0000bb]void settoan[/color][color=#007700]([/color][color=#0000bb]float toan[/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]toan [/color][color=#007700]= [/color][color=#0000bb]toan[/color][color=#007700]; } public [/color][color=#0000bb]float gettoan[/color][color=#007700](){ return [/color][color=#0000bb]toan[/color][color=#007700]; } public [/color][color=#0000bb]void setly[/color][color=#007700]([/color][color=#0000bb]float ly[/color][color=#007700]){ [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]ly [/color][color=#007700]= [/color][color=#0000bb]ly[/color][color=#007700]; } public [/color][color=#0000bb]float getly[/color][color=#007700](){ return [/color][color=#0000bb]ly[/color][color=#007700]; } public [/color][color=#0000bb]void sethoa[/color][color=#007700]([/color][color=#0000bb]float hoa[/color][color=#007700]){ [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]hoa [/color][color=#007700]= [/color][color=#0000bb]hoa[/color][color=#007700]; } public [/color][color=#0000bb]float gethoa[/color][color=#007700](){ return [/color][color=#0000bb]hoa[/color][color=#007700]; } public [/color][color=#0000bb]float diemtb[/color][color=#007700](){ return (float)([/color][color=#0000bb]toan [/color][color=#007700]+ [/color][color=#0000bb]ly [/color][color=#007700]+ [/color][color=#0000bb]hoa[/color][color=#007700])/[/color][color=#0000bb]3[/color][color=#007700]; } public [/color][color=#0000bb]string xeploai[/color][color=#007700]([/color][color=#0000bb]float diemtb[/color][color=#007700]){ if ( [/color][color=#0000bb]diemtb [/color][color=#007700]>= [/color][color=#0000bb]8[/color][color=#007700]) return [/color][color=#dd0000]"hoc sinh gioi"[/color][color=#007700]; if ([/color][color=#0000bb]diemtb [/color][color=#007700]>= [/color][color=#0000bb]6.5[/color][color=#007700]) return [/color][color=#dd0000]"hoc sinh kha"[/color][color=#007700]; if ( [/color][color=#0000bb]diemtb [/color][color=#007700]>= [/color][color=#0000bb]5 [/color][color=#007700]) return [/color][color=#dd0000]"hoc sinh trung binh"[/color][color=#007700]; return [/color][color=#dd0000]"hoc sinh yeu"[/color][color=#007700]; }}[/color]
</div>
</div>
main:
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>
show spoiler
hide spoiler
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote>
Mã nguồn PHP:[color=#000000]
[/color][color=#007700]public static [/color][color=#0000bb]void main[/color][color=#007700]([/color][color=#0000bb]string [/color][color=#007700][] [/color][color=#0000bb]args[/color][color=#007700]){ [/color][color=#0000bb]scanner input [/color][color=#007700]= new [/color][color=#0000bb]scanner[/color][color=#007700]([/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]in[/color][color=#007700]); [/color][color=#0000bb]scanner input2 [/color][color=#007700]= new [/color][color=#0000bb]scanner[/color][color=#007700]([/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]in[/color][color=#007700]); [/color][color=#0000bb]sinhvien sv [/color][color=#007700]= new [/color][color=#0000bb]sinhvien[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap ten sinh vien: "[/color][color=#007700]); [/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]sethoten[/color][color=#007700]([/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap lop: "[/color][color=#007700]); [/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]setlophoc[/color][color=#007700]([/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap diem toan:"[/color][color=#007700]); [/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]settoan[/color][color=#007700]([/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextfloat[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap diem ly:"[/color][color=#007700]); [/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]setly[/color][color=#007700]([/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextfloat[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap diem hoa: "[/color][color=#007700]); [/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]sethoa[/color][color=#007700]([/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextfloat[/color][color=#007700]()); [/color][color=#0000bb]giangvien gv [/color][color=#007700]= new [/color][color=#0000bb]giangvien[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap ten giang vien:"[/color][color=#007700]); [/color][color=#0000bb]gv[/color][color=#007700].[/color][color=#0000bb]sethoten[/color][color=#007700]([/color][color=#0000bb]input2[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap lop giang vien giang day:"[/color][color=#007700]); [/color][color=#0000bb]gv[/color][color=#007700].[/color][color=#0000bb]setlopday[/color][color=#007700]([/color][color=#0000bb]input2[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap nam sinh:"[/color][color=#007700]); [/color][color=#0000bb]gv[/color][color=#007700].[/color][color=#0000bb]setnamsinh[/color][color=#007700]([/color][color=#0000bb]input2[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap luong:"[/color][color=#007700]); [/color][color=#0000bb]gv[/color][color=#007700].[/color][color=#0000bb]setluong[/color][color=#007700]([/color][color=#0000bb]input2[/color][color=#007700].[/color][color=#0000bb]nextfloat[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"thong tin sinh vien"[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"ten: " [/color][color=#007700]+ [/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]gethoten[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"lop: " [/color][color=#007700]+ [/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]getlophoc[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"diem toan: " [/color][color=#007700]+ [/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]gettoan[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"diem ly: " [/color][color=#007700]+ [/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]getly[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"diem hoa: " [/color][color=#007700]+ [/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]gethoa[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"diem trung binh: " [/color][color=#007700]+ [/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]diemtb[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"xep loai: " [/color][color=#007700]+ [/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]xeploai[/color][color=#007700]([/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]diemtb[/color][color=#007700]())); if ( [/color][color=#0000bb]gv[/color][color=#007700].[/color][color=#0000bb]getlopday[/color][color=#007700]().[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]getlophoc[/color][color=#007700]())) [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"giang vien: " [/color][color=#007700]+ [/color][color=#0000bb]gv[/color][color=#007700].[/color][color=#0000bb]gethoten[/color][color=#007700]() + [/color][color=#dd0000]" co day sinh vien: " [/color][color=#007700]+ [/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]getlophoc[/color][color=#007700]()); else [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"giang vien: " [/color][color=#007700]+ [/color][color=#0000bb]gv[/color][color=#007700].[/color][color=#0000bb]gethoten[/color][color=#007700]() + [/color][color=#dd0000]" khong day sinh vien: " [/color][color=#007700]+ [/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]getlophoc[/color][color=#007700]()); }[/color]
</div>
</div>
-
02-18-2014, 07:00 AM #29Junior Member
- Ngày tham gia
- Apr 2015
- Bài viết
- 0
[
Mã:/* * to change this license header, choose license headers in project properties. * to change this template file, choose tools | templates * and open the template in the editor. */ package nhansu.thanhkoy.basic; import java.util.scanner; /** * * @author thanh koy */ class thongtin { private string hoten; private string lop; private string truong; private int tuoi; public void sethoten(string hoten){ this.hoten = hoten; } public string gethoten(){ return hoten; } public void setlop(string lop){ this.lop = lop; } public string getlop(){ return lop; } public void settruong(string truong){ this.truong = truong; } public string gettruong(){ return truong; } public void settuoi(int tuoi){ this.tuoi = tuoi; } public int gettuoi(){ return tuoi; } } public class thanhkoy{ public static void main(string[] args) { string ten; int tuoi; string lop; string truong; scanner input = new scanner(system.in); thongtin tt = new thongtin(); system.out.print("nhap ten: "); ten = input.nextline(); system.out.print("lop: "); lop = input.nextline(); system.out.print("tuoi: "); tuoi = input.nextint(); system.out.println("truong: "); truong = input.nextline(); tt.sethoten(ten); tt.setlop(lop); tt.settruong(truong); tt.settuoi(tuoi); system.out.println("sinh vien: "+tt.gethoten()+" tuoi: "+tt.gettuoi()" lop: "+tt.getlop()+" truong: "+tt.gettruong()); } }
mình mới học java. mọi người sửa code giúp mình với!
-
02-20-2014, 07:00 AM #30Junior Member
- Ngày tham gia
- Mar 2015
- Bài viết
- 0
mọi người ơi cho xem hộ mình đoạn code này zới nó có bị lỗi j ko
public void nhapsv()
{
//scanner nhap = new scanner(system.in) ;
system.out.print("nhập tên sinh viên :") ;
name = nhap.nextline() ;
nhap.nextline() ;
system.out.print("nhập lớp của sinh viên :");
classname = nhap.nextline() ;
nhap.nextline() ;
system.out.print("nhập điểm toán của sinh viên") ;
toan = nhap.nextfloat() ;
system.out.print("nhập điểm lý của sinh viên") ;
ly = nhap.nextfloat() ;
system.out.print("nhập điểm hóa của sinh viên") ;
hoa = nhap.nextfloat() ;
}
public void nhapds()
{
sinhvien sv1[] = new sinhvien[50] ;
for (int i = 0 ;i <5 ;i++)
{
system.out.print("nhập tên sinh viên :") ;
sv1.name = nhap.nextline() ;
//nhap.nextline() ;
system.out.print("nhập lớp của sinh viên :");
sv1.classname = nhap.nextline() ;
//nhap.nextline() ;
system.out.print("nhập điểm toán của sinh viên") ;
sv1.toan = nhap.nextfloat() ;
system.out.print("nhập điểm lý của sinh viên") ;
sv1.ly = nhap.nextfloat() ;
system.out.print("nhập điểm hóa của sinh viên") ;
sv1.hoa = nhap.nextfloat() ;
}
}
"căn do xuất tinh ngược này do lượng đường cao dẫn tới thương tổn dây thần kinh tại các cơ vòng khiến người bệnh bị xuất tinh ngược. thường ngày, khi xuất tinh thì cơ thắt cổ bọng đái đóng lại để...
Nguyên nhân và giải pháp cho tình trạng không xuất tinh ở phái mạnh?