Questions
Please use Java language in an easy way with comments! Thanks! Write a static method called...

Please use Java language in an easy way with comments! Thanks!

Write a static method called "evaluate" that takes a string as a parameter. The string will contain a postfix expression, consisting only of integer operands and the arithmetic operators +, -, *, and / (representing addition, subtraction, multiplication, and division respectively). All operations should be performed as integer operations. You may assume that the input string contains a properly-formed postfix expression. The method should return the integer that the expression evaluates to. The method MUST use a stack to perform the evaluation. Specifically, you should use the Stack class from the java.util package (For this problem, you must write a static "evaluate" method).

Also, in the same file, write a program that prompts the user to enter a postfix expression. Your program should evaluate the expression and output the result. Your program should call the "evaluate" method described above. Here are some examples:

     Postfix expression: 1 2 +
     Result: 3

     Postfix expression: 1 2 + 3 4 - *
     Result: -3

     Postfix expression: 3 4 5 + + 1 -
     Result: 11

In: Computer Science

In Java for beginners: The math teacher at Garfield High School, Mr. Escalante, is looking for...

In Java for beginners:

The math teacher at Garfield High School, Mr. Escalante, is looking for new ways to help his students learn algebra. They are currently studying the line equation ( y = m * x + b ). Mr. Escalante wants to be able to give his students a phone app that they can use to study for the midterm exam. This is what he'd like the program to do:

The user will be presented with the option to study in one of 3 modes, or to quit the program:

  1. Solve for the value of y, given the values for m, x and b.
  2. Solve for the value of m, given the values for y, x and b.
  3. Solve for the value of b, given the values for y, m and x.

In each mode, all of the given values should be randomly generated integers between -100 and +100. This means that the correct answer must be calculated by the program.

Once the student selects a mode, the program will continue to present randomly generated questions until the student has correctly answered 3 questions in a row. If the student attempts more than 3 questions in a particular mode, a hint about how to solve the problem should be given before the next question is presented.

After the student has correctly answered 3 questions in a row, an overall score (the number of questions answered correctly divided by the total number of questions attempted) should be displayed, and the menu is presented again.

DIRECTIONS

Your program must

  • define and use custom methods (functions)
  • use if statements
  • use while loops

This is a three-part staged assignment. You must complete part 1 with at least 80% success before you can begin part 2, and the same with part 3. After you've completed and submitted each part, you can proceed to the next part by selecting the drop-down arrow next to the assignment title. You will need to complete all parts to receive full credit.

---------------------------------------------------------------------------------------------

Part 1. Solve for y.

Write a program with a that displays a randomly generated problem that asks the user to solve for the y variable, takes input from the user, and prints "correct" if the user answered correctly and prints "incorrect" if not. Your main should give one problem and then exit. Use one or more methods to produce this behavior. Example interactions: Given: m = 10 x = 3 b = 2 What is the value of y? 32 Correct! Given: m = 6 x = 9 b = 3 What is the value of y? 52 Sorry, that is incorrect. The answer is 57.

Part 2. Solve for y, m and b.

Add 2 choices that behave similarly to your part 1 program, but have the user solve for m and b instead. These choices should also randomly generate problems, and print if the user answers correctly. Your main program should display a menu asking which type of question to ask: Select 1 to Solve for Y, 2 to Solve for M, 3 to Solve for B and 4 to quit. When the user selects the question type, one question should be asked, then the user should return to the menu. This should repeat until the user selects quit, then the program should exit. Use one or more methods and loops to produce this behavior.

Part 3.Three in a Row with Hints.

Update your program so that each problem type mode will repeatedly ask questions until the user gets 3 correct answers in a row. If the attempts more than 3 questions in a particular mode, the program should provide a hint on how to solve problems of this type. After the student has correctly answered 3 questions in a row, an overall score (the number of questions answered correctly divided by the total number of questions attempted) should be displayed, and the menu is presented again.

In: Computer Science

1. Lets construct a Dog class 2.Declare name, breed and weight as their private variables 3.Add...

1. Lets construct a Dog class

2.Declare name, breed and weight as their private variables

3.Add a default constructor

4.Write a constructor with name, breed and weight as arguments

5.Add a toString method to the class

6.Add a equals method

7.Add a copy contructor

8.Add a bark method in Dog class

•This method checks if the weight is greater than 25 , then print (dog.name says woof!) else (dog.name say yip!)

