Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. public class MyClass {
  2. public static void main(String args[]) {
  3.  
  4. int seatPrices[][] = { {-1,42,13,17,23},
  5. {11,13,-1,10,10},
  6. {14,12,15,-1,-1},
  7. {16,17,10,11,19},
  8. {-1,-1,-1,-1,-1},
  9. {-1,14,17,-1,14},
  10. };
  11.  
  12. int seatCombo = 0;
  13. int totalPrice = -1;
  14. int requiredSeats = 3;
  15. int rowNumber = 0;
  16. int lowestComboPrice = -1;
  17. int comboCount = 0;
  18. int firstPrice = 0;
  19.  
  20. //iterate over entire plane
  21. for(int i=0; i<seatPrices.length; i++) {
  22.  
  23. //reset for new row
  24. System.out.println("total Price reset for new row ");
  25. seatCombo = 0;
  26. totalPrice = 0;
  27.  
  28. // Iterate over row
  29. for(int j=0; j<seatPrices[i].length; j++) {
  30.  
  31. rowNumber = i;
  32.  
  33.  
  34. System.out.println("seat location = [" + i + "][" + j + "]");
  35.  
  36. //iterate over each seat
  37. if(seatPrices[i][j] != -1) {
  38. System.out.println("added seat at [" + i + "][" + j + "]");
  39. seatCombo ++;
  40. totalPrice += seatPrices[i][j];
  41.  
  42. if(seatCombo == 1) {
  43. firstPrice = seatPrices[i][j];
  44. }
  45. if(seatCombo == requiredSeats) {
  46. System.out.println("Combo limit hit at = [" + i + "][" + j + "]");
  47. System.out.println("total Price = " + totalPrice);
  48.  
  49. if (comboCount == 0) {
  50. lowestComboPrice = totalPrice;
  51. comboCount++;
  52. } else {
  53. if(totalPrice < lowestComboPrice) {
  54. lowestComboPrice = totalPrice;
  55. }
  56. }
  57.  
  58. seatCombo --;
  59. totalPrice -= firstPrice;
  60. System.out.println("Price decremented due to completion, totalPrice = " + totalPrice);
  61. }
  62. } else {
  63.  
  64. seatCombo = 0;
  65. totalPrice = 0;
  66. System.out.println("combo borked, total price = " + totalPrice);
  67. }
  68. //System.out.println("Seat price at arr["+i+"]["+j+"] is "+seatPrices[i][j]);
  69. }
  70.  
  71.  
  72. }
  73. System.out.println("lowest total Price = " + lowestComboPrice);
  74.  
  75.  
  76. return ;
  77. }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement