资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java大作业源代码 java期末项目大作业源码

Java大一的题目求大神帮忙看看怎么写TAT求源代码

哈哈~网上很多哈,GUI我也不会,现学现卖一个

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

package swing;

import javafx.embed.swing.JFXPanel;

import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.text.DateFormat;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

/**

* @author wenxy

* @create 2020-05-01

*/

public class JavaFxDate {

public static void main(String[] args) {

// 创建 JFrame 实例

JFrame frame = new JFrame();

// Setting the width and height of frame

frame.setSize(310, 180);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

/* 创建面板,这个类似于 HTML 的 div 标签

* 我们可以创建多个面板并在 JFrame 中指定位置

* 面板中我们可以添加文本字段,按钮及其他组件。

*/

JPanel panel = new JPanel();

// 添加面板

frame.add(panel);

/*

* 调用用户定义的方法并添加组件到面板

*/

placeComponents(panel);

// 设置界面可见

frame.setVisible(true);

}

private static void placeComponents(JPanel panel) {

/* 布局部分我们这边不多做介绍

* 这边设置布局为 null

*/

panel.setLayout(null);

// 创建 JLabel

JLabel userLabel = new JLabel("请输入日期字符串");

userLabel.setBounds(5, 5, 300, 25);

panel.add(userLabel);

/*

* 创建文本域用于用户输入

*/

JTextField userText = new JTextField(20);

userText.setBounds(5, 40, 200, 25);

panel.add(userText);

// 创建 JLabel

JLabel showLable = new JLabel();

showLable.setBounds(5, 70, 300, 25);

panel.add(showLable);

// 创建登录按钮

JButton loginButton = new JButton("转换");

loginButton.setBounds(180, 40, 100, 25);

loginButton.addActionListener(new ActionListener() {

DateFormat input = new SimpleDateFormat("yyyy-MM-dd");

DateFormat output = new SimpleDateFormat("yyyy年MM月dd日");

{

input.setLenient(false);    // 设置严格按格式匹配

output.setLenient(false);

}

@Override

public void actionPerformed(ActionEvent actionEvent) {

try {

Date date = convert(userText.getText());

showLable.setText("成功:" + output.format(date));

showLable.setForeground(Color.GREEN);

} catch (WrongDateException e) {

showLable.setText(e.getMessage());

showLable.setForeground(Color.RED);

}

}

private Date convert(String text) throws WrongDateException {

try {

return input.parse(text);

} catch (ParseException e) {

throw new WrongDateException(text);

}

}

});

panel.add(loginButton);

}

static class WrongDateException extends Exception {

WrongDateException(String s) {

super(s + "不是合法的日期字符串");

}

}

}

求java源程序代码:输入两个数,输出最大值

一下代码仅供参考

package com.kidd.test.zhidao;

import java.util.NoSuchElementException;

import java.util.Scanner;

public class Test {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int a = 0;

int b = 0;

boolean next = false;

while (!next) {

System.out.print("请输入两个整数(用空格分隔):");

try {

a = sc.nextInt();

b = sc.nextInt();

next = true;

} catch (NoSuchElementException e) {

System.out.println("输入有误,请重新输入.");

sc.nextLine();

continue;

}

}

System.out.printf("最大值为:%d\n", a  b ? a : b);

}

}

需要一份500行的java程序,期末大作业,最好带详细注释。

Java生成CSV文件简单操作实例

CSV是逗号分隔文件(Comma Separated Values)的首字母英文缩写,是一种用来存储数据的纯文本格式,通常用于电子表格或数据库软件。在 CSV文件中,数据“栏”以逗号分隔,可允许程序通过读取文件为数据重新创建正确的栏结构,并在每次遇到逗号时开始新的一栏。如:

123   1,张三,男2,李四,男3,小红,女   

Java生成CSV文件(创建与导出封装类)

package com.yph.omp.common.util;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import java.io.OutputStreamWriter;

import java.util.ArrayList;

import java.util.Iterator;

import java.util.LinkedHashMap;

import java.util.List;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;

import org.junit.Test;

/**

* Java生成CSV文件

*/

