1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
strojnjashka [21]
3 years ago
12

You have been handed a mysterious piece of data by an unknown person. Judging by his shifty eyes and maniacal laughter you don't

think he can be trusted. Complete the below method to tell you the type for this unknown data. The example already implemented can be adapted for other wrapper classes as well. Complete the method to analyze String, Character, and Double. Examples: whatAmI(1) -> "Integer" 1 public String whatAmI(E e) { 3 //.getClass() returns the runtime class of an object //.equals() determines whether two objects are equivalent //by calling a new static instance of a wrapper object we can analyze //it's class type and compare it to the variable passed in if(e.getClass().equals(new Integer(1).getClass()) { return "Integer"; }else{ return "Who knows!"; Given a word, use a stack to reverse the word and return a new string with the original word in reverse order. You cannot use the reverse string methods in the String class. Examples: reverseword("hello") -> "olleh" reverseword("hallo") -> "ollah" i public String reverseWord(String word) Stack character> stack = new Stack ;
Computers and Technology
1 answer:
irga5000 [103]3 years ago
5 0

Answer:

Java Code given below with appropriate comments for better understanding

Explanation:

1.

public String whatAmI(E e) {

//.getClass() returns the runtime class of an object

//.equals() determines whether two objects are equivalent

//by calling a new static instance of a wrapper object we can analyze

//it's class type and compare it to the variable passed in

if(e.getClass().equals(new Integer(1).getClass())) {

return "Integer";

}

else if(e.getClass().equals(new String("1").getClass())) {

return "String";

}

else if(e.getClass().equals(new Double(1.0).getClass())) {

return "Double";

}

else {

return "Who knows!";

}

}

2.

public String reverseWord(String word) {

   Stack<Character> stack = new Stack<Character>();

   for (int i = 0; i < word.length(); i++) {

       stack.push(word.charAt(i));

   }

   String result = "";

   while (!stack.isEmpty()) {

       result += stack.pop();

   }

   return result;

}

You might be interested in
How many lines are on a standard sheet of typing paper?
kotegsom [21]
60 lines on the paper
3 0
3 years ago
A teacher has five students who have taken four tests. The teacher uses the following grading scale to assign a letter grade to
AlladinOne [14]

Answer:

#include <iostream>

using namespace std;

int main()

{

const int numofStudents = 5;//number of students

const int numofTests = 2;//number of tests taken by students

const int grade = 5;//number of grades available

char letter[grade] = { 'A','B','C','D','F' };

double table[numofStudents][numofTests];//defining 2darray with names and scores

string names[numofStudents];//storing names of students

for (int num = 0; num < numofStudents; num++)//storing names and scores of students

{

 cout << "Enter student's name: ";

 cin >> names[num];

 for (int test = 0; test < numofTests; test++)//scores loop

 {

  cout << "Enter the test score: ";

  cin >> table[num][test];

  if (table[num][test] < 0 || table[num][test]>100)//input validation

  {

   cout << "Invalid input. Try again" << endl;

   cin >> table[num][test];//input again

  }

 }

}

for (int i = 0;i < numofStudents;i++)//calculating averages and grades

{

 int sum = 0;

 cout << "Test scores for " << names[i] << ": " << endl;

 for (int j = 0;j < numofTests;j++)

 {

  cout << table[i][j] << " ";

  sum += table[i][j];//summing scores

 }

 cout << endl;

 float average = (float)sum / numofTests;//calculating the average

 cout << "Making an average of: "<< average;

 if (average <= 100 && average >= 90)//assigning a grade

 {

  cout << " and has received an " << letter[0];

 }

 else if (average <= 89 && average >= 80)

 {

  cout << " and has received a " << letter[1];

 }

 else if (average <= 79 && average >= 70)

 {

  cout << " and has received a " << letter[2];

 }

 else if (average <= 69 && average >= 60)

 {

  cout << " and has received a " << letter[3];

 }

 else if (average <= 59 && average >= 0)

 {

  cout << " and has received an " << letter[4];

 }

 else

 {

  cout << "Invalid scores entered." << endl;

 }

 cout << endl;

}

 return 0;

}

Explanation:

We first define the number of students, number of tests and number of grades available for assignments. We then fill in the 2D array of students names and their scores making sure assigning more than 100 and less than 0 is not allowed. We then sum the scores and retrieve an average. Using the average, a letter grade is assigned to that individual.

6 0
3 years ago
HELP ME PLEASE
rosijanka [135]

Answer:

Variable, operator, expression, value.

Explanation:

We could use variables, operators, expressions, and values in a mathematical formula, we're going to do an example with every part.

For this example we're going to use a simple sum formula:

First, we have 3 variables:

sum;

sum1;

sum2;

Second, we have 3 operators:

=, + and *

Third, we have our expression and 1 value:

sum = sum1 + (sum2 * 5);

(sum2 * 5) = expression;

5 = value;

We're going to see the result when we print the variable sum.

8 0
3 years ago
Read 2 more answers
Which skill type refers to the ability to interact and communicate effectively with people?
sukhopar [10]
Softskills refer to the ability to interact and communicate effectively with people.
3 0
3 years ago
Put the parts of the program in order to have the output shown below.
Ksenya-84 [330]
Diana is attaching a brace to a rectangular gate. She will put the brace on the diagonal of the rectangle as shown.
5 0
3 years ago
Other questions:
  • Henry Ford would have been most interested to bring which modern innovation to his automotive factories?
    5·2 answers
  • In the Microsoft publisher application, words underlined in red are ____.
    6·1 answer
  • What is an input, output and storage device?
    12·1 answer
  • Why are 90% of questions not being answered im scrolling through the questions. Most are not being answered except the easy ques
    8·2 answers
  • Why should ERP architecture include a discussion on organizational structure, business processes, and people, instead of just in
    5·1 answer
  • what determines the best types of sketch or drawing to complete when you want to communicate your idea about a solution to a tec
    9·1 answer
  • A python package used in text analysis and natural language processing. True or False
    10·1 answer
  • A computer (mainframe, server, or workstation) that has an operating system enabling _____________ to access it at the same time
    11·1 answer
  • Which of the following is another type of brake system used in trucks
    5·1 answer
  • Plagiarism is considered
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!