Write program on memory calculator

Assignment Help JAVA Programming
Reference no: EM131590593

Homework on memory calculator.

Write code but need to rework with separate class from the Test or Driver or Demo class that contains the main method. please help fix it.

import java.util.Scanner;

public class MemoryCalculator {
private double currentValue;
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
int menu = 0;
double operand2 = 0;

MemoryCalculator calculator = new MemoryCalculator();

do {
System.out.println("The current value is "
+ calculator.currentValue);

menu = MemoryCalculator.displayMenu();

switch(menu){
case 1:
operand2 = getOperand("What is the second number?: ");
calculator.add(operand2);
break;

case 2:
operand2 = getOperand("What is the second number?: ");
calculator.subtract(operand2);
break;

case 3:
operand2 = getOperand("What is the second number?: ");
calculator.multiply(operand2);
break;

case 4:
operand2 = getOperand("What is the second number?: ");
calculator.divide(operand2);
break;

case 5:
calculator.clear();
break;

}
} while (menu != 6);

}


//* display menu
public static int displayMenu() {

System.out.println("nMenu:");
System.out.println("1. Add");
System.out.println("2. Subtract");
System.out.println("3. Multiply");
System.out.println("4. Divide");
System.out.println("5. Clear");
System.out.println("6. Quitn");
System.out.print("What would you like to do? ");
int menuInput = input.nextInt();

if (menuInput 6) {
System.out.println( menuInput
+ " wasn't one of the options.n");
menuInput = 0;
}
else if (menuInput == 6) {
System.out.println("Goodbye!");
}

return menuInput;
}

public static double getOperand(String prompt) {
System.out.print(prompt);
double operand = input.nextDouble();
return operand;
}

public double getCurrentValue() {
return currentValue;
}

public void setCurrentValue(double currentValue) {
this.currentValue = currentValue;
}

// add
public void add(double operand2) {
currentValue += operand2;
}

// subtract
public void subtract(double operand2) {
currentValue -= operand2;
}

// multiply
public void multiply(double operand2) {
currentValue *= operand2;
}

// divide
public void divide(double operand2) {
if (operand2 > 0) {
currentValue /= operand2;

}
else{
currentValue = Double.NaN;
}
}

// clear
public void clear() {
currentValue = 0;
}

}

Reference no: EM131590593

Questions Cloud

Andalusian variety of chicken : The so-called "blue" (really gray) Andalusian variety of chicken is produced by a cross between the black and white varieties.
Decisions of the united states supreme court : Write a paper explaining the issue, your proposed outcome, the social policy implications of your solution, and the research that supports your outcome
Tongue-rolling woman with detached earlobes : So, suppose a tongue-rolling woman with detached earlobes marries a man who has attached earlobes and can't roll his tongue.
Determine where you will get the hardware : Construct a document in three parts. Determine where you will get the hardware. Present the document in a way that is appropriate for the workplace.
Write program on memory calculator : Write code but need to rework with separate class from the Test or Driver or Demo class that contains the main method. please help fix it.
What is the current p-e ratio foe axr : Company AXR had sales revenues of $94 million last year. What is the current P/E ratio foe AXR?
Information security data analytics and encryption algorithm : Big data and data analytics are hot topics that are frequently in the media these days. Much of the application of these mathematical concepts.
Process to control microbial growth : How are they separated and segregated into two daughter cells? What antibiotics exploit this process to control microbial growth?
Identify the hardware that will be needed : Clearly identify and define your product. Identify the hardware that will be needed. Determine where to get the hardware and how much it will cost.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd