Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java Program that Use\'s a while statement in Order to make a Program th

ID: 3671675 • Letter: W

Question

Write a Java Program that Use's a while statement in Order to make a Program that will Solve the Problem and Produce bellow Output.

Problem:

An accumulator is a primitive kind of calculator that can evaluate arithmetic expressions. In fact, the Arithmetic-Logic Unit (ALU) of the first computers was just an accumulator. An arithmetic expression, as you know, consists of two kinds of tokens: operands and operators. All our operands will be (float) numbers and for a start, and the operators are characters (char). We shall use only two operators: + (plus) and - (minus).

The output looks like the following:

Strategy:

Input: An alternating sequence of operands and operators, given one at a time, starting with an operand and ending with an operand followed by an equals sign. Each operand is a float value and each operator is a plus or a minus.

Output: The value of the expression defined by the sequence of operands and operators. We shall assume for now that the user will not make mistakes when using the accumulator, i.e., there is no bad input (e.g., two consecutive tokens being both operands or both operators, other unexpected characters etc.) Note that the equals sign acts like a terminating operator.The Strategy. To initialize the process, the first operand (a number) is read and stored as the total. Next, an operator (a character) is read and we decide what action to take. The action can be one of the following:

(i) In case of termination (equals sign) the process is exited and the total is printed;                                                                                                                                                      (ii) Otherwise another operand is read and either added to or subtracted from the total depending on the operator.

Hint1: To read a character, you can use the following code: operator = (char)System.in.read();

The output looks like the following: run : Welcome to your friendly neighborhood accumulator! Please input your expression, starting with an operand and type inwhen completed. 1.0 2.1 The result is: 3.10 Thank you for using your friendly neighborhood accumulator! BUILD SUCCESSFUL (total time: 19 seconds)

Explanation / Answer

please check this..

class Alu{
   public static void main(String[] aa) {
       scanner scan=new scanner(System.in);
       char chr;
       String sf;
       sf=scan.next();
       chr=sf.charAt(0);
       while(chr=="="){
       System.out.println("Please Enter operand/operator");
       sf=scan.next();
       chr=sf.charAt(0);

       }
  
   }
}