public class CSVUtil {

/**

* 生成为CVS文件

*

* @param exportData

*            源数据List

* @param map

*            csv文件的列表头map

* @param outPutPath

*            文件路径

* @param fileName

*            文件名称

* @return

*/

@SuppressWarnings("rawtypes")

public static File createCSVFile(List exportData, LinkedHashMap map,

String outPutPath, String fileName) {

File csvFile = null;

BufferedWriter csvFileOutputStream = null;

try {

File file = new File(outPutPath);

if (!file.exists()) {

file.mkdir();

}

// 定义文件名格式并创建

csvFile = File.createTempFile(fileName, ".csv",

new File(outPutPath));

// UTF-8使正确读取分隔符","

csvFileOutputStream = new BufferedWriter(new OutputStreamWriter(

new FileOutputStream(csvFile), "GBK"), 1024);

// 写入文件头部

for (Iterator propertyIterator = map.entrySet().iterator(); propertyIterator

.hasNext();) {

java.util.Map.Entry propertyEntry = (java.util.Map.Entry) propertyIterator

.next();

csvFileOutputStream

.write("\"" + (String) propertyEntry.getValue() != null ? (String) propertyEntry

.getValue() : "" + "\"");

if (propertyIterator.hasNext()) {

csvFileOutputStream.write(",");

}

}

csvFileOutputStream.newLine();

// 写入文件内容

for (Iterator iterator = exportData.iterator(); iterator.hasNext();) {

Object row = (Object) iterator.next();

for (Iterator propertyIterator = map.entrySet().iterator(); propertyIterator

.hasNext();) {

java.util.Map.Entry propertyEntry = (java.util.Map.Entry) propertyIterator

.next();

/*-------------------------------*/ 

//以下部分根据不同业务做出相应的更改

StringBuilder sbContext = new StringBuilder("");

if (null != BeanUtils.getProperty(row,(String) propertyEntry.getKey())) {

if("证件号码".equals(propertyEntry.getValue())){

//避免:身份证号码 ,读取时变换为科学记数 - 解决办法:加 \t(用Excel打开时,证件号码超过15位后会自动默认科学记数)

sbContext.append(BeanUtils.getProperty(row,(String) propertyEntry.getKey()) + "\t");

}else{

sbContext.append(BeanUtils.getProperty(row,(String) propertyEntry.getKey()));                         

}

}

csvFileOutputStream.write(sbContext.toString());

/*-------------------------------*/                 

if (propertyIterator.hasNext()) {

csvFileOutputStream.write(",");

}

}

if (iterator.hasNext()) {

csvFileOutputStream.newLine();

}

}

csvFileOutputStream.flush();

} catch (Exception e) {

e.printStackTrace();

} finally {

try {

csvFileOutputStream.close();

} catch (IOException e) {

e.printStackTrace();

}

}

return csvFile;

}

/**

* 下载文件

*

* @param response

* @param csvFilePath

*            文件路径

* @param fileName

*            文件名称

* @throws IOException

*/

public static void exportFile(HttpServletRequest request,

HttpServletResponse response, String csvFilePath, String fileName)

throws IOException {

response.setCharacterEncoding("UTF-8");

response.setContentType("application/csv;charset=GBK");

response.setHeader("Content-Disposition", "attachment; filename="

+ new String(fileName.getBytes("GB2312"), "ISO8859-1"));

InputStream in = null;

try {

in = new FileInputStream(csvFilePath);

int len = 0;

byte[] buffer = new byte[1024];

OutputStream out = response.getOutputStream();

while ((len = in.read(buffer)) 0) {

out.write(buffer, 0, len);

}

} catch (FileNotFoundException e1) {

System.out.println(e1);

} finally {

if (in != null) {

try {

in.close();

} catch (Exception e1) {

throw new RuntimeException(e1);

}

}

}

}

/**

* 删除该目录filePath下的所有文件

*

* @param filePath

*            文件目录路径

*/

public static void deleteFiles(String filePath) {

File file = new File(filePath);

if (file.exists()) {

File[] files = file.listFiles();

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

if (files[i].isFile()) {

files[i].delete();

}

}

}

}

/**

* 删除单个文件

*

* @param filePath

*            文件目录路径

* @param fileName

*            文件名称

*/

public static void deleteFile(String filePath, String fileName) {

File file = new File(filePath);

if (file.exists()) {

File[] files = file.listFiles();

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

if (files[i].isFile()) {

if (files[i].getName().equals(fileName)) {

files[i].delete();

return;

}

}

}

}

}