In: Computer Science

Draw a memory layout to show the relations of a, b and c. char a[3][10] =...

Draw a memory layout to show the relations of a, b and c.

char a[3][10] = {"abcdefg", "1234567", "!@#$%^&"};
char* b[3];
char** c;
b[0] = &a[0][0];
b[1] = &a[1][0];
b[2] = &a[2][0];
c = b;
char x = b[0][3];
char y = b[0][13];

In: Computer Science

(matlab) Since the problem is fairly complex, it may be better to complete & debug the...

(matlab) Since the problem is fairly complex, it may be better to complete & debug the program offline, then submit in Grader.

In this exercise you will complete a simplified program to play a hand of Blackjack. The goal is to complete a modular program using local and anonymous functions. Although there are several functions that must be written, they are all quite short and simple, just 1 to 4 lines. The most important learning objective is to understand how function definitions and function calls fit together.

PART 1: At the bottom of the template, complete the following local functions:

deal_hand() function

This function will generate a hand of two cards by generating two random numbers between 1 and 13.

Input argument: None

Output argument: A row vector of 2 integers between 1 and 13.

The body of the function can be implemented in a single line using the Matlab built-in function randi(). (NOTE: we are making a simplifying assumption that we have an infinite deck of cards, so we don’t have to keep track of which cards have already been dealt.)

To deal two cards, each having a value between 1 and 13, the form of the function is:

hand = randi (13, 1, 2);

display_hand() function

This function will display a blackjack hand to the screen.

input argument: a row vector containing the hand as described in 1.

output argumen: None

The contents of the display_hand() function will be as follows:

Define a row vector with characters representing the card values, like so:

cards = ['A','2','3','4','5','6','7','8','9','T','J','Q','K'];

(this can also be written more compactly as cards='A23456789TJQK')

NOTE: Each card is represented by a single character; thus ‘T’ is used for 10.

The character corresponding to a card value is accessed by indexing. For example if the card is a ten, the corresponding character using can be displayed by:

fprintf(‘%c’,cards(10))

The entire hand can be displayed with a single fprintf() call as follows:

fprintf(‘%c ’,cards(hand))

Once the hand has been displayed, print a new line using

fprintf(‘\n’)

score_hand()function

This function calculates the score of a blackjack hand.

Input argument: a hand (row vector of numbers between 1 and 13)

Output argument: the score corresponding to that hand of cards

To keep it simple, we will only allow the Ace to have a value of 1. (Allowing it to have either a value of 1 or 11 depending on context is a challenge problem that you can try after you have the rest of the game working.)

With this restriction, the value of the card is equal to the number representing the card, with the exception of face cards (11, 12, and 13), which are worth 10. You can use the min() function and the sum()function to sum the values of the cards while limiting each card to an upper value of 10.

Since the simplified score_hand() function only requires one line of code, it can be implemented via an in-line (anonymous) function. Try implementing it that way. It can be defined anywhere in the script before it is called for the first time.

deal_card() function

This function adds a card to an existing hand. Generate a single card using randi(), and use concatenation to add it to the existing hand. For example,

new_hand = [existing_hand new_card];

Input argument: a hand (row vector of numbers between 1 and 13)

Output argument: a hand consisting of the input hand with one additional card added to it.

PART 2: Add calls to your user-defined functions in the appropriate places of the template script. So that you don't have to think much about the logic of the game for this exercise, we have provided the looping and branching code.

(Script)

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

%to make an anonymous function for score_hand()

%complete this line:

score_hand = %code to calculate the score

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

%Testing the functions

testScore = score_hand(deal_card(deal_hand()));

testLength1=length(deal_hand());

testLength2=length(deal_card(deal_hand()));

disp('Blackjack:')

display_hand([1,13]);

%The main things that your program has to do are:

%

% Deal the cards

% Display the hand

% Calculate the score and store in the variable player_score or

% dealer_score

% display the score

%

%The other logic (when to quit the game, etc.) is already built into the

%template

%****************************************************

% ENTER YOUR CODE BETWEEN THE %XXXXXXXXXXXXXXX LINES.

%

%****************************************************

dealer_score = 0; %initialize dealer score so grader doesn't fail if player busts

disp('Your hand:')

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

% Deal the player's initial cards, score the hand, display the hand, display the score

player_score = 0; %Replace the 0 with a function call

