Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7745861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:07:47+00:00 2026-06-01T10:07:47+00:00

The code is-create a calculate class with calcTotal, calcSalesTax, and calcSubTotal methods inside. The

  • 0

The code is-create a calculate class with calcTotal, calcSalesTax, and calcSubTotal methods inside. The user should be prompted to enter in a quantity and price and the tax is 0.7. I need to call this class in Main and then output the subtotal, tax, and total.

So far this is what I have in the calulator class

package com.Nick.Calculator;

public class Calculator {
    public double calcSubTotal( double amount, double qty){
        double subTotal;
        subTotal=qty*amount;
        return subTotal;
    }

    public static double calcSalesTax(double subTotal, double taxAmount){
        double tax=0.7;
        taxAmount=subTotal*tax;
        return taxAmount;
    }

    public static double calcTotal(double subTotal, double taxAmount){
        double total;
        total=subTotal+taxAmount;
        return total;
    }
}

Does anything else need to go in this class, or can I prompt the user in main, and how to I call these functions correctly in Main? Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:07:49+00:00Added an answer on June 1, 2026 at 10:07 am

    That class looks fine, I would keep that logic separate from any user prompts. The quickest way will be to prompt the user in your main. In your main instantiate a new Calculator class:

    //beginning of main, prompt user and capture input feed into below lines
    Calculator taxCalc = new Calculator();
    double subTotal = taxCalc.calcSubTotal(amount, qty);
    double taxAmount = Calculator.calcSalesTax(subTotal, taxAmount);
    //... you should get the idea from here, print the result back to the user
    

    Few observations tho, why is one of your methods in Calculator non-static and the rest static? I would make none of them static as it will be easier to write a test for them. Or some may argue the logic is soo simple static would be fine. Your call but go one way or the other. Also in your calcSalesTax call you set your result to a parameter that is passed in. This is generally bad practice and I would either just return the value directly or make a new object for it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create some class that can calculate absolute or relative time period.
I created the following code to calculate the duration between two timestamps which can
I have a code: CREATE TABLE IF NOT EXISTS Person ( name varchar(24) ...
I use following code: Create a retry policy, when error, retry after 1 second,
I have the following test-code: CREATE TABLE #Foo (Foo int) INSERT INTO #Foo SELECT
Why, this code create 2 the same columns in grid (Color and Color). How
Does nHibernate create code that has all the details of the column? I know
I have code to create another row (div with inputs) on a button click.
In my code i create a HyperLinkField object. Depending on a database field value,
Below is sample code to create a radio button element with Yes/No options in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.