@SuppressWarnings({ "unchecked", "rawtypes" })

@Test

public void createFileTest() {

List exportData = new ArrayListMap();

Map row1 = new LinkedHashMapString, String();

row1.put("1", "11");

row1.put("2", "12");

row1.put("3", "13");

row1.put("4", "14");

exportData.add(row1);

row1 = new LinkedHashMapString, String();

row1.put("1", "21");

row1.put("2", "22");

row1.put("3", "23");

row1.put("4", "24");

exportData.add(row1);

LinkedHashMap map = new LinkedHashMap();

map.put("1", "第一列");

map.put("2", "第二列");

map.put("3", "第三列");

map.put("4", "第四列");

String path = "d:/export";

String fileName = "文件导出";

File file = CSVUtil.createCSVFile(exportData, map, path, fileName);

String fileNameNew = file.getName();

String pathNew = file.getPath();

System.out.println("文件名称:" + fileNameNew );

System.out.println("文件路径:" + pathNew );

}

}

//注:BeanUtils.getProperty(row,(String) propertyEntry.getKey()) + "\t" ,只为解决数字格式超过15位后,在Excel中打开展示科学记数问题。

java源代码编辑器 设计用于编写Java源代码的编辑器,基本要求:可以完成源程序的文件打开,编辑和文件保存

一. 高亮的内容:

需要高亮的内容有:

1. 关键字, 如 public, int, true 等.

2. 运算符, 如 +, -, *, /等

3. 数字

4. 高亮字符串, 如 "example of string"

5. 高亮单行注释

6. 高亮多行注释

二. 实现高亮的核心方法:

StyledDocument.setCharacterAttributes(int offset, int length, AttributeSet s, boolean replace)

三. 文本编辑器选择.

Java中提供的多行文本编辑器有: JTextComponent, JTextArea, JTextPane, JEditorPane等, 都可以使用. 但是因为语法着色中文本要使用多种风格的样式, 所以这些文本编辑器的document要使用StyledDocument.

JTextArea使用的是PlainDocument, 此document不能进行多种格式的着色.

JTextPane, JEditorPane使用的是StyledDocument, 默认就可以使用.

为了实现语法着色, 可以继承自DefaultStyledDocument, 设置其为这些文本编辑器的documet, 或者也可以直接使用JTextPane, JEditorPane来做. 为了方便, 这里就直接使用JTextPane了.

四. 何时进行着色.

当文本编辑器中有字符被插入或者删除时, 文本的内容就发生了变化, 这时检查, 进行着色.

为了监视到文本的内容发生了变化, 要给document添加一个DocumentListener监听器, 在他的removeUpdate和insertUpdate中进行着色处理.

而changedUpdate方法在文本的属性例如前景色, 背景色, 字体等风格改变时才会被调用.

@Override

public void changedUpdate(DocumentEvent e) {

}

@Override

public void insertUpdate(DocumentEvent e) {

try {

colouring((StyledDocument) e.getDocument(), e.getOffset(), e.getLength());

} catch (BadLocationException e1) {

e1.printStackTrace();

}

}

@Override

public void removeUpdate(DocumentEvent e) {

try {

// 因为删除后光标紧接着影响的单词两边, 所以长度就不需要了

colouring((StyledDocument) e.getDocument(), e.getOffset(), 0);

} catch (BadLocationException e1) {

e1.printStackTrace();

}

}

五. 着色范围:

pos: 指变化前光标的位置.

len: 指变化的字符数.

例如有关键字public, int

单词"publicint", 在"public"和"int"中插入一个空格后变成"public int", 一个单词变成了两个, 这时对"public" 和 "int"进行着色.

着色范围是public中p的位置和int中t的位置加1, 即是pos前面单词开始的下标和pos+len开始单词结束的下标. 所以上例中要着色的范围是"public int".

提供了方法indexOfWordStart来取得pos前单词开始的下标, 方法indexOfWordEnd来取得pos后单词结束的下标.

public int indexOfWordStart(Document doc, int pos) throws BadLocationException {

// 从pos开始向前找到第一个非单词字符.

for (; pos 0 isWordCharacter(doc, pos - 1); --pos);

return pos;

}

public int indexOfWordEnd(Document doc, int pos) throws BadLocationException {

// 从pos开始向前找到第一个非单词字符.

for (; isWordCharacter(doc, pos); ++pos);

return pos;

}

一个字符是单词的有效字符: 是字母, 数字, 下划线.

public boolean isWordCharacter(Document doc, int pos) throws BadLocationException {

char ch = getCharAt(doc, pos); // 取得在文档中pos位置处的字符

if (Character.isLetter(ch) || Character.isDigit(ch) || ch == '_') { return true; }

return false;

}

所以着色的范围是[start, end] :

int start = indexOfWordStart(doc, pos);

int end = indexOfWordEnd(doc, pos + len);

六. 关键字着色.

从着色范围的开始下标起进行判断, 如果是以字母开或者下划线开头, 则说明是单词, 那么先取得这个单词, 如果这个单词是关键字, 就进行关键字着色, 如果不是, 就进行普通的着色. 着色完这个单词后, 继续后面的着色处理. 已经着色过的字符, 就不再进行着色了.

public void colouring(StyledDocument doc, int pos, int len) throws BadLocationException {

// 取得插入或者删除后影响到的单词.

// 例如"public"在b后插入一个空格, 就变成了:"pub lic", 这时就有两个单词要处理:"pub"和"lic"

// 这时要取得的范围是pub中p前面的位置和lic中c后面的位置

int start = indexOfWordStart(doc, pos);

int end = indexOfWordEnd(doc, pos + len);

char ch;

while (start end) {

ch = getCharAt(doc, start);

if (Character.isLetter(ch) || ch == '_') {

// 如果是以字母或者下划线开头, 说明是单词

// pos为处理后的最后一个下标

start = colouringWord(doc, start);

} else {

//SwingUtilities.invokeLater(new ColouringTask(doc, pos, wordEnd - pos, normalStyle));

++start;

}

}

}

public int colouringWord(StyledDocument doc, int pos) throws BadLocationException {

int wordEnd = indexOfWordEnd(doc, pos);

String word = doc.getText(pos, wordEnd - pos); // 要进行着色的单词

if (keywords.contains(word)) {

// 如果是关键字, 就进行关键字的着色, 否则使用普通的着色.

// 这里有一点要注意, 在insertUpdate和removeUpdate的方法调用的过程中, 不能修改doc的属性.

// 但我们又要达到能够修改doc的属性, 所以把此任务放到这个方法的外面去执行.

// 实现这一目的, 可以使用新线程, 但放到swing的事件队列里去处理更轻便一点.

SwingUtilities.invokeLater(new ColouringTask(doc, pos, wordEnd - pos, keywordStyle));

} else {

SwingUtilities.invokeLater(new ColouringTask(doc, pos, wordEnd - pos, normalStyle));

}

return wordEnd;

}

因为在insertUpdate和removeUpdate方法中不能修改document的属性, 所以着色的任务放到这两个方法外面, 所以使用了SwingUtilities.invokeLater来实现.

private class ColouringTask implements Runnable {

private StyledDocument doc;

private Style style;

private int pos;

private int len;

public ColouringTask(StyledDocument doc, int pos, int len, Style style) {

this.doc = doc;

this.pos = pos;

this.len = len;

this.style = style;

}

public void run() {

try {

// 这里就是对字符进行着色

doc.setCharacterAttributes(pos, len, style, true);

} catch (Exception e) {}

}

}

七: 源码

关键字着色的完成代码如下, 可以直接编译运行. 对于数字, 运算符, 字符串等的着色处理在以后的教程中会继续进行详解.

import java.awt.Color;

import java.util.HashSet;

import java.util.Set;

import javax.swing.JFrame;

import javax.swing.JTextPane;

import javax.swing.SwingUtilities;

import javax.swing.event.DocumentEvent;

import javax.swing.event.DocumentListener;

import javax.swing.text.BadLocationException;

import javax.swing.text.Document;

import javax.swing.text.Style;

import javax.swing.text.StyleConstants;

import javax.swing.text.StyledDocument;