fprintf('Score = %i\n', player_score);

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

hit = 1; %flag that says deal another card

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

%CHANGE THE FOLLOWING LINE AFTER YOU HAVE COMPLETED THE REST OF THE SCRIPT

%CHANGE THE 1 TO A 0

busted = 1; %flag that says player is not busted

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

while busted == 0 && hit == 1 && player_score < 21

% Since this game does not use user input, use a semi-intelligent

% algorithm to decide whether the player hits:

% if his score is <15, definitely hit

% if his score is >18, do not hit

% if his score is between 15 and 18, generate a random number

% to decide if he hits.

hit = player_score<15 || 15+randi(4)>player_score;

if hit == 1

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

% Deal one more card and calculate the score and display the hand

% and the score

fprintf('Score = %i\n', player_score); %display the score

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

if player_score > 21

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

% The player is busted and stops playing. Display a losing

% message

busted = 1;

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

end

end

end

if busted == 0

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

% Deal the dealer a separate hand, score it, then show it

disp('Dealer''s hand:')

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

while (dealer_score < player_score) && (dealer_score < 21)

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

%Deal the dealer a new card and calculate his score and display his

%new hand

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

end

if dealer_score > 21

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

% Show that the player wins

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

else

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

%Show that the dealer wins

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

end

end

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

%Complete these local functions

%Add input & output arguments as needed

function [] = deal_hand()

end

function [] = deal_card()

end

function [] = display_hand()

cards = 'A23456789TJQK';

end

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

In: Computer Science

Write a program that will calculate the sum of the first n odd integers, and the...

Write a program that will calculate the sum of the first n odd integers, and the

sum of the first n even integers.

Use a Do while loop

Use a for loop

Here is a sample of how the program should run:

How many odd integers would you like to add? 5

Count Odd Integer Sum

1 1 1

2 3 4

3 5 9

4 7 16

5 9 25

The sum of the first 5 odd integers is 25

How many even integers would you like to add? 7

Count Even Integer Sum

1 2 2

2 4 6

3 6 12

4 8 20

5 10 30

6 12 42

7 14 56

The sum of the first 7 even integers is 56

Do you want to add again? Press y or n

y

How many odd integers would you like to add?

Make sure your program works with any input value from 1 to 1000.

REMEMBER! The sum of the first 5 odd integers is 1 + 3 + 5 + 7 + 9. It is NOT the

sum of the odd integers up to 5

In: Computer Science

Below is part of my code to sort table of x,y,z cordinates using x,y with qsort....

Below is part of my code to sort table of x,y,z cordinates using x,y with qsort. I can read all the data into *xyz part of the structure and allocate memory, I keep getting errors on line 7, "read access violation". I would take any help...Thanks

typedef struct

{

       int x;

       int y;

       int z;

} Coordinates;

typedef Coordinates * xyz;

