
正文
java高级代码题 java高级编程期末考试
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java练习题求完整代码
按照题目要求编写java高级代码题的用javaBean规范设计java高级代码题的学生类Studentjava高级代码题的Java程序如下
需要创建user.java.test包,把Student.java文件和Test.java文件放入包中,编译Student.java文件并且编译运行Test.java文件得到运行结果
Student.java文件代码如下
package user.java.test;
import java.io.Serializable;
public class Student implements Serializable{
private static final long serialVersionUID = 1L;
private String no;
private String name;
private double score;
public Student(){}
public Student(String no,String name,double score){
this.no=no;
this.name=name;
this.score=score;
}
public String getNo(){ return no;}
public void setNo(String no){ this.no=no;}
public String getName(){ return name;}
public void setName(String name){ this.name=name;}
public double getScore(){ return score;}
public void setScore(double score){ this.score=score;}
public String toString(){
return "学号:"+no+",姓名:"+name+",成绩:"+score;
}
public static double getAvg(Student[] sArray){
double sum=0,avg;
for(int i=0;isArray.length;i++){
sum=sum+sArray[i].getScore();
}
avg=sum/sArray.length;
return avg;
}
}
Test.java文件代码如下
package user.java.test;
public class Test{
public static void main(String[] args){
Student[] sArray=new Student[5];
sArray[0]=new Student("001","张三",89.5);
sArray[1]=new Student("002","李四",82.5);
sArray[2]=new Student("003","王五",93);
sArray[3]=new Student("004","赵六",73.5);
sArray[4]=new Student("005","孙七",66);
System.out.println("这些学生的平均分:"+Student.getAvg(sArray));
for(int i=0;isArray.length;i++){
System.out.println(sArray[i].toString());
}
}
}
相关问答
Q1: java 高级编程题
你想要我把程序写出来?
得等二十分钟,而且我现在很懒 不想写了
Q2: java代码题 求java大神解答!必有高分 有追加哦
public static void main(String[] args) {
// TODO Auto-generated method stub
String str="语音类,视频类|callandvideo;短信类,彩信类|MSM;数据类|data;中继类,WLAN,互联网业务,其他|rests";
Map map=new HashMap();
//ListString names=new ArrayList();
SetString names=new HashSet();
String[] temp1=str.split(";");
for(String temp:temp1){
String[] temp2=temp.split("\\|");
String[] temp3=temp2[0].split(",");
for(String name:temp3){
map.put(name, temp2[1]);
}
}
names= map.keySet();
for(String n:names){
System.out.println(n+" == "+ map.get(n));
}
}
Q3: Java编程题!新人,求代码,最好有详细的注解!感谢各位大神~
环境:JDK1.8+。然后复制粘贴代码即可用。
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
public class MainController {
public static void main(String[] args) {
//一.将图一四个人的信息放入list中
ListStudent students = new ArrayList();
Student s1 = new Student("小赵",getTime("1992.08.11"),400);
Student s2 = new Student("小钱",getTime("1995.01.24"),750);
Student s3 = new Student("小孙",getTime("1990.06.05"),670);
Student s4 = new Student("小李",getTime("1991.12.17"),550);
students.add( s1 );
students.add( s2 );
students.add( s3 );
students.add( s4 );
//二.计算四个人成绩的平均值,并输出每个人比平均值多或少多少分。
System.out.println("二.计算四个人成绩的平均值,并输出每个人比平均值多或少多少分。");
average( students );
//三.将四人排序输出,控制台输出结果请参照图二
System.out.println("三.将四人排序输出,控制台输出结果请参照图二");
sort( students );
//四.用递归计算出小赵的成绩以每月2%的增长,多少个月后他的成绩可以超过小钱。
System.out.println("四.用递归计算出小赵的成绩以每月2%的增长,多少个月后他的成绩可以超过小钱。");
markBeyong( students.get(0).getMark() , students.get(1).getMark() );
}
public static void average( ListStudent students ){
int sum = 0;//总成绩
for ( Student student: students ){
sum = sum + student.getMark();
}
int average = sum/students.size();//平均成绩
students.forEach( student - {
if ( student.getMark() average ){
System.out.println( student.getName() + "比平均分高:" + (student.getMark() - average) );
}else if ( student.getMark() average ){
System.out.println( student.getName() + "比平均分低:" + ( average - student.getMark()) );
}else {
System.out.println( student.getName() + "和平均分一样" );
}
} );
}
public static void sort( ListStudent students ){
ListStudent studentBir = new ArrayList();
studentBir.addAll( students );
System.out.println("①第一种排序,按照出生年月日升序;");
Collections.sort( studentBir, (o1, o2) - ( o1.getBirthDay().compareTo( o2.getBirthDay() ) ) );
studentBir.forEach( stu -{
System.out.println( stu.getName() + " | " + getTime(stu.getBirthDay()) + " | " + stu.getMark() );
} );
System.out.println(" ②第二种排序,按照成绩降序;");
ListStudent markDesc = students.stream().sorted((a, b) - b.getMark() - a.getMark()).collect(Collectors.toList());
markDesc.forEach( stu -{
System.out.println( stu.getName() + " | " + getTime(stu.getBirthDay()) + " | " + stu.getMark() );
} );
System.out.println("③比较输出:计算他们互相大多少天,要考虑到闰年。");
for ( int i = 0 ; i students.size() ; i++ ){
for ( int j = i + 1 ; j students.size() ; j++ ){
Long ageSub = students.get( i ).getBirthDay().getTime() - students.get( j ).getBirthDay().getTime();
Long dateSub = ageSub/(1000*60*60*24);
if ( dateSub 0 ){
System.out.println( students.get( i ).getName() + "比" + students.get( j ).getName() + "大" + dateSub );
}else if ( dateSub 0 ){
System.out.println( students.get( i ).getName() + "比" + students.get( j ).getName() + "小" + -dateSub );
}else {
System.out.println( students.get( i ).getName() + "和" + students.get( j ).getName() + "同日出生" );
}
}
}
}
public static void markBeyong( int mark ,int targetMark){
double markDou = mark;
double targetMarkDou = targetMark;
boolean b = true;
int month = 0;
while ( b ){
if ( markDou targetMarkDou ){
markDou = markDou*1.02;
month ++;
}else {
System.out.println("一共用了" + month + "个月反超");
b = false;
}
}
}
public static Date getTime( String target ) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
Date date = sdf.parse(target);
return date;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public static String getTime( Date target ) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
String date = sdf.format( target );
return date;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
class Student {
private String name;
private Date birthDay;
private Integer mark;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getBirthDay() {
return birthDay;
}
public void setBirthDay(Date birthDay) {
this.birthDay = birthDay;
}
public Integer getMark() {
return mark;
}
public void setMark(Integer mark) {
this.mark = mark;
}
public Student(){
}
public Student(String name,Date birthDay , Integer mark){
this.name = name;
this.birthDay = birthDay;
this.mark = mark;
}
}
Q4: JavaEE 高级编程 试题
1、A
2、B
3、B
4、A
5、没有任何输出,main方法没有执行任何代码
6、只能是D,没有两个
7、B
Q5: 求下题代码,java题目。
Java程序:
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* 汽车类
*/
class Car {
/**
* 汽车编号
*/
protected int id = 0;
/**
* 汽车款式
*/
protected String type = null;
/**
* 构造汽车对象
*/
public Car() {
}
/**
* 构造汽车对象
* @param id 汽车编号
* @param type 汽车款式
*/
public Car(int id, String type) {
this.id = id;
this.type = type;
}
/**
* 获得汽车编号
* @return 汽车编号
*/
public int getId() {
return this.id;
}
/**
* 获得汽车款式
* @return 汽车款式
*/
public String getType() {
return this.type;
}
}
/**
* 汽车销售人员类
*/
class Saler {
/**
* 姓名
*/
protected String name = null;
public ListCar cars = new ArrayListCar();
/**
* 构造销售汽车人员对象
*/
public Saler() {
}
/**
* 构造汽车销售人员对象
* @param name 姓名
*/
public Saler(String name) {
this.name = name;
}
/**
* 获得姓名
* @return 姓名
*/
public String getName() {
return this.name;
}
}
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ListCar allCar = new ArrayListCar(); //待售汽车对象的集合
allCar.add(new Car(1001, "凯越"));
allCar.add(new Car(1002, "凯越"));
allCar.add(new Car(1003, "凯越"));
allCar.add(new Car(1004, "凯越"));
allCar.add(new Car(2001, "君威"));
allCar.add(new Car(2002, "君威"));
allCar.add(new Car(2003, "君威"));
allCar.add(new Car(2004, "君威"));
allCar.add(new Car(2005, "君威"));
Saler saler = new Saler("张三其");
int choice = 0;
int type; //销售车型
int num; //销售数量
while(true) {
System.out.println("请选择销售方式");
System.out.println("按车辆销售:\t1");
System.out.println("按车型销售:\t2");
System.out.println("查看销售情况:\t3");
System.out.println("退出:\t\t0");
System.out.print("您的选择:");
choice = scan.nextInt();
switch(choice) {
case 0: //退出系统
System.out.println("退出系统");
System.exit(0);
break;
case 1: //按车辆销售
for(Car car : allCar) {
if(! exists(saler.cars, car)) {
saler.cars.add(car);
System.out.printf("\t售出 %s 1 辆\n", car.getType());
break;
}
}
break;
case 2: //按车型销售
System.out.print("车型(凯越 0/君威 1):");
type = scan.nextInt();
System.out.print("销售数量:");
num = scan.nextInt();
int c = 0; //实际销售数量
for(Car car : allCar) {
if(c = num) {
break;
}
if(car.getType().equals(type == 0 ? "凯越" : "君威") ! exists(saler.cars, car)) {
saler.cars.add(car);
c++;
}
}
if(c num) {
System.out.printf("\t库存不足,实际售出 %s %d 辆\n", type == 0 ? "凯越" : "君威", c);
}
else {
System.out.printf("\t售出 %s %d 辆\n", type == 0 ? "凯越" : "君威", num);
}
break;
case 3: //查看销售情况
System.out.println("\t当前销售情况一览");
System.out.printf("\t%10s%10s\n", "汽车款式", "汽车编号");
for(Car car : saler.cars) {
System.out.printf("\t%10s%10d\n", car.getType(), car.getId());
}
System.out.println("---------------------------");
System.out.printf("\t小计:\t%d 辆\n", saler.cars.size());
break;
default:
break;
}
try {
System.in.read();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//判断car在cars中是否存在
public static boolean exists(ListCar cars, Car car) {
for(Car c : cars) {
if(c.getId() == car.getId()) {
return true;
}
}
return false;
}
}
运行测试:
请选择销售方式
按车辆销售: 1
按车型销售: 2
查看销售情况: 3
退出: 0
您的选择:1
售出 凯越 1 辆
请选择销售方式
按车辆销售: 1
按车型销售: 2
查看销售情况: 3
退出: 0
您的选择:2
车型(凯越 0/君威 1):0
销售数量:3
售出 凯越 3 辆
请选择销售方式
按车辆销售: 1
按车型销售: 2
查看销售情况: 3
退出: 0
您的选择:3
当前销售情况一览
汽车款式 汽车编号
凯越 1001
凯越 1002
凯越 1003
凯越 1004
---------------------------
小计: 4 辆
请选择销售方式
按车辆销售: 1
按车型销售: 2
查看销售情况: 3
退出: 0
您的选择:0
退出系统
java高级代码题的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java高级编程期末考试、java高级代码题的信息别忘了在本站进行查找喔。







