Creating complex calculator application

Assignment Help JAVA Programming
Reference no: EM131590521

(1) Create a project using your name "johs8972"
  That will be your "main" class (since it's the class that has this
o public static void main(String[] args)
  From here on, I'll refer to that as the "main" class.
(2) Use main_class.txt
  Copy the contents of main_class.txt into your main class. (SECOND PAGE)
  The code will not compile, until you do finish step (4)
(3) Create a class named Helper
  Its purpose is to hold some methods to help you deal with input and numbers.
(4) Move methods into Helper
  Move these methods from your main class into the Helper class.
o addValues
o subtractValues
o multiplyValues
o divideValues
o getInput
  You may have to import a package so it compiles without error
  Replace all the private static with public
  At this point, your code should compile and run
(5) Create the moduloValues method
  In Helper create a method named moduloValues to do the modulo operation (%)
(6) Use moduloValues
  In your main class, use moduloValues in the same way that the other operations are used
  The operation symbol will be: %
  Don't forget to change the operation prompt so the user knows about "%"
(7) Comments and Formatting
  Make sure you have the standard header comment in each .java file
  Add comments throughout the code
  Ensure your code is formatted by hitting Alt+Shift+F

main_class.txt
 
  /*
  * This is the code that you will put into your main class
  * And delete this comment block afterward
  */
 
  public static void main(String[] args) {
  Helper helper = new Helper();
  String operandOne = helper.getInput("Enter a numeric value: ");
  String operandTwo = helper.getInput("Enter a numeric value: ");
  String operation = helper.getInput("Choose an operation (+ - * /):");
 
  double result = 0;
 
  try {
  switch (operation) {
  case "+":
  result = helper.addValues(operandOne, operandTwo);
  break;
  case "-":
  result = helper.subtractValues(operandOne, operandTwo);
  break;
  case "*":
  result = helper.multiplyValues(operandOne, operandTwo);
  break;
  case "/":
  result = helper.divideValues(operandOne, operandTwo);
  break;
  default:
  System.out.println("Unrecognized operation!");
  return;
  }
 
  System.out.println("The answer is " + result);
 
  } catch (Exception e) {
  System.out.println("Number formatting exception " + e.getMessage());
  }
  }
 
  private static double addValues(String operandOne, String operandTwo) {
  double d1 = Double.parseDouble(operandOne);
  double d2 = Double.parseDouble(operandTwo);
  return d1 + d2;
  }
 
  private static double subtractValues(String operandOne, String operandTwo) {
  double d1 = Double.parseDouble(operandOne);
  double d2 = Double.parseDouble(operandTwo);
  return d1 - d2;
  }
 
  private static double multiplyValues(String operandOne, String operandTwo) {
  double d1 = Double.parseDouble(operandOne);
  double d2 = Double.parseDouble(operandTwo);
  return d1 * d2;
  }
 
  private static double divideValues(String operandOne, String operandTwo) {
  double d1 = Double.parseDouble(operandOne);
  double d2 = Double.parseDouble(operandTwo);
  return d1 / d2;
  }
 
  private static String getInput(String prompt) {
  System.out.print(prompt);
  Scanner sc = new Scanner(System.in);
  return sc.nextLine();
  }

Reference no: EM131590521

Questions Cloud

What are the essential functions of our body : What are the essential functions of our body that will be affected by a lack of fat in our diet?
What will be shown in the message box : Consider the following program statement - What will be shown in the message box?
Define false positives and false negatives : What is meant by selective incapacitation. What are some of the eligibility requirements of prospective candidates for diversion
Articles on managerial issues of a networked organization : Research at least two articles on the topic of managerial issues of a networked organization.
Creating complex calculator application : Creating complex calculator application
After-tax equivalent annual worth of investment : What is the after-tax equivalent annual worth of this investment over the five year period which ends with the sale of the machine?
Discuss about the pathophysiology : The following outlines what should be included in the extended SOAP note:Disease Background.
External factors exerting influences on the organization : Workplace reengineering, reorganization, and redesign are responses to internal and external factors exerting influences on the organization .
Discuss methods of preventing prejudicial pretrial publicity : Discuss the methods of preventing prejudicial pretrial publicity. Are there recent examples of celebrated cases where prejudicial pretrial

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