上面 wuzhikun12同學寫的不錯,但我想還不能運行,并且還不太完善。我給個能運行的:(注意:文件名為:Test.java)
成都創新互聯公司是一家以重慶網站建設公司、網頁設計、品牌設計、軟件運維、seo優化、小程序App開發等移動開發為一體互聯網公司。已累計為汽車玻璃修復等眾行業中小客戶提供優質的互聯網建站和軟件開發服務。
//要實現對象間的比較,就必須實現Comparable接口,它里面有個compareTo方法
//Comparable最好使用泛型,這樣,無論是速度還是代碼量都會減少
@SuppressWarnings("unchecked")
class Student implements ComparableStudent{
private String studentNo; //學號
private String studentName; //姓名
private double englishScore; //英語成績
private double computerScore; //計算機成績
private double mathScore; //數學成績
private double totalScore; //總成績
//空構造函數
public Student() {}
//構造函數
public Student(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
this.studentNo = studentNo;
this.studentName = studentName;
this.englishScore = englishSocre;
this點抗 puterScore = computerScore;
this.mathScore = mathScore;
}
//計算總成績
public double sum() {
this.totalScore = englishScore+computerScore+mathScore;
return totalScore;
}
//計算評測成績
public double testScore() {
return sum()/3;
}
//實現compareTO方法
@Override
public int compareTo(Student student) {
double studentTotal = student.getTotalScore();
return totalScore==studentTotal?0:(totalScorestudentTotal?1:-1);
}
//重寫toString方法
public String toString(){
return "學號:"+this.getStudentNo()+" 姓名:"+this.getStudentName()+" 英語成績:"+this.getEnglishScore()+" 數學成績:"+this.getMathScore()+" 計算機成績:"+this.getComputerScore()+" 總成績:"+this.getTotalScore();
}
//重寫equals方法
public boolean equals(Object obj) {
if(obj == null){
return false;
}
if(!(obj instanceof Student)){
return false;
}
Student student = (Student)obj;
if(this.studentNo.equals(student.getStudentName())) { //照現實來說,比較是不是同一個學生,應該只是看他的學號是不是相同
return true;
} else {
return false;
}
}
/*以下為get和set方法,我個人認為,totalScore的set的方法沒必要要,因為它是由其它成績計算出來的
在set方法中,沒設置一次值,調用一次sum方法,即重新計算總成績
*/
public String getStudentNo() {
return studentNo;
}
public void setStudentNo(String studentNo) {
this.studentNo = studentNo;
sum();
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
sum();
}
public double getEnglishScore() {
return englishScore;
}
public void setEnglishScore(double englishScore) {
this.englishScore = englishScore;
sum();
}
public double getComputerScore() {
return computerScore;
}
public void setComputerScore(double computerScore) {
this點抗 puterScore = computerScore;
sum();
}
public double getMathScore() {
return mathScore;
}
public void setMathScore(double mathScore) {
this.mathScore = mathScore;
sum();
}
public double getTotalScore() {
return totalScore;
}
}
//Student子類學習委員類的實現
class StudentXW extends Student {
//重寫父類Student的testScore()方法
@Override
public double testScore() {
return sum()/3+3;
}
public StudentXW() {}
//StudentXW的構造函數
public StudentXW(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
super(studentNo,studentName,englishSocre,computerScore,mathScore);
}
}
//Student子類班長類的實現
class StudentBZ extends Student {
//重寫父類Student的testScore()方法
@Override
public double testScore() {
return sum()/3+5;
}
public StudentBZ() {}
//StudentXW的構造函數
public StudentBZ(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
super(studentNo,studentName,englishSocre,computerScore,mathScore);
}
}
//測試類
public class Test {
public static void main(String[] args) {
//生成若干個student類、StudentXW類、StudentBZ類
Student student1 = new Student("s001","張三",70.5,50,88.5);
Student student2 = new Student("s002","李四",88,65,88.5);
Student student3 = new Student("s003","王五",67,77,90);
StudentXW student4 = new StudentXW("s004","李六",99,88,99.5);
StudentBZ student5 = new StudentBZ("s005","朱漆",56,65.6,43.5);
Student[] students = {student1,student2,student3,student4,student5};
for(int i = 0 ; istudents.length; i++){
double avgScore = students[i].testScore();
System.out.println(students[i].getStudentName()+"學生的評測成績為:"+ avgScore+"分");
}
}
}
運行結果為:
張三學生的評測成績為:69.66666666666667分
李四學生的評測成績為:80.5分
王五學生的評測成績為:78.0分
李六學生的評測成績為:98.5分
朱漆學生的評測成績為:60.03333333333333分
首先需要購買一個服務器,用其放置網站代碼,然后購買域名,域名解析到服務器,然后配置網站站點,然后進行網站開發即可。
Java是一門面向對象編程語言,不僅吸收了C++語言的各種優點,還摒棄了C++里難以理解的多繼承、指針等概念,因此Java語言具有功能強大和簡單易用兩個特征。Java語言作為靜態面向對象編程語言的代表,極好地實現了面向對象理論,允許程序員以優雅的思維方式進行復雜的編程。
Java具有簡單性、面向對象、分布式、健壯性、安全性、平臺獨立與可移植性、多線程、動態性等特點。Java可以編寫桌面應用程序、Web應用程序、分布式系統和嵌入式系統應用程序等。
怎么用java來編寫網頁,目前比較流行的是SSH(struts2+spring+hibernate)框架。其實只要有servlet和JSP基礎就可以實現,框架只是高效的開發和管理。
推薦使用SSH框架進行開發。
使用struts2來實現頁面跳轉,他的標簽也可以寫JSP界面。
使用hibernate來進行數據庫操作的封裝,進行自動管理。
使用spring可以整合以上兩個,使控制權轉移給spring,這個就是控制反轉。
具體頁面怎么寫,這個多看下工具書不難。前臺頁面可以使用HTML來寫,解析速度快,并且頁面開發難度低,排版效果好。
附上SSH實例參考文獻:
一: 首先弄清題目的意思
A.需要的主要組件列表:
1. ?創建一個窗口,窗口標題叫Information
2. ?3個標簽, 用于顯示文字 Name Number Class
3. ?3個文本框, 用于填寫信息
4. ?1個按鈕, ?文字是確認
5. ?1個文本域
B.業務邏輯
1. 當點擊按鈕確認的時候, 把 文本框的信息顯示到文本域
C.設計的主要技術
JLabel , JButton, JTextField ...等, 都是swing的組件 , ?所以應該使用swing進行創建
二: ?確定使用的布局
swing雖然重寫了大部分的組件, 但是布局, 依舊沿襲awt技術
分析圖片上的布局:
至少有2種方法可以實現,?
方法一: 絕對布局 , 優點: ?配合可視化GUI拖曳, 可以完美的實現圖上的組件的位置
但是缺點也是致命的, 不同的操作系統平臺下, 可能會出現位置的移動,
只適合開發平臺, 移植效果差 . ?所以不推薦使用
方法二: 靈活的表格布局, 配合流式布局 , 所有操作系統下,顯示效果都比較統一.?
三: 效果圖
四: 參考代碼
import?java.awt.*;
import?java.awt.event.*;
import?javax.swing.*;
public?class?FrameDemo?extends?JFrame?{
//申明需要的組件
private?final?JTextField?jtf1,jtf2,jtf3;
private?final?JTextArea?jta;
public?FrameDemo()?{
setTitle("Information");//設置窗口標題
setSize(320,?360);//設置窗口大小
setLocationRelativeTo(null);//設置窗口居中
setDefaultCloseOperation(EXIT_ON_CLOSE);//設置關閉時退出虛擬機
getContentPane().setLayout(new?FlowLayout());//設置窗口布局為流式布局
JPanel?jp?=?new?JPanel(new?GridLayout(4,?2));//設置jp面板為表格布局4行2列
//第一行
JPanel?jp01?=?new?JPanel();
JLabel?jl1?=?new?JLabel("Name:");
jp01.add(jl1);
JPanel?jp1?=?new?JPanel();
jtf1?=?new?JTextField(8);
jp1.add(jtf1);
//第二行
JPanel?jp02?=?new?JPanel();
JLabel?jl2?=?new?JLabel("Number:");
jp02.add(jl2);
JPanel?jp2?=?new?JPanel();
jtf2?=?new?JTextField(8);
jp2.add(jtf2);
//第三行
JPanel?jp03?=?new?JPanel();
JLabel?jl3?=?new?JLabel("Class:");
jp03.add(jl3);
JPanel?jp3?=?new?JPanel();
jtf3?=?new?JTextField(8);
jp3.add(jtf3);
//第四行
JPanel?jp04?=?new?JPanel();
JLabel?jl4?=?new?JLabel("");
jp04.add(jl4);
JPanel?jp4?=?new?JPanel();
JButton?jb?=?new?JButton("確認");
jp4.add(jb);
jp.add(jp01);
jp.add(jp1);
jp.add(jp02);
jp.add(jp2);
jp.add(jp03);
jp.add(jp3);
jp.add(jp04);
jp.add(jp4);
getContentPane().add(jp);
jta?=?new?JTextArea();
jta.setColumns(20);//設置文本域的大小
jta.setEditable(false);//設置文本域不可編輯
jta.setBackground(jp.getBackground());//設置文本域的背景色和面板一樣
getContentPane().add(jta);
jb.addActionListener(new?ActionListener()?{//給按鈕添加事件
public?void?actionPerformed(ActionEvent?e)?{//點擊按鈕,顯示信息到文本域
String?name?=?jtf1.getText();
String?number?=?jtf2.getText();
String?clazz?=?jtf3.getText();
jta.setText("You?name?is?"+name+"?number?is?"+number+"?class?is?"+clazz);
}
});
}
public?static?void?main(String[]?args)?{
new?FrameDemo().setVisible(true);//創建窗口,被設置為可見
}
}
五: 拓展
雖然圖形界面的實現方法是多樣的, ?我們一定要根據具體情況, 選擇一個比較優化的 合理的, 符合業務邏輯的實現方法
本文標題:java網站設計代碼 javaweb網站源碼
網頁鏈接:http://vcdvsql.cn/article10/ddipcgo.html
成都網站建設公司_創新互聯,為您提供做網站、ChatGPT、網站設計、軟件開發、動態網站、商城網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