Lab Report #5: More Practice with Conditionals and Loops, Study Guides, Projects, Research of Object Oriented Programming

Object-oriented programming (OOP) refers to a type of computer programming (software design) in which programmers define the data type of a data structure, and also the types of operations (functions) that can be applied to the data structure.

Typology: Study Guides, Projects, Research

2019/2020

Uploaded on 01/11/2020

samia-khan-2
samia-khan-2 🇵🇸

4.8

(4)

11 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
LAB REPORT: #5
SUBJECT: More practice writing methods
SUBMITTED BY: SAMIA
REG. NO: 17JZBCS0022
DEPARTMENT: CS&IT
TITLE: More practice with conditionals and loops
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Lab Report #5: More Practice with Conditionals and Loops and more Study Guides, Projects, Research Object Oriented Programming in PDF only on Docsity!

LAB REPORT:

  • SUBJECT: More practice writing methods

SUBMITTED BY: SAMIA

REG. NO: 17JZBCS

DEPARTMENT: CS&IT

  • TITLE: More practice with conditionals and loops

Exercise 1:

- In BlueJ, create a new project called Lab - Create a class in that project called MoreMethods - Write a method in that class called driver that takes no parameters and returns no value - In driver, print the following statement This method calls the others. Stay tuned. - Compile the code and run the method. SOLUTION: Figure 1

Exercise 2:

- Write a method called max that accepts two double parameters and returns the larger of the two.

Figure 3

Exercise 3:

- Write a method called sum that accepts one int parameter and returns the sum of the numbers from 1 to the parameter. - In the driver method, print the results of two calls to the sum method: The sum of 1 to 10 is xxx The sum of 1 to 100 is xxx SOLUTION: Figure 4

OUTPUT:

Figure 5

Exercise 4:

- Write a method called doubleIt that accepts one String parameter and returns a string that is the parameter concatenated with itself with "XXX" in between. - So calling doubleIt with "Java" will return "JavaXXXJava" - Calling doubleIt with "VT" will return "VTXXXVT" - In the driver method, print the results those two calls.

- Calling halfIt with "Hokies" will return "Hke" - To do this, the method should build the result string one character at a time (use a for loop). - In the driver method, print the results those two calls. SOLUTION: Figure 8 OUTPUT: Figure 9

Exercise 6:

- Write a method called doIt that accepts one String parameter and one int parameter, and returns a String - If the int parameter is greater than the number of characters in the String parameter, the method should return the result of calling doubleIt on the string. - Otherwise, it should return the result of calling halfIt on the string. - In the driver method, print the results of the following two calls: doIt("Voracious", 7) doIt("Efficacious", 20) SOLUTION: Figure 10 OUTPUT:

SOLUTION:

  • Figure 12 OUTPUT:

Figure 13 -