网站建设资讯

NEWS

网站建设资讯

java源代码八字,八字算命源码

高分求两个简单的JAVA设计源代码

上面 wuzhikun12同学写的不错,但我想还不能运行,并且还不太完善。我给个能运行的:(注意:文件名为:Test.java)

站在用户的角度思考问题,与客户深入沟通,找到相山网站设计与相山网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站建设、做网站、企业官网、英文网站、手机端网站、网站推广、主机域名、虚拟空间、企业邮箱。业务覆盖相山地区。

//要实现对象间的比较,就必须实现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.computerScore = 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.computerScore = 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 源代码 基础点的 谢谢

package com.regex;

import java.io.*;

import java.net.URLDecoder;

import java.util.regex.*;

public class Regex {

private int REMARK=0;

private int LOGIC=0;

private int PHYSIC=0;

boolean start=false;

/**

* @param args

*/

public static void main(String[] args) { //测试方法

// TODO Auto-generated method stub

Regex re=new Regex();

re.regCount("Regex.java");

System.out.println("remark Line: "+re.REMARK);

System.out.println("logic Line: "+re.LOGIC);

System.out.println("physic Line: "+re.PHYSIC);

}/**

* @author BlueDance

* @param s

* @deprecated count

*/

public void regCount(String s){

String url=null;

try {

url=URLDecoder.decode(this.getClass().getResource(s).getPath(),"UTF-8");

} catch (Exception e) {

e.printStackTrace();

// TODO: handle exception

}

try {

BufferedReader br=new BufferedReader(new FileReader(new File(url)));

String s1=null;

while((s1=br.readLine())!=null){

PHYSIC++;

if(CheckChar(s1)==1){

REMARK++;

System.out.println("纯注释行:"+s1);

}

if(CheckChar(s1)==2){

LOGIC++;

REMARK++;

System.out.println("非纯注释行:"+s1);

}

if(CheckChar(s1)==3)

LOGIC++;

}

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}catch(IOException e){

e.printStackTrace();

}

}

/**

*

* @param s

* @return int

* @version check s

*/

public int CheckChar(String s){

String s1=null;

if(s!=null)

s1=s.trim();

//System.out.println(regCheck(s1,re));

if(regCheck(s1,"(//.*)")) //判断//开头的为纯注释行

return 1;

if(regCheck(s1,"(.*[;{})] *//.*)")) //判断不是//开头的非纯注释行

return 2;

if(regCheck(s1,"(//*.*)")){ //判断/*开头的纯注释行

start=true;

return 1;

}

if(regCheck(s1,"(.*[;{})]//*.*)")){ //判断不是/*开头的非纯注释行

start=true;

return 2;

}

if(regCheck(s1,"(.* */*/)")){ //判断*/结尾的纯注释行

start=false;

return 1;

}

if(regCheck(s1,"(.* */*/.*)")!strCheck(s1)){ //判断不是*/结尾的非纯注释行

if(strCheck(s1)){

start=false;

return 2;

}

}

if(start==true) //状态代码,start即/*开始时start=true*/结束时为false

return 1;

return 3;//ssssllll

}//aeee

/**

*

* @param s

* @param re

* @return boolean

*/

public boolean regCheck(String s,String re){ //正则表达试判断方法

return Pattern.matches(re,s);

}

public boolean strCheck(String s){ //中间有*/的字符判断 此方法最关键

if(s.indexOf("*/")0){

int count=0;

String y[]=s.split("/*/");

boolean boo[]=new boolean[y.length];

for (int i = 0; i y.length-1; i++) {

char c[]=y[i].toCharArray();

for (int j = 0; j c.length; j++) {

if(c[j]=='\\'c[j+1]=='"'){

count++;

}

}

if(count%2==0){

if(countNumber("\"",y[i])%2!=0){

boo[i]=true;

}else{

boo[i]=false;

}

}else{

if(countNumber("\"",y[i])%2==0){

boo[i]=true;

}else{

boo[i]=false;

}

}

}

for(int i=0;iboo.length;i++){

if(!boo[i])

return false;

}

return true;

}

return false;

}

public int countNumber(String s,String y){ //此方法为我前面写的字符串出现次数统计方法,不懂的可以看我前面的文章

int count=0;

String [] k=y.split(s);

if(y.lastIndexOf(s)==(y.length()-s.length()))

count=k.length;

else

count=k.length-1;

if(count==0)

System.out.println ("字符串\""+s+"\"在字符串\""+y+"\"没有出现过");

else

return count;

return -1;

}

}

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class GoodLucky extends JFrame implements ActionListener{

JTextField tf = new JTextField(); //实例化一个文本域

//设置两个按钮

JButton b1 = new JButton("开始");

JButton b2 = new JButton("停止");

boolean isGo = false;

//构造函数

public GoodLucky(){

b1.setActionCommand("start");//在开始按钮上设置一个动作监听 start

JPanel p = new JPanel(); //实例化一个可视化容器

//将两个按钮添加到可视化容器上面,用add方法

p.add(b1);

p.add(b2);

//在两个按钮上增加监听的属性,自动调用下面的监听处理方法actionPerformed(ActionEvent e),如果要代码有更好的可读性,可用内部类实现动作

//监听处理。

b1.addActionListener(this);

b2.addActionListener(this);

//将停止按钮设置为不可编辑(即不可按的状态)

b2.setEnabled(false);

this.getContentPane().add(tf,"North"); //将上面的文本域放在面板的北方,也就是上面(上北下南左西右东)

this.getContentPane().add(p,"South"); //将可视化容器pannel放在南边,也就是下面

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //设置用户在此窗体上发起 "close" 时默认执行的操作,参数EXIT_ON_CLOSE是使用 System exit 方法退出应用程序。仅在应用程序中使用

this.setSize(300,200); //设置面板大小,宽和高

this.setLocation(300,300); //设置面板刚开始的出现的位置

Cursor cu = new Cursor(Cursor.HAND_CURSOR); //用指定名称创建一个新的定制光标对象,参数表示手状光标类型

this.setCursor(cu); //为指定的光标设置光标图像,即设置光标图像为上面所创建的手状光标类型

this.setVisible(true); //将面板可视化设置为true,即可视,如果为false,即程序运行时面板会隐藏

tf.setText("welcome you! "); //设置面板的标题为欢迎

this.go(); //调用go方法

}

public void go(){

while(true){ //这里是死循环,也就是说用户不点击停止按钮的话他一直循环出现随机数,直到用户点击停止按钮循环才能推出,具体流程在actionPerformed方法中控制。

if(isGo == true){ //上面所定义的isGo的初始值为false,所以程序第一次到此会跳过

String s = ""; //设置空字符串

for(int j = 1; j = 7;j++){ //产生7个随机数

int i = (int)(Math.random() * 36) + 1;//每个随机数产生方式,这里定义灵活,可以自由定义随机数产生的方式

if(i 10){

s = s + " 0" + i; //如果产生的随机数小于10的话做处理:这里就牵扯到一个重要的概念,简单叙述一下:

/*

当一个字符串与一个整型数项相加的意思是连接,上面的s = s + " 0" + i的意思是字符串s链接0再连接整型i值,而不会导致0和整型的i相加,

产生的效果为s0i,由于s为空字符串(上面定义过的),所以当i小于零时,在个位数前面加上0,比如产生的随机数i为7的话,显示效果为 07.

*/

}else{

s = s + " " + i; //如果产生的随机数比10打的话,那么加上空格显示,即数字和数字之间有个空格

}

//以上循环循环七次,以保证能出现7个随机数

}

tf.setText(s); //将产生的随机数全部显示在文本域上,用文本域对象tf调用它的设置文本的方法setText(String)实现。

}

//以下为线程延迟

try{

Thread.sleep(10); //线程类同步方法sleep,睡眠方法,括号里的单位为ms。

}catch(java.lang.InterruptedException e){

e.printStackTrace(); //异常捕获,不用多说。

}

}

}

//以下是上面设置的事件监听的具体处理办法,即监听时间处理方法,自动调用

public void actionPerformed(ActionEvent e){ //传入一个动作事件的参数e

String s = e.getActionCommand(); //设置字符串s来存储获得动作监听,上面的start

/*

以下这个条件语句块的作用为:用户点击开始后(捕获start,用方法getActionCommand()),将命令触发设置为true,从而执行上面的go方法中的循环体(因为循环体中要求isGo参数为true,而初始为false)。

执行循环快产生随机数,并将开始按钮不可编辑化,而用户只可以使用停止按钮去停止。如果用户按下停止时,也就是没有传入参数“start”的时候,

执行else语句块中的语句,isGo设置为false,将不执行上面go中的循环语句块,从而停止产生随机数,并显示,并且把开始按钮设置为可用,而把

停止按钮设置为不可用,等待用户按下开始再去开始新一轮循环产生随机数。

*/

if(s.equals("start")){ //如果捕获到start,也就是用户触发了动作监听器,那么下面处理

isGo = true; //设置isGo为true

b1.setEnabled(false); //将开始按钮设置为不可用

b2.setEnabled(true); //将停止按钮设置为可用

}else{

isGo = false; //将isGo设置为false,isGo为循环标志位

b2.setEnabled(false); //设置停止按钮为不可用(注意看是b2,b2是停止按钮)

b1.setEnabled(true); //设置开始按钮为可用

}

}

public static void main(String[] args){

new GoodLucky(); //产生类的实例,执行方法

}

}

Java 源代码的编码问题

//我写了一个程序,你把文字复制到文本框中点转码按钮,就可以了

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JTextArea;

public class Class1 extends JFrame {

private final class AT implements ActionListener {

public void actionPerformed(ActionEvent e) {

jta.setText(fixString(jta.getText()));

}

}

public static void main(String[] args) {

JFrame jf = new Class1();

}

JTextArea jta = new JTextArea();

public Class1() {

setSize(400, 400);

setDefaultCloseOperation(EXIT_ON_CLOSE);

JButton jb = new JButton("转码");

jb.addActionListener(new AT());

add(jta);

add("North", jb);

setVisible(true);

}

String fixString(String s) {

while (true) {

int index = s.indexOf("\\u");

if (index != -1) {

String s1 = s.substring(index, index + 6);

if (s1.matches("\\\\u[0-9A-F]{4}")) {

char c = (char) Integer.parseInt(s1.replace("\\u", ""), 16);

s = s.substring(0, index) + c + s.substring(index + 6);

}

} else {

break;

}

}

return s;

}

}

java根据日期时间换算生辰八字算法。

生辰八字的介绍请参考:

具体算法:

1、设置一个下限年,比如1960,1960年以前的就不给查。并且查万年历,该年节后是庚子年。

2、将天干和地支分别装在两个数组里面。

3、以该年为基准线,设定循环,以查询年为上限年,循环计数器每加一年,天干和地支数组标号各右移一位,然后if判断是否数组到底了,到底了则从头开始。

月、时的算法类似。

求一个简单java程序代码,谢谢

public class TestStar {

public static void main(String[] args) {

String star = "*";

for (int i = 0; i 5; i++) {

if (i == 0) {

System.out.print(" " + star);

System.out.println();

}

if (i == 1) {

for (int z = 0; z 4; z++) {

System.out.print(" " + star);

}

System.out.println();

}

if (i == 2) {

System.out.print(" ");

for (int x = 0; x 3; x++) {

System.out.print(" " + star);

}

System.out.println();

}

if (i == 3) {

for (int y = 0; y 2; y++) {

System.out.print(" " + star + " ");

}

}

}

}

}

是好使的 但是我没找到画五角星有什么规律(五角星好象不是正规图形吧?)如果还有什么要求的话 补充问题(如果是用*填充所有的东西 不包括 “ ”的话 我可以重新再给你写一个)


当前名称:java源代码八字,八字算命源码
网站链接:http://cdweb.net/article/phphgc.html