Completely lost on how to complete this please help :( Below I have written a “m
ID: 3811400 • Letter: C
Question
Completely lost on how to complete this please help :(
Below I have written a “main” function for you. I have also shown what the output should be. You are notallowed to change main in any way nor add static variables. Implement the functions to make the program make the correct output. These ones here. Below. No changing. Seriously. Scorn otherwise. Content can be seen at grahamsmallwood.com/wp-content/uploads/2013/01/Homework74.pdf
public static void main(String[] args)
{
///// System.out.println("Enter first number between 1 and 10") int tFirst = GetGoodInt(1, 10)
System.out.println("Enter second number between 1 and 10")
int tSecond = GetGoodInt(1, 10) int tAnswer = BlertTwoNumbers(tFirst, tSecond)
System.out.println(tAnswer) ///// String tPony = "Pony" String tMonkey = "Monkey"
String tMonster = tMonkey+tPony for(int i = 0 i < 8 i++ ) tMonster = PerformScience(tMonster, tMonkey)
System.out.println(tMonster)
} // This doesn’t return until it has a good number. (It doesn’t rely on the caller to do the loop.)
static int GetGoodInt(int tLow, int tHigh)
{
???
}
// To Blert is to raise the second number to the first's power and then subtract two // *coughimportMathcough*
static int BlertTwoNumbers(int tOne, int tAnother )
{
???
}
// Insert creature two in to the middle of creature one. Science! // Hamster and Emu make a HamEmuster
static String PerformScience( String tCreatureOne, String tCreatureTwo )
{
???
}
Explanation / Answer
import java.util.Scanner;
import java.lang.Math;
public class string {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter first number between 1 and 10");
int tFirst = GetGoodInt(1, 10);
System.out.println("Enter second number between 1 and 10");
int tSecond = GetGoodInt(1, 10);
int tAnswer = BlertTwoNumbers(tFirst, tSecond);
System.out.println(tAnswer);
String tPony = "Pony";
String tMonkey = "Monkey";
String tMonster = tMonkey+tPony;
for(int i = 0;i < 8; i++ )
tMonster = PerformScience(tMonster, tMonkey);
System.out.println(tMonster);
}/*end of main*/
/* This doesn’t return until it has a good number. (It doesn’t rely on the caller to do theloop.)*/
static int GetGoodInt(int tLow, int tHigh)
{
Scanner sc=new Scanner(System.in);
int number;
do {
while (!sc.hasNextInt()) {
System.out.println("Not A Number");
sc.next(); // this is important!
}
number = sc.nextInt();
if(number<0)
{
System.out.println("Too Low");
}
if(number>10)
{
System.out.println("Too High");
}
} while (number < 0||number>10);
return number;
}
/* To Blert is to raise the second number to the first's power and then subtract two*/
/*coughimportMathcough*/
static int BlertTwoNumbers(int tOne,int tAnother )
{
int result = 1;
while (tOne != 0)
{
if ((tOne & 1) == 1)
result *= tAnother;
tOne >>= 1;
tAnother *= tAnother;/*to find the power of*/
}
return result-2;/*subtract 2 from result*/
}
/*Insert creature two in to the middle of creature one. Science!*/
/*Hamster and Emu make a HamEmuster*/
static String PerformScience( String tCreatureOne, String tCreatureTwo )
{
int length=tCreatureOne.length(); /*find the lenth*/
length=length/2; /*divide it to find middle of string one*/
String start = tCreatureOne.substring(0,length);/*substring of tCreatureOne*/
String End = tCreatureOne.substring(length);/*end subString of tCreatureOne*/
return start + tCreatureTwo + End;
}
}/*end of class string*/
/***************OUTPUT**********
Enter first number between 1 and 10
111
Too High
-4
Too Low
4
Enter second number between 1 and 10
7
2399
MonkeMonMonMonMonMonMonMonMonkeykeykeykeykeykeykeykeyyPony
*********************************/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.