int compare(const void *p1, const void *p2)

       {

       const xyz num1 = *(const xyz *)p1;

       const xyz num2 = *(const xyz *)p2;

7      if (num1->x < num2->x)    //read access violation

       {

              return -1;

       }

       else if (num1->x > num2->x)

       {

              return 1;

       }

       else

       {

              if (num1->y < num2->y)

              {

                     return -1;

              }

              else if (num1->y > num2->y)

              {

                     return 1;

              }

              else

              {

                     return 0;

              }

       }

Main

{

//allocates memory

Coordinates * xyz = (Coordinates *) malloc(sizeof(Coordinates) * numElem);

qsort(xyz, numElem, sizeof(xyz), compare);

}

In: Computer Science

Transfer in MIPS char * strtoupper(char s[]) { char c; c = s[0]; /* empty string...

Transfer in MIPS

char * strtoupper(char s[]) {

char c;

c = s[0];

      /* empty string */
      if (c == 0)
            return s;

/* convert the first character to upper case*/

if (c >= ‘a’ && d <= ‘z’) { c -= 32;

s[0] = c; }

/* convert the remaining characters*/

      strtoupper(s + 1);

return s; }

In: Computer Science

whats wrong here? import java.util.Scanner; public class AirportParking2 {    public static void main(String[] args) {...

whats wrong here?

import java.util.Scanner;

public class AirportParking2 {
   public static void main(String[] args) {
       Scanner scnr = new Scanner(System.in);

       int parkmins;

       System.out.print("Enter minutes parked");
       parkmins = scnr.nextInt();

       if(parkmins < 0)
           System.out.println("Invalid");
       else {
           if(parkmins > 30)
               int numbDay = parkmins/(60*24);
               parkmins -= (numbDay*24*60);

               parkfee = 24 * numbDay;

               int fee = 0;
       {
           parkmind -= 60;
           fee += 2;

           while(parkmins > 0)

           {
               fee += 1;
               parkmins -= 30;
           }  

           if(fee > 24)
               fee = 24;
       }

       parkfee += fee;
       System.out.println("Fee: $" +parkfee);


   }
}

In: Computer Science

Binary conversion: Convert 1234.5869 × 103 to IEEE 745 (show your work)

Binary conversion:

Convert 1234.5869 × 103 to IEEE 745 (show your work)

In: Computer Science

List all major steps when developing android applications. Use code examples if possible. These steps should...

List all major steps when developing android applications. Use code examples if possible. These steps should pertain to the most commonly distributed android applications. Only consider Java-based applications.

In: Computer Science

Write a single statement that prompts the user to enter their age in years and places...

Write a single statement that prompts the user to enter their age in years and places the integer value in a variable named age.

Write a short code segment in Python that prompts the user to enter the number of quarters, dimes, nickels and pennies they have, compute the total value and print that value

What convention is considered “standard” for the naming of variables and functions, in order to improve the readability of code?

What type of error will occur due to the following Python statement? -  Class = “Type II”

Using decimal scientific literal notation, write the number 314,159.

In: Computer Science

in your opinion what is Leach (2010) Can your computer make you happy in 200 words.

in your opinion what is Leach (2010) Can your computer make you happy in 200 words.

In: Computer Science

Write a C# console program that continually asks the user "Do you want to enter a...

Write a C# console program that continually asks the user "Do you want

to enter a name (Y/N)? ". Use a "while" loop to accomplish this. As long as the user enters

either an upper or lowercase 'Y', then prompt to the screen "Enter First and Last Name: " and

then get keyboard input of the name. After entering the name, display the name to the screen.

---

Create a Patient class which has private fields for patientid, lastname,

firstname, age, and email. Create public data items for each of these private fields with get and

set methods. The entire lastname must be stored in uppercase. Create a main class which

instantiates a patient object and sets values for each data item within the class. Display the

data in the object to the console window.

---

Modify the Patient class with two overloaded constructors: A new default

constructor which initializes the data items for a patient object using code within the

constructor (use any data). A second constructor with parameters to pass all the data items

into the object at the time of instantiation. Create a test main class which instantiates two

objects. Instantiate the first object using the default constructor and the second object using

the constructor with the parameters.

---

Modify the main class in the patient application to include a display

method that has a parameter to pass a patient object and display its content.

---

Modify the patient class with two overloaded methods to display a bill for a

standard visit based on age. In the first method do not use any parameters to pass in data. If

the patient is over 65, then a standard visit is $75. If the patient is under 65, then the standard

doctors office visit is $125. Build a second method where you pass in a discount rate. If the

patient is over 65, then apply the discount rate to a standard rate of $125. Create a main

method that calls both of these methods and displays the results.

-----

Create two subclasses called outpatient and inpatient which inherit from

the patient base class. The outpatient class has an additional data field called doctorOfficeID

and the inpatient class has an additional data item called hospitalID. Write a main method that

creates inpatient and outpatient objects. Sets data for these objects and display the data.

---

Modify the base class of Problem 5 to be an abstract class with an abstract

display method called displayPatient that does not implement any code. Create specific

implementations for this method in both the outpatient and inpatient subclasses

In: Computer Science

In C++ with comments in code with screenshot In this assignment, you are asked to create...

In C++ with comments in code with screenshot

In this assignment, you are asked to create a class called Account, which models a bank account. The requirement of the account class is as follows, (1) It contains two data members: accountNumber and balance, which maintains the current account name and balance, respectively. (1) It contains three functions: functions credit() and debit(), which adds or subtracts the given amount from the balance, respectively. The debit() function shall print ”amount withdrawn exceeds the current balance!” if the amount is more than balance. A function print(), which shall print ”A/C no: xxx Balance=xxx” (e.g., A/C no: 991234 Balance=$88.88), with balance rounded to two decimal places.

When you submit your code, please upload your class code(s) and your test code to prove that your code works correctly.

In: Computer Science