public class HighlightKeywordsDemo {

public static void main(String[] args) {

JFrame frame = new JFrame();

JTextPane editor = new JTextPane();

editor.getDocument().addDocumentListener(new SyntaxHighlighter(editor));

frame.getContentPane().add(editor);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setSize(500, 500);

frame.setVisible(true);

}

}

/**

* 当文本输入区的有字符插入或者删除时, 进行高亮.

*

* 要进行语法高亮, 文本输入组件的document要是styled document才行. 所以不要用JTextArea. 可以使用JTextPane.

*

* @author Biao

*

*/

class SyntaxHighlighter implements DocumentListener {

private SetString keywords;

private Style keywordStyle;

private Style normalStyle;

public SyntaxHighlighter(JTextPane editor) {

// 准备着色使用的样式

keywordStyle = ((StyledDocument) editor.getDocument()).addStyle("Keyword_Style", null);

normalStyle = ((StyledDocument) editor.getDocument()).addStyle("Keyword_Style", null);

StyleConstants.setForeground(keywordStyle, Color.RED);

StyleConstants.setForeground(normalStyle, Color.BLACK);

// 准备关键字

keywords = new HashSetString();

keywords.add("public");

keywords.add("protected");

keywords.add("private");

keywords.add("_int9");

keywords.add("float");

keywords.add("double");

}

public void colouring(StyledDocument doc, int pos, int len) throws BadLocationException {

// 取得插入或者删除后影响到的单词.

// 例如"public"在b后插入一个空格, 就变成了:"pub lic", 这时就有两个单词要处理:"pub"和"lic"

// 这时要取得的范围是pub中p前面的位置和lic中c后面的位置

int start = indexOfWordStart(doc, pos);

int end = indexOfWordEnd(doc, pos + len);

char ch;

while (start end) {

ch = getCharAt(doc, start);

if (Character.isLetter(ch) || ch == '_') {

// 如果是以字母或者下划线开头, 说明是单词

// pos为处理后的最后一个下标

start = colouringWord(doc, start);

} else {

SwingUtilities.invokeLater(new ColouringTask(doc, start, 1, normalStyle));

++start;

}

}

}

/**

* 对单词进行着色, 并返回单词结束的下标.

*

* @param doc

* @param pos

* @return

* @throws BadLocationException

*/

public int colouringWord(StyledDocument doc, int pos) throws BadLocationException {

int wordEnd = indexOfWordEnd(doc, pos);

String word = doc.getText(pos, wordEnd - pos);

if (keywords.contains(word)) {

// 如果是关键字, 就进行关键字的着色, 否则使用普通的着色.

// 这里有一点要注意, 在insertUpdate和removeUpdate的方法调用的过程中, 不能修改doc的属性.

// 但我们又要达到能够修改doc的属性, 所以把此任务放到这个方法的外面去执行.

// 实现这一目的, 可以使用新线程, 但放到swing的事件队列里去处理更轻便一点.

SwingUtilities.invokeLater(new ColouringTask(doc, pos, wordEnd - pos, keywordStyle));

} else {

SwingUtilities.invokeLater(new ColouringTask(doc, pos, wordEnd - pos, normalStyle));

}

return wordEnd;

}

/**

* 取得在文档中下标在pos处的字符.

*

* 如果pos为doc.getLength(), 返回的是一个文档的结束符, 不会抛出异常. 如果pos0, 则会抛出异常.

* 所以pos的有效值是[0, doc.getLength()]

*

* @param doc

* @param pos

* @return

* @throws BadLocationException

*/

public char getCharAt(Document doc, int pos) throws BadLocationException {

return doc.getText(pos, 1).charAt(0);

}

/**

* 取得下标为pos时, 它所在的单词开始的下标. ±wor^d± (^表示pos, ±表示开始或结束的下标)

*

* @param doc

* @param pos

* @return

* @throws BadLocationException

*/

public int indexOfWordStart(Document doc, int pos) throws BadLocationException {

// 从pos开始向前找到第一个非单词字符.

for (; pos 0 isWordCharacter(doc, pos - 1); --pos);

return pos;

}

/**

* 取得下标为pos时, 它所在的单词结束的下标. ±wor^d± (^表示pos, ±表示开始或结束的下标)

*

* @param doc

* @param pos

* @return

* @throws BadLocationException

*/

public int indexOfWordEnd(Document doc, int pos) throws BadLocationException {

// 从pos开始向前找到第一个非单词字符.

for (; isWordCharacter(doc, pos); ++pos);

return pos;

}

/**

* 如果一个字符是字母, 数字, 下划线, 则返回true.

*

* @param doc

* @param pos

* @return

* @throws BadLocationException

*/

public boolean isWordCharacter(Document doc, int pos) throws BadLocationException {

char ch = getCharAt(doc, pos);

if (Character.isLetter(ch) || Character.isDigit(ch) || ch == '_') { return true; }

return false;

}

@Override

public void changedUpdate(DocumentEvent e) {

}

@Override

public void insertUpdate(DocumentEvent e) {

try {

colouring((StyledDocument) e.getDocument(), e.getOffset(), e.getLength());

} catch (BadLocationException e1) {

e1.printStackTrace();

}

}

@Override

public void removeUpdate(DocumentEvent e) {

try {

// 因为删除后光标紧接着影响的单词两边, 所以长度就不需要了

colouring((StyledDocument) e.getDocument(), e.getOffset(), 0);

} catch (BadLocationException e1) {

e1.printStackTrace();

}

}

/**

* 完成着色任务

*

* @author Biao

*

*/

private class ColouringTask implements Runnable {

private StyledDocument doc;

private Style style;

private int pos;

private int len;

public ColouringTask(StyledDocument doc, int pos, int len, Style style) {

this.doc = doc;

this.pos = pos;

this.len = len;

this.style = style;

}

public void run() {

try {

// 这里就是对字符进行着色

doc.setCharacterAttributes(pos, len, style, true);

} catch (Exception e) {}

}

}

}

