A large company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who sells $5000 worth of merchandise in a week receives $200 plus 9% of $5000, or a total of $650. Your program will allow the user to enter item numbers for each item sold by the salesperson for that week, print out the total of each item sold by the salesperson, and the total weekly earnings for that salesperson. The items and values are: Item 1 equals to 5.00, Item 2 equals to 10.00, Item 3 equals to 1.00, Item 4 equals to 25.00. Program should use JOptionPane for all input.
I have some programmed but I only get one input.
--- Update ---
//This is what I have so far
import javax.swing.JOptionPane;
public class KingRocker {
public static void main( String[]args )
{
double gross = 0.0, earnings;
int product = 0, number;
String input;
while( product < 4 ){
product++;
input = JOptionPane.showInputDialog("Enter the number of products sold #" + product + " ");
number = Integer.parseInt( input );
if (product == 1)
gross = gross + number * 5.00;
else if (product == 2)
gross = gross + number * 10.00;
else if (product == 3)
gross = gross + number * 1.00;
else if (product == 4)
gross = gross + number * 25.00;
earnings = 0.09 * gross + 200;
String result = "Week earnings: " + earnings;
JOptionPane.showMessageDialog(null, result, "Sales", JOptionPane.INFORMATION_MESSAGE );
System.exit( -1);
}
}
}
From what I can tell, you are calling System.exit( -1); before you run though the rest of your while loop. Try moving System.exit( -1); outside of the loop.
Try closing the loops here
if (product == 1)
gross = gross + number * 5.00;
else if (product == 2)
gross = gross + number * 10.00;
else if (product == 3)
gross = gross + number * 1.00;
else if (product == 4)
gross = gross + number * 25.00;
}
Doing so will allow the loop to run four times. Giving you what you ask for in the comments.
Related
I'm using (Bahmni with) Odoo-10 and when I press Confirm button in the Sale Order and skip/cancel the Register Payment step, the Total Outstanding amount is displayed as double the actual amount.
Here, the Previous Balance field is taking the amount in the current sale order, and then this value is also getting added with the Net Amount.
When I check the bahmni-erp/bahmni-addons/bahmni_sale/models/sale_order.py, I observe this code under SaleOrder class
prev_outstanding_balance = fields.Monetary(string="Previous Outstanding Balance",
compute=_calculate_balance)
total_outstanding_balance = fields.Monetary(string="Total Outstanding Balance",
compute=_amount_all)
def _calculate_balance(self):
for order in self:
order.prev_outstanding_balance = 0.0
order.total_outstanding_balance = 0.0
total_receivable = order._total_receivable()
order.prev_outstanding_balance = total_receivable
def _amount_all(self):
"""
Compute the total amounts of the SO.
"""
for order in self:
...
order.update({
'amount_untaxed': order.pricelist_id.currency_id.round(amount_untaxed),
'amount_tax': order.pricelist_id.currency_id.round(amount_tax),
'amount_total': amount_total + round_off_amount,
'round_off_amount': round_off_amount,
'total_outstanding_balance': order.prev_outstanding_balance + amount_total + round_off_amount
})
def _total_receivable(self):
receivable = 0.0
if self.partner_id:
self._cr.execute("""SELECT l.partner_id, at.type, SUM(l.debit-l.credit)
FROM account_move_line l
LEFT JOIN account_account a ON (l.account_id=a.id)
LEFT JOIN account_account_type at ON (a.user_type_id=at.id)
WHERE at.type IN ('receivable','payable')
AND l.partner_id = %s
AND l.full_reconcile_id IS NULL
GROUP BY l.partner_id, at.type
""", (self.partner_id.id,))
for pid, type, val in self._cr.fetchall():
if val is None:
val=0
receivable = (type == 'receivable') and val or -val
return receivable
Why it's adding the Net Amount in the current Sale Order to the prev_outstanding_balance?
Please help.
Thanks.
Spain an invoice could have different taxes: IVA 0%, IVA 4%, IVA 10%, IVA 21%. I need to show in a tree view all these taxes as columns, no matter if they are all present in the same invoice. For example:
num invoice | client | base 0 | base 4 | base 10 | base 21 | iva 0 | iva 4 | iva 10 | iva 21 | total amount
What should I do to get the list of available taxes and bases and put them as columns in the tree view and show the respective amount in each row
(if tax applies)?
I'm using OpenERP 7, but I hope you can help me no matter what version you use.
The following code was my solution:
# -*- coding: utf-8 -*-
from openerp import models, fields, api, _
# mapping payment method with its human descriptions
PAYMENT_METHODS = [
('bank_transfer', 'Bank transfer'),
('commerce_cod', 'Bank debit'),
('commerce_sermepa', 'Credit card (POS)'),
('commerce_stripe', 'Credit card'),
('pagamastarde', 'Funded payment'),
('paypal_wps', 'PayPal'),
]
class account_invoice_resume(models.Model):
_name = 'account.invoice.resume'
_inherit = 'account.invoice'
_order = 'date_invoice asc, id asc'
_table = 'account_invoice'
#api.depends('partner_id','partner_id.parent_id')
def _get_partner_parent_name(self):
for invoice in self:
if invoice.partner_id.parent_id:
name = invoice.partner_id.parent_id.name
else:
name = invoice.partner_id.name
invoice.display_name = name
# Sum products amount for each type of tax and base
#api.depends('tax_line.name','tax_line.amount','tax_line.base')
def _specific_tax_amount(self):
for invoice in self:
invoice.tax_base_0 = invoice.tax_base_4 = invoice.tax_base_10 = invoice.tax_base_21 = invoice.tax_iva_4 = invoice.tax_iva_10 = invoice.tax_iva_21 = 0.0
amount_without_taxes = invoice.amount_total # Final total of products without taxes or with tax 0%
if len(invoice.tax_line) > 0:
for line in invoice.tax_line:
_tax = line.name.strip()
amount = line.amount
base = line.base
if _tax in ['21% IVA soportado (bienes corrientes)','IVA 21% (Bienes)','IVA 21% (Servicios)']: # If tax is IVA 21%
invoice.tax_iva_21 += amount
invoice.tax_base_21 += base
amount_without_taxes -= amount + base
elif _tax in ['10% IVA soportado (bienes corrientes)','IVA 10% (Bienes)','IVA 10% (Servicios)']: # If tax is IVA 10%
invoice.tax_iva_10 += amount
invoice.tax_base_10 += base
amount_without_taxes -= amount + base
elif _tax in ['4% IVA soportado (bienes corrientes)','IVA 4% (Bienes)']: # If tax is IVA 4%
invoice.tax_iva_4 += amount
invoice.tax_base_4 += base
amount_without_taxes -= amount + base
elif _tax is None or _tax in ['','IVA 0% Entregas Intracomunitarias exentas','IVA 0% Exportaciones','IVA Soportado exento (operaciones corrientes)']: # If tax is IVA 0%
invoice.tax_base_0 += base
amount_without_taxes -= base
# Sum residual amount of prices without 4%, 10% o r21% taxes to base 0
invoice.tax_base_0 += amount_without_taxes
else:
invoice.tax_base_0 = invoice.amount_total
account_invoices_resume()
Little description of task:
Need to get total of base if we will selling coin_quantity of coin to the market.
By default, this example means, that market is coin+"_"+base. No flip case.
For simplification, there is only one case(action): selling / ask.
python:
def get_depth_price( db_cursor, coin_quantity, coin, market ):
sql_command = "SELECT * FROM '" + market + "' WHERE type=1"
db_cursor.execute( sql_command )
bids = sorted([ i for i in db_cursor.fetchall() ], \
key = lambda k: k[3], reverse = True )
tmp_quantity = float( coin_quantity )
tmp_total = 0
for bid in bids:
if tmp_quantity > bid[4]:
tmp_total += bid[4] * bid[3]
tmp_quantity -= bid[4]
else:
tmp_total += tmp_quantity * bid[3]
tmp_quantity = 0
break
return tmp_total
Where market data looks like:
# echo "SELECT * from 'DOGE_BTC' WHERE type=1
ORDER BY price DESC;" | sqlite3 big.db
6f827564d88ddd0d99a9f976ac384a3f|0|1|5.0e-07|374365.08
1f696fea1270c07d9d4217e47ad40d3c|0|1|4.9e-07|1337443.42857
b9bee0a3bc2d4b241383062f06569b54|0|1|4.8e-07|465618.375
716cb29e0f5fe4742de73302e5b88250|0|1|4.7e-07|197560.659574
3189ed55c60530014892c6a3fce673e8|0|1|4.6e-07|115757.521739
cf19858241fb25de9095160b1704ef44|0|1|4.5e-07|237807.133333
f53642c0e7d5074daaa2b324e82483c5|0|1|4.4e-07|16112.6818182
ee8fb3f5255fb0ef8c157becb6a8c539|0|1|4.3e-07|22581.0697674
### (0)id ----^ (1)self---^ ^ ^-(3)price ^
### (2)type(ask=0/bid=1)-------+ (4)quantity--+
Methinks, that python script - is very very slow thing against sql.
However, I can't create similar on the sql language.
How to replace full function of get_depth_price by sql-query?
How to create on sql similar to if tmp_quantity > bid[4] / then / else ?
I want to count loan amortization, but I have no idea how to compute the payoff date.
I have Loan amount,Interest rate,Monthly paymnet,Loan Start date. From these four values I want to know my Loan Payoff date in iOS.
I count Interest,Monthly Amount like as
double loanAmount = [self.amount doubleValue];
double intRate = [self.rate doubleValue];
double years = [self.durationCount doubleValue];
double r = intRate / 1200;
double n;
if ([self.duration isEqualToString:#"Yearly"])
{
n = years * 12;
}
else
{
n = years;
}
double rPower = pow(1 + r, n);
_monthlyPayment = loanAmount * r * rPower / (rPower - 1);
double annualPayment = _monthlyPayment * 12;
if ([self.duration isEqualToString:#"Yearly"])
{
_totalAmount = annualPayment * years;
}
else
{
_totalAmount = annualPayment;
}
self.InterestPaid=_totalAmount-loanAmount;
Any one can help me?
I'm doing the Euler's Method project to find the sum of prime numbers below 2 million and I'm struggling. Here is the code I'm using. When I calculate the sum below 10 and the sum below 50 I'm getting the right value, but where I'm calculating the sum below 2 million project Euler is saying my solution is incorrect. Any ideas?
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
#autoreleasepool {
int p = 2, d, total;
BOOL isPrime;
total = 0;
NSLog(#"%i ", p);
for ( p = 3; p < 2e6; p += 2){
isPrime = YES;
for ( d = 3; isPrime == YES && d < p; d += 2)
if ( p % d == 0)
isPrime = NO;
if (isPrime == YES){
NSLog(#"%i ", p);
total += p ;}
}
NSLog(#"total = %i", total + 2);
}
return 0;
}
This function sums the primes less than n using the Sieve of Eratosthenes:
function sumPrimes(n)
sum := 0
sieve := makeArray(2..n, True)
for p from 2 to n step 1
if sieve[p]
sum := sum + p
for i from p * p to n step p
sieve[i] := False
return sum
I'll leave it to you to translate to Objective-C with a suitable data type. For n = 2000000, this should run in one or two seconds.
There are a couple of mistakes. The first being that you're overflowing. Use a long instead of an int. The second thing is just a performance boost. Change your for loop from p < 2e6, to p*p <= 2e6. This way you rule out all numbers above the square root of 2e6. Fix those problems and you'll be good to go. Good luck!