0% found this document useful (0 votes)
28 views7 pages

Oop Assignment #2: Submitted By: Adnan Haider Reg No. Sp20-Bse-037

This document contains 15 logic puzzles or problems with proposed solutions in Java code. Each logic puzzle is presented with a title and the Java code to solve it in 1-3 lines of code. The document was submitted by a student for an OOP assignment and contains solutions to logic puzzles involving conditions like weekends, speed limits, numbers divisible by other numbers, sums, differences and more.

Uploaded by

Adnan Aadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views7 pages

Oop Assignment #2: Submitted By: Adnan Haider Reg No. Sp20-Bse-037

This document contains 15 logic puzzles or problems with proposed solutions in Java code. Each logic puzzle is presented with a title and the Java code to solve it in 1-3 lines of code. The document was submitted by a student for an OOP assignment and contains solutions to logic puzzles involving conditions like weekends, speed limits, numbers divisible by other numbers, sums, differences and more.

Uploaded by

Adnan Aadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

OOP ASSIGNMENT #2

SUBMITTED BY: ADNAN HAIDER


Reg NO. SP20-BSE-037
Logic :1 Cigar Party:
public boolean cigarParty(int cigars, boolean isWeekend) {
2   if (isWeekend == true && cigars >= 40)

3     return true;
4   if (!(isWeekend) && cigars >=40 && cigars <= 60)
5     return true;
6   else
7     return false;
8}

Logic 2: Caught Speeding:


01 public int caughtSpeeding(int speed, boolean isBirthday) {
02   if (!(isBirthday)) {
03     if (speed <= 60)
04       return 0;
05     if (speed > 60 && speed <= 80)
06       return 1;

07     else
08       return 2;
09   } else if (speed <=65)
10       return 0;
11     else if (speed > 65 && speed <= 85)
12       return 1;

13     else
14       return 2;
15 }

Logic 3: Love6
01 public boolean love6(int a, int b) {
02   if (a == 6 || b == 6)
03     return true;
04      

05   int sum = a+b;
06   int diff = Math.abs(a-b);
07    
08   if (sum == 6 || diff == 6)
09     return true;
10   else
11     return false;
12 }

Logic 4: morethan20
1 public boolean more20(int n) {
2   return (n % 20) == 1 || (n % 20) == 2;
3}

Logic 5: near10
1 public boolean nearTen(int num) {
2   if (num % 10 < 3 || num % 10 >=8)
3     return true;
4   else return false;
5}

Logic 6: Teaparty
1 public int teaParty(int tea, int candy) {
2   if (tea < 5 || candy < 5)

3     return 0;
4   if ((tea >= 2 * candy) || (candy >= 2 * tea))
5     return 2;
6   else
7     return 1;
8}

Logic 7: TwoAsone
1 public boolean twoAsOne(int a, int b, int c) {
2   if ( a + b == c || c + b == a || c + a == b)
3     return true;
4   else
5     return false;
6 }

Logic 8: LastDigit
01 public boolean lastDigit(int a, int b, int c) {
02   int modA = a % 10;
03   int modB = b % 10;
04   int modC = c % 10;
05    
06   if (modA == modB || modA == modC || modB == modC)
07     return true;
08   else
09     return false;
10 }

Logic 9: maxMod5
1 public int maxMod5(int a, int b) {
2   if (a == b)
3     return 0;
4      

5   if (a % 5 == b % 5)


6     return Math.min(a,b);
7    
8   return Math.max(a,b);
9}

Logic 10: BlueTicket


public int blueTicket(int a, int b, int c) {
if (a + b == 10 || b + c == 10 || c + a == 10){
return 10;
}
if(a == c + 10 || b == c + 10){
return 5;
}
return 0;
}

Logic 11: dateFashion


public int dateFashion(int you, int date) {
if((you >= 8 || date >= 8) && !(you <= 2 || date <= 2)) {
return 2;
}
else if (you <= 2 || date <= 2) {
return 0;
}
else {
return 1;
}

}
Logic 12: TeenSum
1 public int teenSum(int a, int b) {
2   int sum = a+b;
3   if ((a >= 13 && a <= 19) || (b >= 13 && b <= 19))
4     return 19;

5   else
6     return sum;
7}

Logic 13: redTicket


public int redTicket(int a, int b, int c) {
if(a==b&&b==c)
{
if(a==2) return 10;
else return 5;
}
else if(b!=a&&c!=a) return 1;
else return 0;
}

Logic 14: shareDigit


01 public boolean shareDigit(int a, int b) {
02   int aL = a / 10;
03   int aR = a % 10;
04   int bL = b / 10;
05   int bR = b % 10;
06    
07   if (aL == bL || aL == bR || aR == bL || aR == bR)
08     return true;

09   else
10     return false;
11 }
Logic 15: sumLimit
public int sumLimit(int a, int b) {

if( String.valueOf(a).length() == String.valueOf(a+b).length()){


return a+b;
} else {
return a;
}
}

You might also like