Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java - Calculator

joyciita23
joyciita23 


I need help with this code... For this problem, follow the instructions for Program #5 in Chapter 3 Exercises of your textbook. Remember the following points: Create an application that contains a method that computes the final price for a sales transaction and returns that value to a calling method. The method requires three arguments: product price, salesperson commission rate, and customer discount rate. A product's final price is the original price plus the commission amount minus the discount amount; the customer discount is taken as a percentage of the total price after the salesperson commission has been added to the original price. Write a main() method that prompts the user for the price of an item, the salesperson's commission expressed as a percentage, and the customer discount expressed as a percentage, and that then passes the values to the method. Save the application as Calculator.java I did it myself here...but I do not want to use the JOptionPane I want it to be in System.out.println form but everytime I try to change it, it gives me an error... import javax.swing.*; public class Calculator { public double calculation(double price, double commission, double discount){ double commissionAmt = price*commission/100; double priceWithCommission = price+commissionAmt; double discountAmt = priceWithCommission*discount /100; return price+commissionAmt-discountAmt; } public static void main(String[] args) { double price = Double.parseDouble (JOptionPane.showInputDialog ("Enter the item price")); double commission = Double.parseDouble ( JOptionPane.showInputDialog ("Enter the salesman commission(%)")); //salesperson commison in % double discount = Double.parseDouble (JOptionPane.showInputDialog ("Enter the customer discount(%)")); // customer discount in % Calculator c = new Calculator(); double finalPrice = c.calculation (price, commission,discount); String msg = "ITEM PRICE: "+price+ "\nCommission: "+commission+"%"+ "\nDiscount: "+discount+"%"+ "\n-------------- ------------------"+ "\nFINAL PRICE: "+finalPrice; JOptionPane.showMessageDialog (null,msg); } } Attachments
Tags Clarifications

Answers

Java - Calculator - System out

dickersonka
dickersonka 



Attached are the updates using System.out instead of JOptionPane

The old lines are still there but commented out so you can see the difference.
Attachments
Calculator.java (1 K) Download Preview
System.out.print("Enter the salesman commission(%): "); double commission = Double.parseDouble ( input.nextLine()); //salesperson commison in % System.out.print("Enter the customer discount(%): "); double discount = Double.parseDouble (input.nextLine()); // customer discount in % Calculator c = new Calculator(); double finalPrice = c.calculation (price, commission,discount); String

Screenshots
Purchase Answer