Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab2;
- import java.util.Scanner;
- import java.util.Date;
- import java.util.LinkedList;
- import java.text.SimpleDateFormat;
- import java.text.DateFormat;
- import java.time.LocalDate;
- import java.text.ParseException;
- interface MainInterface {
- public void input();
- public void output();
- public void method();
- }
- class Dyscyplina implements MainInterface {
- private String name;
- private int lectHours;
- private int labHours;
- private int selfHours;
- public void input() {
- Scanner in = new Scanner(System.in);
- System.out.println("Input name: ");
- name = in.nextLine();
- System.out.println("Input lect hours: ");
- lectHours = in.nextInt();
- System.out.println("Input lab hours: ");
- labHours = in.nextInt();
- System.out.println("Input self hours: ");
- selfHours = in.nextInt();
- }
- public void output() {
- System.out.printf("Name: %s\nLect hours: %s\nLab hours: %s\n Self hours: %s\n", name, lectHours, labHours,selfHours);
- }
- public void method() {
- System.out.printf("Total hours: %s\n", Integer.toString(lectHours + labHours + selfHours));
- }
- @Override
- public String toString() {
- return String.format("Name: %s\nLect hours: %s\nLab hours: %s\n Self hours: %s\n", name, lectHours, labHours,selfHours);
- }
- @Override
- public int hashCode() {
- return lectHours * lectHours;
- }
- }
- class Salary implements MainInterface {
- private String fio;
- private int hours;
- private int payment;
- public void input() {
- Scanner in = new Scanner(System.in);
- System.out.println("Input fio: ");
- fio = in.nextLine();
- System.out.println("Input hours of work: ");
- hours = in.nextInt();
- System.out.println("Input payment for hour: ");
- payment = in.nextInt();
- }
- public void output() {
- System.out.printf("Name: %s\nHours of work: %s\nPayment: %s\n", fio, hours, payment);
- }
- public void method() {
- System.out.printf("Total payout: %s\n", Integer.toString(hours * payment));
- }
- @Override
- public String toString() {
- return String.format("Name: %s\nHours of work: %s\nPayment: %s\n", fio, hours, payment);
- }
- @Override
- public int hashCode() {
- return payment * payment;
- }
- }
- class Providers implements MainInterface {
- private String name;
- private int speed;
- private int price;
- public void input() {
- Scanner in = new Scanner(System.in);
- System.out.println("Input name: ");
- name = in.nextLine();
- System.out.println("Input speed: ");
- speed = in.nextInt();
- System.out.println("Input price: ");
- price = in.nextInt();
- }
- public void output() {
- System.out.printf("Name: %s\nSpeed: %s\nPrice: %s\n", name, speed, price);
- }
- public void method() {
- System.out.printf("Price/Speed: %s\n", price / speed);
- }
- @Override
- public String toString() {
- return String.format("Name: %s\nSpeed: %s\nPrice: %s\n", name, speed, price);
- }
- @Override
- public int hashCode() {
- return speed * speed;
- }
- }
- public class lab11 {
- public static void main(String[] args) throws Exception {
- Dyscyplina dysc = new Dyscyplina();
- Salary salary = new Salary();
- Providers providers = new Providers();
- dysc.input();
- salary.input();
- providers.input();
- Long long_obj = 1234L;
- Short short_obj = 123;
- Boolean boolean_obj = true;
- LinkedList<Object> linkList = new LinkedList<Object>();
- linkList.add(long_obj);
- linkList.add(short_obj);
- linkList.add(boolean_obj);
- linkList.add(dysc);
- linkList.add(salary);
- linkList.add(providers);
- for (Object e : linkList) {
- System.out.println( "\n" + e.toString() );
- System.out.println( "Hash code: " + e.hashCode() );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement