Skip to content

cameronto2009/CS.11.02-Lab.2.1

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CS.11.02-Lab.2.1

Your task is to implement all of the eight methods described below in a class called Main. For each method that you implement, you will call your method inside the main method and store it in an appropriately named variable. You will then print out this varible's contents to the console. You should pass all of the tests in the MainTest class (provided).

Note that unlike Lab 1, in Lab 2 you are provided with a class called MainTest. This class is not to be edited. That is, you will not write or edit any code inside the MainTest class. You may, however, wish to comment out certain test cases that you are not currently testing.

When we wish to output a value to the console, we use the statement:

System.out.print(insertValueThatYouWishToPrintHere) to print on the same line. System.out.println(insertValueThatYouWishToPrintHere) to print on different lines.

In intelliJ, a neat shortcut for the print statement is to type “sout” and press enter. In intelliJ, a neat shortcut to create a main method is to type “main” and press enter.

Ensure that your parameter names are meaningful variable names.

Ensure that all the methods that you write in this lab are declared to be static.

Ensure that all the methods that you write in this lab contain a return statement. That is, none of the methods that you write in this lab will contain print statements.

  1. Write a method called add that takes two integers, adds them together, and returns the result. Below is an example of a call to the add method.

add(3,8) → 11

Call your add method in the main method and see that it works as intended. When you call it, store it into an appropriately named variable and then print out that variable.

  1. Write a method called add that takes four integers, adds them together, and returns the result. Make sure to call the add method that takes two integers (the add method that you wrote in 1.) thrice inside this method. Below is an example of a call to the add method.

add(3,8,4,9) → 24

Call your add method in the main method and see that it works as intended. When you call it, store it into an appropriately named variable and then print out that variable.

  1. Write a method called morningGreeting. Below is an example of a call to the morningGreeting method.

morningGreeting(“Toby Fox”) → 早上好, Toby Fox!

Call your morningGreeting method in the main method and see that it works as intended. When you call it, store it into an appropriately named variable and then print out that variable.

  1. Write a method called afternoonGreeting Below is an example of a call to the morningGreeting method.

afternoonGreeting(“Mac Miller”) → 下午好, Mac Miller!

Call your afternoonGreeting method in the main method and see that it works as intended. When you call it, store it into an appropriately named variable and then print out that variable.

  1. Write a method called triple Below is an example of a call to the triple method.

triple(“oohbaby”) → oohbabyoohbabyoohbaby

Call your triple method in the main method and see that it works as intended. When you call it, store it into an appropriately named variable and then print out that variable.

  1. Write a method called half that takes an integer and returns half of its value.
    Below is an example of a call to the half method.

half(8) → 4.0

half(17) → 8.5

Call your half method in the main method and see that it works as intended. When you call it, store it into an appropriately named variable and then print out that variable.

  1. Write a method called roundPositiveValueToNearestInteger that takes a double that is positive and rounds this value to the nearest integer. Below is an example of a call to the roundPositiveValueToNearestInteger method.

roundPositiveValueToNearestInteger(8.5) → 9

roundPositiveValueToNearestInteger(8.49) → 8

Call your roundPositiveValueToNearestInteger method in the main method and see that it works as intended. When you call it, store it into an appropriately named variable and then print out that variable. Use casting in your solution to achieve the desired output.

  1. Write a method called roundNegativeValueToNearestInteger that takes a double that is negative and rounds this value to the nearest integer. Below is an example of a call to the roundNegativeValueToNearestInteger method.

roundNegativeValueToNearestInteger(-8.5) → -9

roundNegativeValueToNearestInteger(-8.49) → -8

Call your roundNegativeValueToNearestInteger method in the main method and see that it works as intended. When you call it, store it into an appropriately named variable and then print out that variable. Use casting in your solution to achieve the desired output.

About

ndcnckncdkjn

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%