java
1. Write a method header on line three with the following specs:
Returns: a boolean
Name: beTrue
Parameters: none
public class Main
{
{
return true;
}
}
2.
Write a method header on line two with the following specs:
Returns: a String
Name: makeCapital
Parameters: a String named "name"
You should not be writing code on any line other than #2
public class Main {
{
String ans = name.toUpperCase();
return ans;
}
//test case below (dont change):
public static void main(String[] args){
System.out.println(makeCapital("test"));
}
}
3.
Returns: an integer
Name: addTwo
Parameters:
An integer called "x"
An integer called "y"
You should not be writing code on any line other than #3
public class Main
{
{
return x+y;
}
//test case below (dont change):
public static void main(String[] args)
{
int total = addTwo(3,4);
System.out.println( total );
}
}
4.
Write a method header on line NINE with the following specs:
Returns: a double
Name: negate
Parameters: a double called "num"
Then, starting on line 11, write the code that will return the opposite value of num (if it's positive, make it negative, otherwise make it positive)
Examples:
4 ==> -4
-10 ==> 10
1 ==> -1
public class Main
{
public static void main(String[] args){
System.out.println(negate(8));
//should be -8
System.out.println(negate(-2));
//should be 2
}
//test case above (dont change):
{
}
}
5.
Write a method header on line NINE with the following specs:
Returns: a boolean
Name: bothEven
Parameters:
an integer called "num1"
an integer called "num2"
Examples:
bothEven(4,6) ==> true
bothEven(3,4) ==> false
bothEven(-1,1) ==> falsepublic class Main
{
//test case below (dont change):
public static void main(String[] args){
System.out.println(bothEven(8,6));
//should be true
System.out.println(bothEven(5,6));
//should be false
Then, starting on line 11, write code that will return true if both num1 and num2 are even. Return false otherwise.
6.
Write a method header on line TEN with the following specs:
Returns: a char
Name: getChar
Parameters:
a String called "word"
an integer called "index"
Examples:
getChar("hello",1) ==> 'e'
public class Main
{
public static void main(String[] args)
{
System.out.println(getChar("hello",1)); //should be 'e'
}
//Write your code below (don't change lines
above):
7.
Write a method header on line TEN with the following specs:
Returns: a String
Name: makeThreeSubstr
Parameters:
a String called "word"
an integer called "startIndex"
an integer called "endIndex"
Examples:
makeThreeSubstr("hello",0,2) ==> "hehehe"
makeThreeSubstr("shenanigans",3,7) ==> "naninaninani"
public class Main
{
public static void main(String[] args)
{
System.out.println(makeThreeSubstr("hello",0,2)); //should be
hehehe
System.out.println(makeThreeSubstr("shenanigans",3,7)); //should be
naninaninani
}
//change only the code below
please answer me quickly thank you so much
Then, starting on line 12, write code that will return 3x the substring (no spaces) from "startIndex" to "endIndex"
Then, starting on line 12, write code that will return the character in "word" at the index "index"
====================ANSWER ARE HIGHLIGHTED IN BOLD=============================
public class Main
{
public static boolean beTrue()
{
return true;
}
}
2.
public class Main {
public static String makeCapital(String
name)
{
String ans = name.toUpperCase();
return ans;
}
//test case below (dont change):
public static void main(String[] args){
System.out.println(makeCapital("test"));
}
}
3.
Returns: an integer
Name: addTwo
Parameters:
An integer called "x"
An integer called "y"
You should not be writing code on any line other than #3
public class Main
{
public static int addTwo(int x, int y)
{
return x+y;
}
//test case below (dont change):
public static void main(String[] args)
{
int total = addTwo(3,4);
System.out.println( total );
}
}
4.
Write a method header on line NINE with the following specs:
Returns: a double
Name: negate
Parameters: a double called "num"
Then, starting on line 11, write the code that will return the opposite value of num (if it's positive, make it negative, otherwise make it positive)
Examples:
4 ==> -4
-10 ==> 10
1 ==> -1
public class Main
{
public static void main(String[] args){
System.out.println(negate(8));
//should be -8
System.out.println(negate(-2));
//should be 2
}
//test case above (dont change):
public static double negate(double num){
return -1*num;
}
}
5.
Write a method header on line NINE with the following specs:
Returns: a boolean
Name: bothEven
Parameters:
an integer called "num1"
an integer called "num2"
Examples:
bothEven(4,6) ==> true
bothEven(3,4) ==> false
bothEven(-1,1) ==> false
public class Main
{
//test case below (dont change):
public static void main(String[] args){
System.out.println(bothEven(8,6));
//should be true
System.out.println(bothEven(5,6));
//should be false
}
public static boolean bothEven(int num1 , int num2) {
return num1%2== 0 && num2%2== 0
}
Then, starting on line 11, write code that will return true if both num1 and num2 are even. Return false otherwise.
6.
Write a method header on line TEN with the following specs:
Returns: a char
Name: getChar
Parameters:
a String called "word"
an integer called "index"
Examples:
getChar("hello",1) ==> 'e'
public class Main
{
public static void main(String[] args)
{
System.out.println(getChar("hello",1)); //should be 'e'
}
//Write your code below (don't change lines
above):
public static char getChar(String word, int index) {
return word.charAt(index);
}
7.
Write a method header on line TEN with the following specs:
Returns: a String
Name: makeThreeSubstr
Parameters:
a String called "word"
an integer called "startIndex"
an integer called "endIndex"
Examples:
makeThreeSubstr("hello",0,2) ==> "hehehe"
makeThreeSubstr("shenanigans",3,7) ==> "naninaninani"
public class Main
{
public static void main(String[] args)
{
System.out.println(makeThreeSubstr("hello",0,2)); //should be
hehehe
System.out.println(makeThreeSubstr("shenanigans",3,7)); //should be
naninaninani
}
//change only the code below
public static String makeThreeSubstr(String word , int startIndex, int endIndex) {
String substr =
word.substring(startIndex, endIndex) ;
return substr + substr+ substr;
}
java 1. Write a method header on line three with the following specs: Returns: a boolean...
I need java code for the following problem.
Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...
Filename(s): ReformatCode. java Public class: ReformatCode Package-visible class(es): none Write a program that reformats Java source code from the next-line brace style to the end-of-line brace style. The program is invoked from the command line with the input Java source code file as args [0] and the name of the file to save the formatted code in as args [1]. The original file is left untouched. The program makes no other changes the source code, including whitespace. For example, the...
JAVA Programming
Produce a method that reads in a set of values (double) from the
user and returns them. Use this header:
public static double[] getNumsFromUser(String msg1,
String msg2)
The implementation of the method should start with a message to
input the total number of array elements, followed by a message to
enter all the array elements. The method returns the array of
elements. The two strings msg1 and msg2 that are passed to the
method as parameters will be...
in
java
Part 1 In this section, we relook at the main method by examining passing array as parameters. Often we include options/flags when running programs. On command line, for example, we may do “java MyProgram -a -v". Depending on options, the program may do things differently. For example, "a" may do all things while "-v" display messages verbosely. You can provide options in Eclipse instead of command line: "Run ... Run Configurations ... Arguments". Create a Java class (Main.java)....
This is a java assignment Please help me Write the body of the fileAverage() method. Have it open the file specified by the parameter, read in all of the floating point numbers in the file and return their average (rounded to 1 decimal place). For the testing system to work, don't change the class name nor the method name. Additionally, the file will have different contents during testing. public class Main { public double fileAverage( String filename ){ }...
Java has a class for a stack. It is java.util.Stack. Let us make use of this class. Step 1: Create a project. Name the project MyStk. This will result in the creation of the main class called MyStk if you are using Netbeans IDE with relevant default settings unchanged. If comments are excluded you should see the following in the code editor after creating the project. package mystk; public class MyStk { public static void main(String[ ] args){ } }...
Question 1[JAVA] Add a method in the Main class named getLines() that takes a filename as a String and returns each line in the file in an array. Have each element of the array be a String. Do not include the newline at the end of each line. Use a BufferedReader object to read the file contents. Note, the contents of input.txt will be different (including the number of lines) for each test case. Example: getLines( "input.txt" ) returns (an...
When I try running this code in java, it doesn't work properly. The part where it should ask the user to write some string, where I would write in "one two three four" doesn't work, it says "bash: one: command not found" Please help fix. public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); System.out.println("The arguments are:"); for(String element : args) { System.out.println("\t" + element); } } } Sample output: Hello World! The arguments are: ...
Java 1. Write a getCount method in the IntArrayWorker class that returns the count of the number of times a passed integer value is found in the matrix. There is already a method to test this in IntArrayWorkerTester. Just uncomment the method testGetCount() and the call to it in the main method of IntArrayWorkerTester. 2. Write a getLargest method in the IntArrayWorker class that returns the largest value in the matrix. There is already a method to test this in...
1) Consider the following Java program: 1 public class HelloWorld { 2 // My first program! 3 public static void main(String[] args) { 4 System.out.println("Hello, World!"); 5 } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...