JAVA实训第三次作业

package 实训作业3;

import java.util.Scanner;

public class Student {
    String name;
    String sex;
    int age;
    String ID;
    int score[] = new int [5];
   
public void qw() {
    System.out.print("姓名:"+name+",性别:"+sex+",年龄:"+age+",学号:"+ID);
    System.out.print(",成绩:");
    for(int i = 0;i < 5;i++) {
        System.out.print(" "+score[i]);
    }
}
public double as() {
    double aveScore = 0;
    int sum = 0;
    for(int i = 0;i < 5;i++) {
        sum = sum+score[i];
    }
    aveScore = sum/5;
    return aveScore;
}
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        @SuppressWarnings("unused")
        int[] score = new int [5];
        @SuppressWarnings("resource")
        Scanner aa = new Scanner(System.in);
        Student t = new Student();
        System.out.print("姓名,性别,年龄,学号\n");
        t.name = aa.next();
        t.sex = aa.next();
        t.age = aa.nextInt();
        t.ID = aa.next();
        System.out.print("请输入成绩:");
        for(int i = 0;i < 5;i++) {
            t.score[i] = aa.nextInt();
        }
        t.qw();
        System.out.print("\n平均成绩:"+t.as());
    }
}

package 实训作业3;

import java.util.Scanner;

public class LibraryCard {
    String ID;
    String name;
    String IDCard;
    String site;
    int i,j = 10,k,L;//i:已借书数  j:可借书数   k:本次借书数  L:本次还书数

public void qw() {
    j = j-k;
    System.out.print("账号"+ID+",姓名"+name+",身份证"+IDCard+",地址"+site+",本次借书数"+k+",可借书数"+j+"\n");
}
public void as() {
    j = j+L;
    System.out.print("账号"+ID+",姓名"+name+",身份证"+IDCard+",地址"+site+",本次还书数"+L+",可借书数"+j);
}
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        @SuppressWarnings("resource")
        Scanner aa = new Scanner(System.in);
        LibraryCard t1 = new LibraryCard();
        LibraryCard t2 = new LibraryCard();
        System.out.print("请输入:账号、姓名、身份证、地址、本次借书数、本次还书数");
        t1.ID = aa.next();
        t1.name = aa.next();
        t1.IDCard = aa.next();
        t1.site = aa.next();
        t1.k = aa.nextInt();
        t1.L = aa.nextInt();
        t1.qw();
        t2.as();
    }

}

package 实训作业3;

import java.util.Scanner;

public class LibraryCard {
    String ID;
    String name;
    String IDCard;
    String site;
    int i,j = 10,k,L;//i:已借书数  j:可借书数   k:本次借书数  L:本次还书数

public void qw() {
    j = j-k;
    System.out.print("账号"+ID+",姓名"+name+",身份证"+IDCard+",地址"+site+",本次借书数"+k+",可借书数"+j+"\n");
}
public void as() {
    j = j+L;
    System.out.print("账号"+ID+",姓名"+name+",身份证"+IDCard+",地址"+site+",本次还书数"+L+",可借书数"+j);
}
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        @SuppressWarnings("resource")
        Scanner aa = new Scanner(System.in);
        LibraryCard t1 = new LibraryCard();
        LibraryCard t2 = new LibraryCard();
        System.out.print("请输入:账号、姓名、身份证、地址、本次借书数、本次还书数");
        t1.ID = aa.next();
        t1.name = aa.next();
        t1.IDCard = aa.next();
        t1.site = aa.next();
        t1.k = aa.nextInt();
        t1.L = aa.nextInt();
        t1.qw();
        t2.as();
    }

}

package 实训作业3;

import java.util.Scanner;

public class dianfe {
    int lastmonth;//上月电表读数
    int thismonth;//本月电表读数
    int i,n;
   
public void myprint() {
    System.out.print("输出上月电表读数:"+lastmonth+"\n输出本月电表读数:"+thismonth);
}
public void elec() {
    i = thismonth - lastmonth;
    System.out.print("\n本月用电数:"+i);
}
public void qwq() {
    n = i * 2;
    System.out.print("\n本月电费:"+n);
}

    public static void main(String[] args) {
        // TODO Auto-generated method stub @SuppressWarnings("resource")
        Scanner a = new Scanner(System.in);
        dianfe t = new dianfe();
        System.out.print("请输入上月电表读数:");
        t.lastmonth = a.nextInt();
        System.out.print("请输入本月电表读数:");
        t.thismonth = a.nextInt();
        t.myprint();
        t.elec();
        t.qwq();
    }

}

package 实训作业3;

import java.util.Scanner;

public class yunsuan {
    int x1,x2;
    int s;
   
public void jia() {
     s = x1 + x2;
     System.out.print("相加为:"+s);
}
public void jian() {
     s = x1 - x2;
     System.out.print("\n相减为:"+s);
}
public void cheng() {
     s = x1 * x2;
     System.out.print("\n相乘为:"+s);
}
public void chu() {
     s = x1 / x2;
     System.out.print("\n相除为:"+s);
}
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        @SuppressWarnings("resource")
        Scanner a = new Scanner(System.in);
        System.out.print("请输入两个数:");
        yunsuan t = new yunsuan();
        t.x1 = a.nextInt();
        t.x2 = a.nextInt();
        t.jia();
        t.jian();
        t.cheng();
        t.chu();
    }

}

 

posted @ 2019-05-05 17:45  虎牙搜索Darwin  阅读(118)  评论(0编辑  收藏  举报