Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.87 KB | None | 0 0
  1. // Roman Kungurov
  2. // Exercise 1
  3. public class Runner {
  4. String name;
  5. double[] results;
  6.  
  7. public Runner(String name, double[] results) {
  8.     this.name = name;
  9.     this.results = results;
  10. }
  11.  
  12. public double averageRun() {
  13.     double avg=0;
  14.     for(int i=0; i<results.length; i++) {
  15.         avg += results[i];
  16.     }
  17.     return avg/results.length;
  18. }
  19.  
  20. public int goodScores(Runner runner) {
  21.     int count=0;
  22.     double avg = this.averageRun();
  23.     for(int i=0; i<runner.getResults().length; i++) {
  24.         if(runner.getResults()[i] > avg)
  25.             count++;
  26.     }
  27.     return count;
  28. }
  29.  
  30.  
  31. public String getName() {
  32.     return name;
  33. }
  34.  
  35. public void setName(String name) {
  36.     this.name = name;
  37. }
  38.  
  39. public double[] getResults() {
  40.     return results;
  41. }
  42.  
  43. public void setResults(double[] results) {
  44.     this.results = results;
  45. }
  46.  
  47. }
  48.  
  49. // Exercise 2
  50. import java.util.Scanner;
  51.  
  52. public class Party {
  53.  
  54.     static int[] boys = new int[200];
  55.     static Scanner in = new Scanner(System.in);
  56.    
  57.     public static void main(String[] args) {
  58.         Scanner in = new Scanner(System.in);
  59.         voting();
  60.         System.out.println("The party's king is the boy number" + kingOfParty());
  61.         System.out.println(wanted() + " boys were wanted");
  62.         System.out.println(notVoted() + " boys hadn't been voted at all");
  63.     }
  64.    
  65.     public static int[] voting() {
  66.        
  67.         for (int i = 0; i < 180; i ++) {        
  68.             for(int v = 1; v <= 10; v++) {  
  69.                 System.out.println("Enter boy's number " + v);
  70.                 int boyNumber = in.nextInt();
  71.                 boys[boyNumber] += (11-v);
  72.             }
  73.             System.out.println("Now is next girl's turn");
  74.         }
  75.         return boys;
  76.     }
  77.     public static int kingOfParty() {
  78.         int max = boys[0];
  79.         int k=0;
  80.         for(int i=0; i<boys.length; i++) {
  81.             if(max < boys[i]) {
  82.                 boys[i] = max;
  83.                 k = i;
  84.             }  
  85.         }
  86.         return k;
  87.     }
  88.     public static int wanted() {
  89.         int avg=0, count=0;
  90.         for(int i=0; i<boys.length; i++) {
  91.             avg += boys[i];
  92.         }
  93.         avg /= boys.length;
  94.         for(int i=0; i<boys.length; i++) {
  95.             if(boys[i] > avg)
  96.                 count++;
  97.         }
  98.         return count;
  99.     }
  100.     public static int notVoted() {
  101.         int count=0;
  102.         for(int i=0; i<boys.length; i++) {
  103.             if(boys[i] == 0)
  104.                 count++;
  105.         }
  106.         return count;
  107.     }
  108.  
  109. }
  110.  
  111. // Exercise 3
  112. import java.util.Scanner;
  113.  
  114. public class Arr {
  115.  
  116.     public static void main(String[] args) {
  117.         Scanner in = new Scanner(System.in);
  118.         System.out.println("Please enter the array's length");
  119.         int n = in.nextInt();
  120.         int[] nums = new int[n];
  121.         for(int i = 0; i < nums.length; i++) {
  122.             System.out.println("Please enter the number");
  123.             nums[i] = in.nextInt();
  124.         }
  125.         int max =0;
  126.         for(int i = 2; i <= nums.length/2; i++) {
  127.             if(lineChecking(nums,i) == 1) {
  128.                 max = i;
  129.             }
  130.         }
  131.         if(max == 0)
  132.             System.out.println("The array is not organized at all");
  133.         else
  134.             System.out.println("The array is organized in " + max + " level");
  135.        
  136.     }
  137.    
  138.     public static int arr(int[] arr, int i, int j) {
  139.         for(i=i; i<j; i++) {
  140.             if(!(arr[i] == arr[j]))
  141.                 return 0;
  142.         }
  143.         return 1;
  144.     }
  145.    
  146.     public static int lineChecking(int[] arr, int m) {
  147.         int n = arr.length;
  148.         int j = n/m - 1;
  149.         int i = 0, count = 0;
  150.         for(int t=0; t<n/m; t++) {
  151.             count += arr(arr, i, j);
  152.             j += n/m;
  153.             i += n/m;
  154.         }
  155.         if(count == n/m)
  156.                 return 1;
  157.         return 0;
  158.     }
  159.        
  160.  
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement