SlideShare ist ein Scribd-Unternehmen logo
1 von 1
It is an object oriented programming question.
3a) Using only conditionals and relational operators, write the method smallestPositive that takes
two numbers and returns the smallest positive one. If neither argument is positive,it returns 0 For
example, smallestPositive (7,4) and smallestPositive (4,7) both return 4, smallestPositive (7,-4)
and smallestPositive (-4,7) both return 7, and smallestPositive (-7,-4) returns 0 public int
smallestPositive (int x, int y) should return the smallest positive of x and y or 0 for two non-
positive arguments. (6 marks) 3b) Using only logical (Boolean) operators, write the method
mixture that takes three Booleans and returns true if and only if they contain at least one true,
and also at least one false. For example, mixture (true, false, false) and mixture (false, true, true)
both return true, but mixture (true,true,true) returns false. public boolean mixture (boolean x,
boolean y, boolean z) should return true iff x,y,z are a mixture of true and false. (4 marks)
Solution
public class Keypad { public static void main(String[] args) { Scanner input = new
Scanner(System.in); System.out.print("Enter a string: "); String s = input.nextLine();
System.out.println(getNumbers(s)); } public static String getNumbers(String s) { String result =
new String(); //Read and append s onto result for (int i = 0; i < s.length(); i++) { if
(Character.isLetter(s.charAt(i))) { result += getNumber(Character.toUpperCase(s.charAt(i))); }
else { result += s.charAt(i); } } return result; } public static int getNumber(char upperCaseLetter)
{ int number = ((upperCaseLetter - 'A') / 3) + 2; if (number < 7) { return number; } else if
(upperCaseLetter - 'A' < 20) { return 7; } else if (upperCaseLetter - 'A' < 23) { return 8; } else
{ return 9; } } }

Weitere ähnliche Inhalte

Ähnlich wie It is an object oriented programming question- 3a) Using only conditio.docx

ch04-conditional-execution.ppt
ch04-conditional-execution.pptch04-conditional-execution.ppt
ch04-conditional-execution.pptMahyuddin8
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxjovannyflex
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxjovannyflex
 
Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)Dharma Kshetri
 
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfLECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfShashikantSathe3
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdfICADCMLTPC
 
Java™ (OOP) - Chapter 5: "Methods"
Java™ (OOP) - Chapter 5: "Methods"Java™ (OOP) - Chapter 5: "Methods"
Java™ (OOP) - Chapter 5: "Methods"Gouda Mando
 
conditional statements
conditional statementsconditional statements
conditional statementsJames Brotsos
 
Use the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docxUse the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docxdickonsondorris
 
I need help with this two methods in java. Here are the guidelines. .pdf
I need help with this two methods in java. Here are the guidelines. .pdfI need help with this two methods in java. Here are the guidelines. .pdf
I need help with this two methods in java. Here are the guidelines. .pdfkourystephaniamari30
 
regular-expression.pdf
regular-expression.pdfregular-expression.pdf
regular-expression.pdfDarellMuchoko
 

Ähnlich wie It is an object oriented programming question- 3a) Using only conditio.docx (20)

ch04-conditional-execution.ppt
ch04-conditional-execution.pptch04-conditional-execution.ppt
ch04-conditional-execution.ppt
 
Jeop game-final-review
Jeop game-final-reviewJeop game-final-review
Jeop game-final-review
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
 
Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)
 
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfLECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
 
Data Handling
Data Handling Data Handling
Data Handling
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdf
 
Array
ArrayArray
Array
 
Computer programming 2 Lesson 10
Computer programming 2  Lesson 10Computer programming 2  Lesson 10
Computer programming 2 Lesson 10
 
Java™ (OOP) - Chapter 5: "Methods"
Java™ (OOP) - Chapter 5: "Methods"Java™ (OOP) - Chapter 5: "Methods"
Java™ (OOP) - Chapter 5: "Methods"
 
conditional statements
conditional statementsconditional statements
conditional statements
 
Use the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docxUse the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docx
 
Java generics
Java genericsJava generics
Java generics
 
I need help with this two methods in java. Here are the guidelines. .pdf
I need help with this two methods in java. Here are the guidelines. .pdfI need help with this two methods in java. Here are the guidelines. .pdf
I need help with this two methods in java. Here are the guidelines. .pdf
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
regular-expression.pdf
regular-expression.pdfregular-expression.pdf
regular-expression.pdf
 
130717666736980000
130717666736980000130717666736980000
130717666736980000
 
Chapter 2 Java Methods
Chapter 2 Java MethodsChapter 2 Java Methods
Chapter 2 Java Methods
 
Chapter 2 Method in Java OOP
Chapter 2   Method in Java OOPChapter 2   Method in Java OOP
Chapter 2 Method in Java OOP
 

Mehr von olsenlinnea427

Assume that X is a discrete random variable that can take on the follo.docx
Assume that X is a discrete random variable that can take on the follo.docxAssume that X is a discrete random variable that can take on the follo.docx
Assume that X is a discrete random variable that can take on the follo.docxolsenlinnea427
 
Assume that in an economy- people hold $1000 of currency and $4000 of.docx
Assume that in an economy- people hold $1000 of currency and $4000 of.docxAssume that in an economy- people hold $1000 of currency and $4000 of.docx
Assume that in an economy- people hold $1000 of currency and $4000 of.docxolsenlinnea427
 
Assume a Poisson distribution with -4-5- Find the following probabilit.docx
Assume a Poisson distribution with -4-5- Find the following probabilit.docxAssume a Poisson distribution with -4-5- Find the following probabilit.docx
Assume a Poisson distribution with -4-5- Find the following probabilit.docxolsenlinnea427
 
Assume a member is selected at random trom the population represented.docx
Assume a member is selected at random trom the population represented.docxAssume a member is selected at random trom the population represented.docx
Assume a member is selected at random trom the population represented.docxolsenlinnea427
 
Assume a list has the following element- write a function to interch.docx
Assume a list has the following element-   write a function to interch.docxAssume a list has the following element-   write a function to interch.docx
Assume a list has the following element- write a function to interch.docxolsenlinnea427
 
Assume a company had no jobs in progress at the beginning of July and.docx
Assume a company had no jobs in progress at the beginning of July and.docxAssume a company had no jobs in progress at the beginning of July and.docx
Assume a company had no jobs in progress at the beginning of July and.docxolsenlinnea427
 
Assignment- Peg Game Create a web page that allows the user to play th.docx
Assignment- Peg Game Create a web page that allows the user to play th.docxAssignment- Peg Game Create a web page that allows the user to play th.docx
Assignment- Peg Game Create a web page that allows the user to play th.docxolsenlinnea427
 
Assignment 2 Application Case 6-5 Efficient Image Recognition and Cate.docx
Assignment 2 Application Case 6-5 Efficient Image Recognition and Cate.docxAssignment 2 Application Case 6-5 Efficient Image Recognition and Cate.docx
Assignment 2 Application Case 6-5 Efficient Image Recognition and Cate.docxolsenlinnea427
 
As part of measures for containing the Covid-19 pandemic- vaccination.docx
As part of measures for containing the Covid-19 pandemic- vaccination.docxAs part of measures for containing the Covid-19 pandemic- vaccination.docx
As part of measures for containing the Covid-19 pandemic- vaccination.docxolsenlinnea427
 
As hematopoietic stem cells (HSC) mature and become differentiated the.docx
As hematopoietic stem cells (HSC) mature and become differentiated the.docxAs hematopoietic stem cells (HSC) mature and become differentiated the.docx
As hematopoietic stem cells (HSC) mature and become differentiated the.docxolsenlinnea427
 
As human populations & ecological footprints approach earth's carrying.docx
As human populations & ecological footprints approach earth's carrying.docxAs human populations & ecological footprints approach earth's carrying.docx
As human populations & ecological footprints approach earth's carrying.docxolsenlinnea427
 
Aries' description of an attitude toward death he called -tame death-.docx
Aries' description of an attitude toward death he called -tame death-.docxAries' description of an attitude toward death he called -tame death-.docx
Aries' description of an attitude toward death he called -tame death-.docxolsenlinnea427
 
Apple Inc- received $350-000 as dividends last year from its investmen.docx
Apple Inc- received $350-000 as dividends last year from its investmen.docxApple Inc- received $350-000 as dividends last year from its investmen.docx
Apple Inc- received $350-000 as dividends last year from its investmen.docxolsenlinnea427
 
Anthony has been living in Western WA for 3 years- After moving from C.docx
Anthony has been living in Western WA for 3 years- After moving from C.docxAnthony has been living in Western WA for 3 years- After moving from C.docx
Anthony has been living in Western WA for 3 years- After moving from C.docxolsenlinnea427
 
answer the questions in Blockchain list 5 point for all of the followi.docx
answer the questions in Blockchain list 5 point for all of the followi.docxanswer the questions in Blockchain list 5 point for all of the followi.docx
answer the questions in Blockchain list 5 point for all of the followi.docxolsenlinnea427
 
Answer the following questions- Question 1- You have implemented a sec.docx
Answer the following questions- Question 1- You have implemented a sec.docxAnswer the following questions- Question 1- You have implemented a sec.docx
Answer the following questions- Question 1- You have implemented a sec.docxolsenlinnea427
 
Answer the following based on a Blockchain and Biometrics I- What t.docx
Answer the following based on a Blockchain and Biometrics    I- What t.docxAnswer the following based on a Blockchain and Biometrics    I- What t.docx
Answer the following based on a Blockchain and Biometrics I- What t.docxolsenlinnea427
 
Anglin Company- a manufacturing firred has supplicd the following info.docx
Anglin Company- a manufacturing firred has supplicd the following info.docxAnglin Company- a manufacturing firred has supplicd the following info.docx
Anglin Company- a manufacturing firred has supplicd the following info.docxolsenlinnea427
 
Angela Lopez owns and manages a consulting firm called Metrixi which b.docx
Angela Lopez owns and manages a consulting firm called Metrixi which b.docxAngela Lopez owns and manages a consulting firm called Metrixi which b.docx
Angela Lopez owns and manages a consulting firm called Metrixi which b.docxolsenlinnea427
 
Andrew finds that on his way to work his wait time for the bus is roug.docx
Andrew finds that on his way to work his wait time for the bus is roug.docxAndrew finds that on his way to work his wait time for the bus is roug.docx
Andrew finds that on his way to work his wait time for the bus is roug.docxolsenlinnea427
 

Mehr von olsenlinnea427 (20)

Assume that X is a discrete random variable that can take on the follo.docx
Assume that X is a discrete random variable that can take on the follo.docxAssume that X is a discrete random variable that can take on the follo.docx
Assume that X is a discrete random variable that can take on the follo.docx
 
Assume that in an economy- people hold $1000 of currency and $4000 of.docx
Assume that in an economy- people hold $1000 of currency and $4000 of.docxAssume that in an economy- people hold $1000 of currency and $4000 of.docx
Assume that in an economy- people hold $1000 of currency and $4000 of.docx
 
Assume a Poisson distribution with -4-5- Find the following probabilit.docx
Assume a Poisson distribution with -4-5- Find the following probabilit.docxAssume a Poisson distribution with -4-5- Find the following probabilit.docx
Assume a Poisson distribution with -4-5- Find the following probabilit.docx
 
Assume a member is selected at random trom the population represented.docx
Assume a member is selected at random trom the population represented.docxAssume a member is selected at random trom the population represented.docx
Assume a member is selected at random trom the population represented.docx
 
Assume a list has the following element- write a function to interch.docx
Assume a list has the following element-   write a function to interch.docxAssume a list has the following element-   write a function to interch.docx
Assume a list has the following element- write a function to interch.docx
 
Assume a company had no jobs in progress at the beginning of July and.docx
Assume a company had no jobs in progress at the beginning of July and.docxAssume a company had no jobs in progress at the beginning of July and.docx
Assume a company had no jobs in progress at the beginning of July and.docx
 
Assignment- Peg Game Create a web page that allows the user to play th.docx
Assignment- Peg Game Create a web page that allows the user to play th.docxAssignment- Peg Game Create a web page that allows the user to play th.docx
Assignment- Peg Game Create a web page that allows the user to play th.docx
 
Assignment 2 Application Case 6-5 Efficient Image Recognition and Cate.docx
Assignment 2 Application Case 6-5 Efficient Image Recognition and Cate.docxAssignment 2 Application Case 6-5 Efficient Image Recognition and Cate.docx
Assignment 2 Application Case 6-5 Efficient Image Recognition and Cate.docx
 
As part of measures for containing the Covid-19 pandemic- vaccination.docx
As part of measures for containing the Covid-19 pandemic- vaccination.docxAs part of measures for containing the Covid-19 pandemic- vaccination.docx
As part of measures for containing the Covid-19 pandemic- vaccination.docx
 
As hematopoietic stem cells (HSC) mature and become differentiated the.docx
As hematopoietic stem cells (HSC) mature and become differentiated the.docxAs hematopoietic stem cells (HSC) mature and become differentiated the.docx
As hematopoietic stem cells (HSC) mature and become differentiated the.docx
 
As human populations & ecological footprints approach earth's carrying.docx
As human populations & ecological footprints approach earth's carrying.docxAs human populations & ecological footprints approach earth's carrying.docx
As human populations & ecological footprints approach earth's carrying.docx
 
Aries' description of an attitude toward death he called -tame death-.docx
Aries' description of an attitude toward death he called -tame death-.docxAries' description of an attitude toward death he called -tame death-.docx
Aries' description of an attitude toward death he called -tame death-.docx
 
Apple Inc- received $350-000 as dividends last year from its investmen.docx
Apple Inc- received $350-000 as dividends last year from its investmen.docxApple Inc- received $350-000 as dividends last year from its investmen.docx
Apple Inc- received $350-000 as dividends last year from its investmen.docx
 
Anthony has been living in Western WA for 3 years- After moving from C.docx
Anthony has been living in Western WA for 3 years- After moving from C.docxAnthony has been living in Western WA for 3 years- After moving from C.docx
Anthony has been living in Western WA for 3 years- After moving from C.docx
 
answer the questions in Blockchain list 5 point for all of the followi.docx
answer the questions in Blockchain list 5 point for all of the followi.docxanswer the questions in Blockchain list 5 point for all of the followi.docx
answer the questions in Blockchain list 5 point for all of the followi.docx
 
Answer the following questions- Question 1- You have implemented a sec.docx
Answer the following questions- Question 1- You have implemented a sec.docxAnswer the following questions- Question 1- You have implemented a sec.docx
Answer the following questions- Question 1- You have implemented a sec.docx
 
Answer the following based on a Blockchain and Biometrics I- What t.docx
Answer the following based on a Blockchain and Biometrics    I- What t.docxAnswer the following based on a Blockchain and Biometrics    I- What t.docx
Answer the following based on a Blockchain and Biometrics I- What t.docx
 
Anglin Company- a manufacturing firred has supplicd the following info.docx
Anglin Company- a manufacturing firred has supplicd the following info.docxAnglin Company- a manufacturing firred has supplicd the following info.docx
Anglin Company- a manufacturing firred has supplicd the following info.docx
 
Angela Lopez owns and manages a consulting firm called Metrixi which b.docx
Angela Lopez owns and manages a consulting firm called Metrixi which b.docxAngela Lopez owns and manages a consulting firm called Metrixi which b.docx
Angela Lopez owns and manages a consulting firm called Metrixi which b.docx
 
Andrew finds that on his way to work his wait time for the bus is roug.docx
Andrew finds that on his way to work his wait time for the bus is roug.docxAndrew finds that on his way to work his wait time for the bus is roug.docx
Andrew finds that on his way to work his wait time for the bus is roug.docx
 

Kürzlich hochgeladen

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 

Kürzlich hochgeladen (20)

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 

It is an object oriented programming question- 3a) Using only conditio.docx

  • 1. It is an object oriented programming question. 3a) Using only conditionals and relational operators, write the method smallestPositive that takes two numbers and returns the smallest positive one. If neither argument is positive,it returns 0 For example, smallestPositive (7,4) and smallestPositive (4,7) both return 4, smallestPositive (7,-4) and smallestPositive (-4,7) both return 7, and smallestPositive (-7,-4) returns 0 public int smallestPositive (int x, int y) should return the smallest positive of x and y or 0 for two non- positive arguments. (6 marks) 3b) Using only logical (Boolean) operators, write the method mixture that takes three Booleans and returns true if and only if they contain at least one true, and also at least one false. For example, mixture (true, false, false) and mixture (false, true, true) both return true, but mixture (true,true,true) returns false. public boolean mixture (boolean x, boolean y, boolean z) should return true iff x,y,z are a mixture of true and false. (4 marks) Solution public class Keypad { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a string: "); String s = input.nextLine(); System.out.println(getNumbers(s)); } public static String getNumbers(String s) { String result = new String(); //Read and append s onto result for (int i = 0; i < s.length(); i++) { if (Character.isLetter(s.charAt(i))) { result += getNumber(Character.toUpperCase(s.charAt(i))); } else { result += s.charAt(i); } } return result; } public static int getNumber(char upperCaseLetter) { int number = ((upperCaseLetter - 'A') / 3) + 2; if (number < 7) { return number; } else if (upperCaseLetter - 'A' < 20) { return 7; } else if (upperCaseLetter - 'A' < 23) { return 8; } else { return 9; } } }