重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
什么项目300行可以搞定?
创新互联建站坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都做网站、网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的含山网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
你这样的提问就是让别人去网上贴一段代码过来,还不如让别人给你介绍几个网站来看的好,建议去看看JAVA社区的东西,蛮有帮助。
/**
* 文件名:Operation.java 2014-1-2 下午3:06:37
* @author Administrator
*/
package cc.icoc.javaxu.action;
import java.util.ArrayList;
import java.util.Scanner;
import cc.icoc.javaxu.datas.StudentInfo;
/**
* @author 许仕永
* 创建时间: 2014 2014-1-2 下午3:06:37
*/
public class Operation
{
int stuNo,stuAge;
String stuName,stuClass,stuSex;
ArrayListStudentInfo list;
/**程序入口
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
new Operation().operation();
}
private int inputInt()
{
Scanner scanner = new Scanner(System.in);
return scanner.nextInt();
}
private String inputStr()
{
Scanner scanner = new Scanner(System.in);
return scanner.nextLine();
}
private void operation()
{
// TODO Auto-generated method stub
if(list == null)
{
list = new ArrayListStudentInfo();
}
while(true)
{
System.out.println("\t\t\t学生信息管理系统\n");
System.out.println("1.信息查阅");
System.out.println("2.信息查询");
System.out.println("3.信息录入");
System.out.println("4.退出系统");
int what = inputInt();
if ( what == 1 )
{
getInfo();
} else if ( what == 2 )
{
allSerach();
} else if ( what == 3 )
{
inputInfo();
} else if( what == 4 )
{
System.out.println("已经退出系统");
System.exit(0);
}
}
}
/**
* 获取全部学生的信息列表
*/
private void getInfo()
{
if(!list.isEmpty())
{
for ( int i = 0; i list.size(); i++ )
{
System.out.println(list.get(i));
}
}
}
/**
* 执行查找
*/
private void allSerach()
{
System.out.println("1.输入学号进行查询");
System.out.println("2.输入姓名进行查询");
int what = inputInt();
if(what == 1)
{
System.out.println("请输入学号:");
search(inputInt());
}
else
{
System.out.println("请输入姓名:");
search(inputStr());
}
}
/**
* 按学生姓名查询学生信息
* @param name 学生姓名
*/
private StudentInfo search(String name)
{
for ( int i = 0; i list.size(); i++ )
{
if(list.get(i).getStuName().equals(name))
{
System.out.println(list.get(i));
return list.get(i);
}
}
System.out.println("未查询到该名字的学生");
return null;
}
/**
* 按学号查询学生信息
* @param id 学号
*/
private StudentInfo search(int id)
{
for ( int i = 0; i list.size(); i++ )
{
if(list.get(i).getStuNo()==id)
{
System.out.println(list.get(i));
return list.get(i);
}
}
System.out.println("未查询到该学号的学生");
return null;
}
/**
* 录入学生信息
*/
private void inputInfo()
{
try
{
System.out.print("请输入学生学号:\n");
stuNo = inputInt();
System.out.print("请输入学生姓名:\n");
stuName = inputStr();
System.out.print("请输入学生性别:\n");
stuSex = inputStr();
System.out.print("请输入学生年龄:\n");
stuAge = inputInt();
System.out.print("请输入学生班级:\n");
stuClass = inputStr();
list.add(new StudentInfo(stuNo, stuAge, stuName, stuSex, stuClass));
} catch (Exception e)
{
// TODO: handle exception
System.out.println("不允许为空,请重新输入");
}
}
}
package cc.icoc.javaxu.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Stu
{
int countStu = 0;
int sum = 0;
int avg = 0;
ListStuBean list = new ArrayListStu.StuBean();
public static void main(String[] args)
{
new Stu().go();
}
private void go()
{
A:while(true)
{
//构造实体Bean来存储学生成绩
StuBean bean = new StuBean();
System.out.println("请输入成绩:");
System.out.println("语文:");
bean.setYuwen(scanner());
System.out.println("数学:");
bean.setMath(scanner());
//获取英语成绩
System.out.println("英语:");
bean.setEnglish(scanner());
//存入容器
list.add(bean);
for ( int i = 0; i list.size(); i++ )
{
sum += list.get(i).english+list.get(i).math+list.get(i).yuwen;
}
avg = sum / (3*list.size());
System.out.println("当前有"+list.size()+"条学生记录,所有学生总分="+sum+"平均分为"+avg);
//输入y继续录入学生信息,输入x退出
System.out.println("\n已成功录入一个学生的数据,是否继续/退出(y/x)");
if("x".equals(scannerString()))
break A;
}
}
/**输入*/
private int scanner()
{
Scanner scanner = new Scanner(System.in);
return scanner.nextInt();
}
/**输入*/
private String scannerString()
{
Scanner scanner = new Scanner(System.in);
return scanner.nextLine();
}
class StuBean
{
int math;
int yuwen;
int english;
public int getMath()
{
return math;
}
public void setMath(int math)
{
this.math = math;
}
public int getYuwen()
{
return yuwen;
}
public void setYuwen(int yuwen)
{
this.yuwen = yuwen;
}
public int getEnglish()
{
return english;
}
public void setEnglish(int english)
{
this.english = english;
}
}
}
/**
* 文件名:StudentInfo.java 2014-1-2 下午3:07:29
* @author Administrator
*/
package cc.icoc.javaxu.datas;
/**
* @author 许仕永
* 创建时间: 2014 2014-1-2 下午3:07:29
*/
public class StudentInfo
{
int stuNo,stuAge;
String stuName,stuSex,stuClass;
public StudentInfo(int stuNo, int stuAge, String stuName, String stuSex, String stuClass)
{
super();
this.stuNo = stuNo;
this.stuAge = stuAge;
this.stuName = stuName;
this.stuSex = stuSex;
this.stuClass = stuClass;
}
public int getStuNo()
{
return stuNo;
}
public void setStuNo(int stuNo)
{
this.stuNo = stuNo;
}
public int getStuAge()
{
return stuAge;
}
public void setStuAge(int stuAge)
{
this.stuAge = stuAge;
}
public String getStuName()
{
return stuName;
}
public void setStuName(String stuName)
{
this.stuName = stuName;
}
public String getStuSex()
{
return stuSex;
}
public void setStuSex(String stuSex)
{
this.stuSex = stuSex;
}
public String getStuClass()
{
return stuClass;
}
public void setStuClass(String stuClass)
{
this.stuClass = stuClass;
}
@Override
public String toString()
{
// TODO Auto-generated method stub
String s = "学号:"+getStuNo()+"\t姓名:"+getStuName()+" \t性别:"+getStuSex()+"\t年龄:"+getStuAge()+"\t班级:"+getStuClass();
return s;
}
}
以1000行为准,超过千行就要考虑类拆分了。
类的代码行数没有特定的行数限制规范。根据实际情况决定。
对于经常使用的java类,代码行数应该尽可能的少,这样能减少java类的加载时间,减少内存频繁占用和回收。如果类过大,java类加载会耗时并且占用内存大。容易引起内存回收。
300行能干啥啊,你还不如自己做做练习题。
package suoha;
import java.util.ArrayList;import java.util.Random;
public class MainFunction {
private ArrayListMyCard cards = new ArrayListMyCard();
private int[] cardNumArr = new int[52];
private int[] mycards = new int[5];
private int[] p1cards = new int[5];
public static void main(String[] args) {
MainFunction mainfunc = new MainFunction();
mainfunc.makeCards();
mainfunc.cardNumArr = mainfunc.shuffleCards(mainfunc.cardNumArr);
mainfunc.catchCards();
mainfunc.showAllCardsOfHand();
//mainfunc.printNums();
}
/**
* 洗牌
* @param cardNums
* @return
*/
private int[] shuffleCards(int[] cardNums){
int size = cardNums.length;
int[] returnNums = new int[size];
//System.out.println(cardNums[0]+"=========================");
Random rand = new Random();
for(int i=size-1;i0;i--){
int nextInt = rand.nextInt(i);
returnNums[size-1-i] = cardNums[nextInt];
cardNums[nextInt] = cardNums[i];
cardNums[i] = returnNums[size-1-i];
//System.out.println("suijishu:"+nextInt+"||zhi:"+returnNums[size-1-i]);
}
returnNums[size-1] = cardNums[0];
return returnNums;
}
/**
* 抓牌
*/
private void catchCards(){
for(int i=0;i5;i++){
mycards[i] = cardNumArr[2*i];
p1cards[i] = cardNumArr[2*i+1];
}
}
private void showAllCardsOfHand(){
System.out.print("你手中的牌是:||");
for(int i=0;i5;i++){
MyCard myCard = cards.get(mycards[i]-1);
System.out.print(myCard.toString()+"||");
}
System.out.println();
System.out.print("对家手中的牌是:||");
for(int i=0;i5;i++){
MyCard myCard = cards.get(p1cards[i]-1);
System.out.print(myCard.toString()+"||");
}
}
/**
* 显示牌的顺序
*/
private void printNums(){
for(int i=0;icardNumArr.length;i++){
System.out.print(cardNumArr[i]+",");
}
}
/**
* 制作卡片
*/
private void makeCards(){
for(int i=1;i=13;i++){
for(int j=1;j=4;j++){
//System.out.println((i-1)*4+j);
MyCard card = new MyCard((i-1)*4+j, j, i);
cardNumArr[(i-1)*4+j-1] = (i-1)*4+j;
cards.add(card);
}
// MyCard card1 = new MyCard((i-1)*4+1, 1, i);
// MyCard card2 = new MyCard((i-1)*4+2, 2, i);
// MyCard card3 = new MyCard((i-1)*4+3, 3, i);
// MyCard card4 = new MyCard((i-1)*4+4, 4, i);
// cards.add(card1);
// cards.add(card2);
// cards.add(card3);
// cards.add(card4);
}
}
}