一个JAVA程序,希望高手可以给出源代码,我交作业用,不会做,非常感谢

参考:

public class Circle{

private Point p;

private double radius;

public Circle(Point p, double radius) {

this.p = p;

this.radius = radius;

}

public Point getP() {

return this.p;

}

public void setP(Point p) {

this.p = p;

}

public double getRadius() {

return this.radius;

}

public void setRadius(double radius) {

this.radius = radius;

}

@Override

public String toString() {

return "Circle(Point(" + getP().getX() + "," + getP().getY()

"," + getRadius() +")";

}

public boolean overLap(Circle c){

if (c.getP().distance(this.p) (c.getRadius() + this.radius))

{

return false;

}

else if ((c.getP().distance(this.p) = Math.abs(c.getRadius() + this.radius))

{

return false;

}

else

{

return true;

}

}

public static void main(String[] args) {

Circle c1=new Circle(new Point(10,20),5);

Circle c2=new Circle(new Point(9,8),10);

boolean b=c1.overLap(c2);

if(b){

System.out.println(c1+"与"+c2+"重叠");

}else{

System.out.println(c1+"与"+c2+"不重叠");

}

}

}

求JAVA源代码

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class GradeStatistic {

public static void main(String[] args) {

GradeStatistic gs = new GradeStatistic();

ListMark list = new ArrayListMark();

float sum = 0;

while(true){

Scanner sc = new Scanner(System.in);

System.out.print("Please input student name: ");

String name = sc.nextLine();

if(name.equals("end")){

break;

}

System.out.print("Please input student score: ");

float score = sc.nextFloat();

sum += score;

list.add(gs.new Mark(name, score));

}

float max = list.get(0).getScore();

float min = list.get(0).getScore();

for(Mark mark: list){

if(max mark.getScore()){

max = mark.getScore();

}

if(min mark.getScore()){

min = mark.getScore();

}

}

float average = sum / list.size();

System.out.println("Average is: " + average);

System.out.println("Max is: " + max);

System.out.println("Min is: " + min);

}

private class Mark{

private String name;

private float score;

public Mark(String name, float score){

this.name = name;

this.score = score;

}

public String getName() {

return name;

}

public float getScore() {

return score;

}

}

}

----------------------

Please input student name: Zhang san

Please input student score: 100

Please input student name: Li Si

Please input student score: 91

Please input student name: Ec

Please input student score: 35

Please input student name: ma qi

Please input student score: 67

Please input student name: end

Average is: 73.25

Max is: 100.0

Min is: 35.0


本文名称:java大作业源代码 java期末项目大作业源码
网址分享:http://cdkjz.cn/article/hghohi.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220