Advertisement
Guest User

Student Journal - Java Console

a guest
Sep 26th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.75 KB | None | 0 0
  1. package javaapplication1;
  2. import java.util.Scanner;
  3.  
  4. class Students {
  5.     private String name;
  6.     private double missed, justified;
  7.     private double totalMissed,totalJustified,totalHours;
  8.  
  9.     public Students(String name, int missed, int justified) {
  10.  
  11.         this.name = name;
  12.         this.missed = missed;
  13.         this.justified = justified;
  14.  
  15.     }
  16.     public Students(){};
  17.  
  18.     public String getName() {return name;}
  19.     public double getMissed() {return missed;}
  20.     public double getJustified() {return justified;}
  21.     public double getTotalMissed() {return totalMissed;}
  22.     public double getTotalJustified() {return totalJustified;}
  23.     public double getTotalHours() {return totalHours;}
  24.  
  25.     public double Percent(double missedHours) {
  26.         return missedHours*100/getMissed();
  27.     }
  28.  
  29.     public double MissedInHours() {
  30.         return missed-justified;
  31.     }
  32.  
  33.     public void setTotalMissed(double totalMissed) {
  34.         this.totalMissed += totalMissed;
  35.     }
  36.     public void setTotalJustified(double totalJustified) {
  37.         this.totalJustified += totalJustified;
  38.     }
  39.     public void setTotalHours(double totalHours) {
  40.         this.totalHours += totalHours;
  41.     }
  42. }
  43.  
  44. public class Main {
  45.     public static void main(String[] args) {
  46.         String name;
  47.         int missed, hours, lenght, count = 1;
  48.         Scanner countStudent = new Scanner(System.in);
  49.         System.out.print("Введите количество Студентов: ");
  50.         lenght = countStudent.nextInt();
  51.         Students total = new Students();
  52.         Students[] Students = new Students[lenght];
  53.         for (int i = 0; i < lenght; i++) {
  54.             Scanner check = new Scanner(System.in);
  55.             System.out.print("Введите Фамилию " + count + "-го студента: ");
  56.             name = check.nextLine();
  57.             System.out.print("Пропущено всего часов у " + count + " студента: ");
  58.             missed = check.nextInt();
  59.             System.out.print("Оправдано часов у " + count + " студента: ");
  60.             hours = check.nextInt();
  61.             Students[i] = new Students(name, missed, hours);
  62.             count++;
  63.         }
  64.         System.out.println("╔═══════════════════════════════════════════════════════════════════════════════════════════════════════════════╗");
  65.         System.out.println("║             |                  Пропущено, часов                |             Пропуск              ");
  66.         System.out.println("║   Фамилия   |__________________________________________________|_________________________________| ");
  67.         System.out.println("║             |         ВСЕГО            |      ОПРАВДАНО        |   В ЧАСАХ      |   В ПРОЦЕНТАХ   ");
  68.         System.out.println("╠═══════════════════════════════════════════════════════════════════════════════════════════════════════════════╣");
  69.         for (int i = 0; i < lenght; i++) {
  70.             System.out.format("║ %-11s | %-25s| %-21s | %-13s  | %.2f %n" ,Students[i].getName() , Students[i].getMissed(),Students[i].getJustified(), Students[i].MissedInHours() ,Students[i].Percent(Students[i].MissedInHours()));
  71.             System.out.format("╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════════╝%n");
  72.             total.setTotalMissed(Students[i].getMissed());
  73.             total.setTotalJustified(Students[i].getJustified());
  74.             total.setTotalHours(Students[i].MissedInHours());
  75.         }
  76.         System.out.format("║ %-11s | %-25s| %-21s | %-13s  | %n" ,"ИТОГО:",total.getTotalMissed(), total.getTotalJustified(),total.getTotalHours());
  77.         System.out.format("╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════════╝%n");
  78.  
  79.     }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement