Advertisement
FlyChsCake

Jaba 10

Nov 22nd, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.05 KB | None | 0 0
  1. package lab2;
  2.  
  3. import java.util.Scanner;
  4. import java.util.Date;
  5. import java.util.LinkedList;
  6. import java.text.SimpleDateFormat;
  7. import java.text.DateFormat;
  8. import java.time.LocalDate;
  9. import java.text.ParseException;
  10.  
  11. interface MainInterface {
  12.     public void input();
  13.     public void output();
  14.     public void method();
  15. }
  16.  
  17. class Dyscyplina implements MainInterface {
  18.     private String name;
  19.     private int lectHours;
  20.     private int labHours;
  21.     private int selfHours;
  22.    
  23.     public void input() {
  24.         Scanner in = new Scanner(System.in);
  25.         System.out.println("Input name: ");
  26.         name = in.nextLine();
  27.         System.out.println("Input lect hours: ");
  28.         lectHours = in.nextInt();
  29.         System.out.println("Input lab hours: ");
  30.         labHours = in.nextInt();
  31.         System.out.println("Input self hours: ");
  32.         selfHours = in.nextInt();
  33.     }
  34.    
  35.     public void output() {
  36.         System.out.printf("Name: %s\nLect hours: %s\nLab hours: %s\n Self hours: %s\n", name, lectHours, labHours,selfHours);
  37.     }
  38.    
  39.     public void method() {
  40.         System.out.printf("Total hours: %s\n", Integer.toString(lectHours + labHours + selfHours));
  41.     }
  42.    
  43.     @Override
  44.     public String toString() {
  45.         return String.format("Name: %s\nLect hours: %s\nLab hours: %s\n Self hours: %s\n", name, lectHours, labHours,selfHours);
  46.     }
  47.    
  48.     @Override
  49.     public int hashCode() {
  50.         return lectHours * lectHours;
  51.        
  52.     }
  53.    
  54. }
  55.  
  56. class Salary implements MainInterface {
  57.     private String fio;
  58.     private int hours;
  59.     private int payment;
  60.    
  61.     public void input() {
  62.         Scanner in = new Scanner(System.in);
  63.         System.out.println("Input fio: ");
  64.         fio = in.nextLine();
  65.         System.out.println("Input hours of work: ");
  66.         hours = in.nextInt();
  67.         System.out.println("Input payment for hour: ");
  68.         payment = in.nextInt();
  69.     }
  70.    
  71.     public void output() {
  72.         System.out.printf("Name: %s\nHours of work: %s\nPayment: %s\n", fio, hours, payment);
  73.     }
  74.    
  75.     public void method() {
  76.         System.out.printf("Total payout: %s\n", Integer.toString(hours * payment));
  77.     }
  78.    
  79.     @Override
  80.     public String toString() {
  81.         return String.format("Name: %s\nHours of work: %s\nPayment: %s\n", fio, hours, payment);
  82.     }
  83.    
  84.     @Override
  85.     public int hashCode() {
  86.         return payment * payment;
  87.        
  88.     }
  89.    
  90. }
  91.  
  92. class Providers implements MainInterface {
  93.     private String name;
  94.     private int speed;
  95.     private int price;
  96.    
  97.     public void input() {
  98.         Scanner in = new Scanner(System.in);
  99.         System.out.println("Input name: ");
  100.         name = in.nextLine();
  101.         System.out.println("Input speed: ");
  102.         speed = in.nextInt();
  103.         System.out.println("Input price: ");
  104.         price = in.nextInt();
  105.     }
  106.    
  107.     public void output() {
  108.         System.out.printf("Name: %s\nSpeed: %s\nPrice: %s\n", name, speed, price);
  109.     }
  110.    
  111.     public void method() {
  112.         System.out.printf("Price/Speed: %s\n", price / speed);
  113.     }
  114.    
  115.     @Override
  116.     public String toString() {
  117.         return String.format("Name: %s\nSpeed: %s\nPrice: %s\n", name, speed, price);
  118.     }
  119.    
  120.     @Override
  121.     public int hashCode() {
  122.         return speed * speed;
  123.        
  124.     }
  125.    
  126. }
  127.  
  128.  
  129. public class lab11 {
  130.   public static void main(String[] args) throws Exception {
  131.  
  132.     Dyscyplina dysc = new Dyscyplina();
  133.     Salary salary = new Salary();
  134.     Providers providers = new Providers();
  135.     dysc.input();
  136.     salary.input();
  137.     providers.input();
  138.          
  139.     Long long_obj = 1234L;
  140.     Short short_obj = 123;
  141.     Boolean boolean_obj = true;
  142.    
  143.     LinkedList<Object> linkList = new LinkedList<Object>();
  144.     linkList.add(long_obj);
  145.     linkList.add(short_obj);
  146.     linkList.add(boolean_obj);
  147.     linkList.add(dysc);
  148.     linkList.add(salary);
  149.     linkList.add(providers);
  150.  
  151.     for (Object e : linkList) {
  152.       System.out.println( "\n" + e.toString() );
  153.       System.out.println( "Hash code: " + e.hashCode() );
  154.     }
  155.   }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement