Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed for this assignment, so don't use them.
_ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please write the code according to functions assigned for the assignment.
You can use these functions in the assignment.
Modifier and Type | Method | |
---|---|---|
static int | bestGuess(int firstGuess, int secondGuess, int answer) | |
static double | bigProduct(double firstNumber, double secondNumber) | |
static int | bigSum(int firstNumber, int secondNumber) | |
static int | countWord(java.lang.String word, java.lang.String text) | |
static boolean | hasBlank(java.lang.String original) | |
static boolean | hasWord(java.lang.String word, java.lang.String text) | |
static boolean | isCapital(java.lang.String original) | |
static boolean | isFloat(java.lang.String firstString) | |
static boolean | isInt(java.lang.String firstString) | |
static int | topSum(int firstNumber, int secondNumber, int thirdNumber, int fourthNumber) |
/**
This exercise involves implementing several methods.
Stubs for each method
with documentation are given here. It is your task to
fill out the code in
each method body so that it runs correctly according
to the documentation.
You can run this file by compiling
TestMethods1.java
It will call this program and run it, validating the
test you choose.
Example inputs with output are provided in the
comments before each method.
At a minimum, your solutions must pass these tests. My
version of TestMethods1
contains more than the examples given or those cases
in your version of
TestMethods1. Therefore, hardcoding the answers will
not pass.
**/
//imports are not allowed in this exercise.
public class ExerciseMethods1{
/**
Boolean function returns true if
the given string begins with a capital letter.
isCapital("Robert") returns
true
isCapital("CSCE111") returns
true
isCapital("bicycle") returns
false
isCapital("42") returns false
isCapital("") returns false
isCapital(" home") returns
false
isCapital("TAMU")) returns true
@param original String,
@return true if the first letter is
a capital letter. False otherwise.
*/
public static boolean isCapital(String original)
{
//your code here
return false;
}//end isCapital
/**
Int function that returns true if
the string has a blank.
hasBlank("Robert Lightfoot")
returns true
hasBlank("Today is the best ever.")
returns true
hasBlank("abcdefghijklmnopqrstuvwxyz") returns false
hasBlank("2590") returns
false
hasBlank("") returns false
hasBlank(" home") returns
true
hasBlank("TAMU")) returns
false
@param original String,
@return true if a blank is
contained. False otherwise.
*/
public static boolean hasBlank(String original)
{
//your code here
return false;
}// end hasBlank
/**
isInt function returns true if the
string is an integer. false otherwise
isInt("12564") returns
true
isInt("-567") returns true
isInt("23.9") returns false
isInt("twenty two") returns
false
@param firstString String,
@return true only if the input
string only contains digits 0-9 and/or a leading "-".
*/
public static boolean isInt(String firstString)
{
//your code here
return false;
}// end isInt
/**
isFloat function returns true if
the string is a floating point number. false otherwise
Note, like doubles, integers are
acceptable.
isFloat("12564") returns
true
isFloat("-567") returns true
isFloat("23.9") returns true
isFloat("-56.7") returns true
isFloat("-567h") returns
false
isFloat("twenty two") returns
false
@param firstString String,
@return true only if the input
string only contains an optional leading "-"digits 0-9
and/or a "." followed
by optional trailing digits.
*/
public static boolean
isFloat(String firstString)
{
//your code
here
return false;
}// end isFloat
/**
If the word is
contained in the text, return true. Otherwise return false.
Capitalization is not
cosidered. Consider the whole word,
"The" is not contained
in "There are no more bananas."
hasWord("Nice",
"Today is a nice day.") returns true
hasWord("The", "There
are no more bananas!") returns false
// hasWord("bananas",
"There are no more bananas?") returns true
hasWord("any-string",
"I can find any-string any-where.") returns true
hasWord("I", "I
can find any-string any-where.") returns true
hasWord("Army", "I
have decided to join the Navy.") returns false
myFunctions.hasWord(" ", "") returns false
@param word
String,
@param text
String,
@return true if the
word in contained in the text.
*/
public static boolean hasWord(String word, String text)
{
//your code here
return false;
}//end hasWord
/**
If the word is contained in the
text, return the number of times it is contained.
Otherwise return 0. If there is no
word, or no text, return -1.
Look at whole words, "the" is not
contained in "these".
Capitalization is not
cosidered.
hasWord("the", "The weather
outside is frightful.") returns 1
hasWord("any-where", "I can find
any-string any-where.") returns 1
hasWord("farm","Old McDonald had a
farm. EI EI O. And on that farm he had a cow.") returns 2
hasWord("do","I love dogs, do
you?") returns 1
hasWord("Army", "I have decided to
join the Navy.") returns 0
hasWord("","This is the fist line
of over 1000 lines.") returns -1
@param word String,
@param text String,
@return returns the count of word
in text, or -1 if either is null.
*/
public static int countWord(String
word, String text)
{
//your code here
return -1;
}//end countWord
/**
Given three integers, return
whichever is closer to the answer.
In the event of a tie return
0.
Note that Math.abs(n) returns the
absolute value of a number.
bestGuess(8, 13, 10) returns
8
bestGuess(13, 8, 10) returns
8
bestGuess(13, 7, 10) returns
0
@param firstGuess int number,
@param secondGuess int
number,
@param answer int number,
@return of two int guess values,
whichever is closer to the answer.
*/
public static int bestGuess(int firstGuess, int secondGuess, int
answer)
{
//your code here
return 0;
}//end bestGuess
/**
Method topSum returns the sum of
the largest two numbers sent.
topSum(3, 3, 3, 3) returns
6
topSum(1, 10, 45, 2) returns
55
topSum(-6, 2, -45, -8) returns
-4
topSum(3, 113, 2, 200) returns
313
@param firstNumber int
number,
@param secondNumber int
number,
@param thirdNumber int
number,
@param fourthNumber int
number,
@return the sum of the largest two
numbers sent.
*/
public static int topSum(int firstNumber, int secondNumber, int
thirdNumber, int fourthNumber )
{
//your code here
return 0;
}// end topSum
/**
Method bigSum returns the sum of
all numbers between the first number and the second
number inclusive. Works in either
direction.
bigSum(3, 3) returns 6
bigSum(1, 10) returns 55
bigSum(-6, 1) returns -20
bigSum(5, 3) returns 12
@param firstNumber int
number,
@param secondNumber int
number,
@return the sum of the numbers from
the first to the second.
*/
public static int bigSum(int firstNumber, int
secondNumber)
{
//Your code here
return 0;
}//end bigSum
/**
Method bigProduct returns the
product of all numbers between the first number and the
second
number inclusive. Works in either
direction.
bigProduct(3, 3) returns 9
bigProduct(1, 10) returns
362880
bigProduct(-6, 1) returns 0
bigProduct(5, 3) returns 60
@param firstNumber double
number,
@param secondNumber double
number,
@return the product of the numbers
from the first to the second.
*/
public static double bigProduct(double firstNumber,
double secondNumber)
{
//Your code here
return 0.0;
}//end bigProduct
}//end ExerciseMethods1
here is the code ----
//imports are not allowed in this exercise.
public class ExerciseMethods1{
/**
Boolean function returns true if the given string begins with a
capital letter.
isCapital("Robert") returns true
isCapital("CSCE111") returns true
isCapital("bicycle") returns false
isCapital("42") returns false
isCapital("") returns false
isCapital(" home") returns false
isCapital("TAMU")) returns true
@param original String,
@return true if the first letter is a capital letter. False
otherwise.
*/
public static boolean isCapital(String original)
{
boolean result=false;
//convert in to array to find the first letter of word is
Capital
char org[]=original.toCharArray();
if(Character.isUpperCase(org[0]))
{
//save true in the boolean value
result . if first letter is capital letter
result=true;
}
return result;
}//end isCapital
/**
Int function that returns true if the string has a blank.
hasBlank("Robert Lightfoot") returns true
hasBlank("Today is the best ever.") returns true
hasBlank("abcdefghijklmnopqrstuvwxyz") returns false
hasBlank("2590") returns false
hasBlank("") returns false
hasBlank(" home") returns true
hasBlank("TAMU")) returns false
@param original String,
@return true if a blank is contained. False otherwise.
*/
public static boolean hasBlank(String original)
{
boolean result=false;
//if string has the white space , we use the contains
method for check the word is in the text or not
if(original.contains(" "))
{
//save true in the boolean value
result .
result=true;
}
//your code here
return result;
}// end hasBlank
/**
isInt function returns true if the string is an integer. false
otherwise
isInt("12564") returns true
isInt("-567") returns true
isInt("23.9") returns false
isInt("twenty two") returns false
@param firstString String,
@return true only if the input string only contains digits 0-9
and/or a leading "-".
*/
public static boolean isInt(String firstString)
{
boolean result;
try
{
Integer
value=Integer.parseInt(firstString);
//convert string into Integer if
sucessfully convert then save true in the boolean value result
.
result=true;
// else throw an exception and we handle the exception
as save the result as false;
}
catch(Exception e)
{
result=false;
//save false in the boolean value
result .
}
return result;
}// end isInt
/**
isFloat function returns true if the string is a floating point
number. false otherwise
Note, like doubles, integers are acceptable.
isFloat("12564") returns true
isFloat("-567") returns true
isFloat("23.9") returns true
isFloat("-56.7") returns true
isFloat("-567h") returns false
isFloat("twenty two") returns false
@param firstString String,
@return true only if the input string only contains an optional
leading "-"digits 0-9
and/or a "." followed by optional trailing digits.
*/
public static boolean isFloat(String firstString)
{
boolean result=false;
try{
//convert string
into Double if sucessfully convert then save true in the boolean
value result .
Double
value=Double.parseDouble(firstString);
// else throw an exception and we handle the exception
as save the result as false;
result=true;
}
catch(Exception e)
{
//save false in the boolean value
result .
result=false;
}
return result;
}// end isFloat
/**
If the word is contained in the text, return true. Otherwise return
false.
Capitalization is not cosidered. Consider the whole word,
"The" is not contained in "There are no more bananas."
hasWord("Nice", "Today is a nice day.") returns true
hasWord("The", "There are no more bananas!") returns false
// hasWord("bananas", "There are no more bananas?") returns
true
hasWord("any-string", "I can find any-string any-where.") returns
true
hasWord("I", "I can find any-string any-where.") returns true
hasWord("Army", "I have decided to join the Navy.") returns
false
myFunctions.hasWord(" ", "") returns false
@param word String,
@param text String,
@return true if the word in contained in the text.
*/
public static boolean hasWord(String word, String text)
{
//your code here
boolean result=false;
//check word contains by the text by using the method
contains
if(text.contains(word) &&
!word.isEmpty())
{ //if text contains the word and word is not empty
then
//save true in the boolean value result .
result=true;
}
return result;
}//end hasWord
/**
If the word is contained in the text, return the number of times it
is contained.
Otherwise return 0. If there is no word, or no text, return
-1.
Look at whole words, "the" is not contained in "these".
Capitalization is not cosidered.
hasWord("the", "The weather outside is frightful.") returns
1
hasWord("any-where", "I can find any-string any-where.") returns
1
hasWord("farm","Old McDonald had a farm. EI EI O. And on that farm
he had a cow.") returns 2
hasWord("do","I love dogs, do you?") returns 1
hasWord("Army", "I have decided to join the Navy.") returns 0
hasWord("","This is the fist line of over 1000 lines.") returns
-1
@param word String,
@param text String,
@return returns the count of word in text, or -1 if either is
null.
*/
public static int countWord(String word, String text)
{
int value=-1;
// split the string by spaces in array a
String a[] = text.split(" ");
// search for pattern in array a
int count = 0;
for (int i = 0; i < a.length; i++)
{
// if match found increase count
if (word.equals(a[i]))
count++;
}
//set the value = count to return as result;
value=count;
return value;
}//end countWord
/**
Given three integers, return whichever is closer to the
answer.
In the event of a tie return 0.
Note that Math.abs(n) returns the absolute value of a number.
bestGuess(8, 13, 10) returns 8
bestGuess(13, 8, 10) returns 8
bestGuess(13, 7, 10) returns 0
@param firstGuess int number,
@param secondGuess int number,
@param answer int number,
@return of two int guess values, whichever is closer to the
answer.
*/
public static int bestGuess(int firstGuess, int secondGuess, int
answer)
{
// Method to compare which one is the more close
// We find the closest by taking the difference
// between the answer and both values. It assumes
// that secondGuess is greater than firstGuess and answer
lies
// between these two.
int number=0;
if(secondGuess>=answer && secondGuess
>=firstGuess)
{ //check if secondGuess is greater than the answer
and firstNumber
if(answer - firstGuess >=
secondGuess - answer)
{ //find the difference between the
numbers and set the value into number to return;
number=secondGuess;
}
else{
number=firstGuess;
}
}
else if(firstGuess>=answer &&
firstGuess>=secondGuess)
{
//check if firstGuess is greater
than the answer and secondGuess
if(answer - secondGuess >=
firstGuess - answer)
{ //find the difference between the
numbers and set the value into number as result;
number=firstGuess;
}
else{
number=secondGuess;
}
}
return number;
}//end bestGuess
/**
Method topSum returns the sum of the largest two numbers sent.
topSum(3, 3, 3, 3) returns 6
topSum(1, 10, 45, 2) returns 55
topSum(-6, 2, -45, -8) returns -4
topSum(3, 113, 2, 200) returns 313
@param firstNumber int number,
@param secondNumber int number,
@param thirdNumber int number,
@param fourthNumber int number,
@return the sum of the largest two numbers sent.
*/
public static int topSum(int firstNumber, int secondNumber, int
thirdNumber, int fourthNumber )
{
int number=0;
//create array and store the number into it . to find the two
greater number
int
nums[]={firstNumber,secondNumber,thirdNumber,fourthNumber};
int maxOne = 0; //maxOne initialize by 0
int maxTwo = 0; //maxTwo initialize by 0
for(int n:nums){ //using for-each loop to find the top two number
from array
if(maxOne < n){
maxTwo = maxOne;
maxOne =n;
} else if(maxTwo < n){
maxTwo = n;
}
}
//sum the numbers
number=maxOne+maxTwo;
return number;
}// end topSum
/**
Method bigSum returns the sum of all numbers between the first
number and the second
number inclusive. Works in either direction.
bigSum(3, 3) returns 6
bigSum(1, 10) returns 55
bigSum(-6, 1) returns -20
bigSum(5, 3) returns 12
@param firstNumber int number,
@param secondNumber int number,
@return the sum of the numbers from the first to the second.
*/
public static int bigSum(int firstNumber, int secondNumber)
{
int number=0;
//declare a variable to store sum
int sum = 0;
//loop to add numbers between the
given range
for(int i = firstNumber ; i <=
secondNumber ; i++)
{ //loop to add numbers
between the firstNumber and secondNumber
sum=sum+i;
}
//display the sum
number=sum;
return number;
}//end bigSum
/**
Method bigProduct returns the product of all numbers between the
first number and the second
number inclusive. Works in either direction.
bigProduct(3, 3) returns 9
bigProduct(1, 10) returns 362880
bigProduct(-6, 1) returns 0
bigProduct(5, 3) returns 60
@param firstNumber double number,
@param secondNumber double number,
@return the product of the numbers from the first to the
second.
*/
public static double bigProduct(double firstNumber, double
secondNumber)
{
double number=0;
double product=1;
for(double
i=firstNumber;i<=secondNumber;i++) {
product *=
i;
}
number=product;
return number;
}//end bigProduct
public static void main(String args[])
{
boolean isCapital=isCapital("Robert");
System.out.println("the given String is capital :
"+isCapital);
boolean hasBlank=hasBlank("this is String");
System.out.println("the given String has Blank :
"+hasBlank);
boolean isInt=isInt("154");
System.out.println("the given
String is Integer : "+isInt);
boolean isFloat=isFloat("475.35");
System.out.println("the given
String is Float : "+isFloat);
boolean hasWord=hasWord("the","the given String
");
System.out.println("the given String has Word :
"+hasWord);
int countWord=countWord("the","the army is our pride
of the nation , the navy is the type of an army");
System.out.println("the total count
word is : "+countWord);
int bestGuess=bestGuess(8,13,10);
System.out.println("the bestGuess is :
"+bestGuess);
int topSum=topSum(1,10,45,2);
System.out.println("the topSum is : "+topSum);
int bigSum=bigSum(1,10);
System.out.println("the big Sum is : "+bigSum);
double bigProduct=bigProduct(1,10);
System.out.println("the big Product is :
"+bigProduct);
}
}//end ExerciseMethods1
here are the inputs given at compile time and out put ---
snapshots are---
i hope it would be helpfull for you,, Thank You !
Please write a code in Java where it says your // your code here to run...
Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please write the code according to functions assigned...
Hey, I was wondering if there’s another way to make these methods not reliable to imports such as “import java.util.Arrays” and “import java.util.Hash” I am still new in coding and would like to know if there’s another way to do it! Here is the code! (Thank you in advance and I will really appreciate it :) ) /** This exercise involves implementing several methods. Stubs for each method with documentation are given here. It is your task to fill out...
Please help me do the java project For this project you will be reading in a text file and evaluating it in order to create a new file that represents the Class that will represent the properties of the text file. For example, consider the following text file: students.txt ID Name Age IsMale GPA 1 Tom Ryan 22 True 3.1 2 Jack Peterson 31 True 2.7 3 Cindy LuWho 12 False 3.9 When you read in the header line, you...
Given java code is below, please use it! import java.util.Scanner; public class LA2a { /** * Number of digits in a valid value sequence */ public static final int SEQ_DIGITS = 10; /** * Error for an invalid sequence * (not correct number of characters * or not made only of digits) */ public static final String ERR_SEQ = "Invalid sequence"; /** * Error for...
I am unsure how to add the following methods onto this code?? please help - rowValuesIncrease(int[][] t) A method that returns true if from left to right in any row, the integers are increasing, otherwise false. - columnValuesIncrease(int[][] t) A method that returns true if from top to bottom in any column, the integers are increasing, otherwise false. - isSetOf1toN(int[][] t) A method that returns true if the set of integers used is {1, 2, . . . , n}...
Please write where its written write your code here!! please use java for the code! please use the given code and I will rate thanks Magic index in an array a[1..n] is defined to be an index such that a[ i ] = i. Given an array of integers, write a recursive method to find the first magic index from left to right. If one exists in the given array, return the index number i, otherwise return -1. Here are...
Create a method based program to find if a number is prime and then print all the prime numbers from 1 through 500 Method Name: isPrime(int num) and returns a boolean Use for loop to capture all the prime numbers (1 through 500) Create a file to add the list of prime numbers Working Files: public class IsPrimeMethod { public static void main(String[] args) { String input; // To hold keyboard input String message; // Message...
Topics: About Java What is a compiler, and what does it do? Characteristics of the languageStrongly typed and statically typed Everything has a data type & data types must be declared Case sensitive Object oriented System.out.print() vs. System.out.println() How to use the Scanner class to obtain user input Data typesWhat are they? Know the basic types like: int, double, boolean, String, etc. Variables What is a variable? Declarations Initialization Assignment Constants Reserved words like: What is a reserved word? Examples:...
Java: Create the skeleton. Create a new file called ‘BasicJava4.java’ Create a class in the file with the appropriate name. public class BasicJava4 { Add four methods to the class that return a default value. public static boolean isAlphabetic(char aChar) public static int round(double num) public static boolean useSameChars(String str1, String str2) public static int reverse(int num) Implement the methods. public static boolean isAlphabetic(char aChar): Returns true if the argument is an alphabetic character, return false otherwise. Do NOT use...
A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run. In this program, ask the user to input some text and print out whether or not that text is a palindrome. Create the Boolean method isPalindrome which determines if a String is a palindrome, which means it is the same forwards and backwards. It should return a boolean of whether or not it was a palindrome. Create the method reverse...