任务一:Java面向对象程序设计基础
3
张寒
开始于 2020-02-17 11:35
0 5 150
已截止

任务尚未发布或者你没有权限查看任务内容。

任务讨论
package edu;

/**
 * 
 *姓名:王广超
 *学号:2014011799 
 *班级:14级6班
 *
 */

public class SGtext {

	public static void main(String[] args) {  
		Grade g1 = new Grade("2018011022","English",98);
		Grade g2 = new Grade("2018011023","Math",90);
		Grade g3 = new Grade("2018011024","servlet",96);
		Student s1 = new Student("2018011022","张三丰",g1);
		Student s2 = new Student("2018011023","孙永峰",g2);
		Student s3 = new Student("2018011024","崔浩楠",g3);
		//String str = g1.toString();
		String str1 = s2.toString();
		System.out.println(str1);
		s2.printGrade(g3);
	}

}



/**
 * 
 * 学生表
 *
 */

public class Student {
	private String Sno;
	private String Sname;
	private Grade Sgrade;
	public Student(){}
	public Student(String Sno, String Sname, Grade Sgrade){
		this.Sno = Sno;
		this.Sname = Sname;
		this.Sgrade = Sgrade;
	}
	public String getSno() {
		return Sno;
	}
	public void setSno(String sno) {
		Sno = sno;
	}
	public String getSname() {
		return Sname;
	}
	public void setSname(String sname) {
		Sname = sname;
	}
	public Grade getSgrade() {
		return Sgrade;
	}
	public void setSgrade(Grade sgrade) {
		Sgrade = sgrade;
	}
	@Override
	public String toString() {
		return "学生表: [ 姓名:" + Sname + ", " + Sgrade.toString() + "]";
	}
	public void printGrade(Grade Sgrade){
		if(Sgrade.getSno().contains(this.Sno)){
			System.out.println(" 学号:"+ Sno + " 姓名:" + Sname +" 课程名称:"+ Sgrade.getCourse()+" 课程成绩:" + Sgrade.getScore());
		}else{
			System.out.println("给学生成绩不匹配,请输入正确的成绩表!");
		}
	}
	
}



/**
 * 
 * 成绩表
 *
 */

public class Grade {
	private String Sno;
	private String Course;
	private int Score;
	public Grade(){
	}
	public Grade(String Sno, String Course, int Score){
		this.Sno = Sno;
		this.Course = Course;
		this.Score = Score;
	}
	
	public String getSno() {
		return Sno;
	}
	public void setSno(String sno) {
		Sno = sno;
	}
	public String getCourse() {
		return Course;
	}
	public void setCourse(String course) {
		Course = course;
	}
	public int getScore() {
		return Score;
	}
	public void setScore(int score) {
		Score = score;
	}
	@Override
	public String toString() {
		return "学生成绩表: [学号:" + Sno + ", 课程名称:" + Course + ", 课程成绩:" + Score + "]";
	}
	
}


package edu;

/**
 * 字符流和字节流的基本应用
 */

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;

public class FileWriteRead {

	public static void main(String[] args) {
/**		File dir = new File("G://auto//");
		boolean f = false;
		if(!dir.exists()){
			f = dir.mkdir();
			if(f){
				System.out.println("目录新建成功!"+ dir);
			}
		}
		File file = new File(dir+"//a.txt");
		if(!file.exists()){
			boolean r = false;
			try {
				r = file.createNewFile();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if(r){
				System.out.println("文件黄建成功!");
			}
		}
		file.delete();
		dir.delete();
*/
		
/**		try {
			InputStream instr = new FileInputStream(new File("G://1.jpg"));
			OutputStream output = new FileOutputStream(new File("F://a.txt"));
			int i = 0;
			while(i!=-1){
				i = instr.read();
				output.write(i);
			}
			instr.close();
			output.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
*/		
		
/**		File test = new File("G://test.txt");
		boolean fi = false;
		if(! test.exists()){
			try {
				fi = test.createNewFile();
				if(fi){
//					System.out.println("this file create success! ");
					Writer w = new FileWriter("G://test.txt");
					CharSequence cs = "the file created success!";
//					char c[] = new char[256];
//					String s = "the file created success!";
//					char ss[] = s.toCharArray();
//					for(int i = 0;i<ss.length;i++){
//						c[i] = ss[i];
//					}
					w.append(cs);
					w.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
*/		
		try {
			Reader r = new FileReader("G://test.txt");
			char ar[] = new char[256];
			r.read(ar);
			System.out.println(ar);
			r.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
张寒

任务已更新

张寒

任务已更新

张寒

任务已更新

张寒

任务已更新

张寒

任务已更新