I am creating an application where the user shall be able to enter the following values:
gross monthly income (before deductions).
estimated monthly tax deducted.
groceries
water and lights
travel costs (including petrol)
cellphone and telephone
other expenses
The user shall be to choose between renting accommodation or buying a property if the the user selects to rents, the user will enter the monthly rental amount
if the user selects to buy a property, the user shall be required to enter the following values for a home loan:
purchase price of property
total deposit
interest rate
number of months to repay
The software shall calculate the monthly home loan repayment for buying a property based of the values that the user entered.
If the monthly home loan repayment is more than a third of the user's gross monthly income, the software shall alert that approval of the home loan is unlikely/
The software shall calculate the available monthly money after all the specified deductions have been made.
The software shall not persist the user data between runs. The data shall only be stored in memory while the software is running.
Please help me out with the code c#.
This should be fairly straight forward, it sounds like the program is supposed to be written entirely in the console which makes things a lot simpler.
Most of the code should use Console.WriteLine(String) and Console.ReadLine().
For example:
double netMonthlyIncome = 0;
Console.WriteLine("Enter gross monthly income:");
double gmi = Double.Parse(Console.ReadLine());
Console.WriteLine("Enter estimated monthly taxes:");
double emt = Double.Parse(Console.ReadLine());
netMonthlyIncome = gmi - emt;
What this code is doing is calling a built-in function to write a string to the console window, and setting up a double variable to hold the result from the console. The ReadLine function will wait for a user to hit enter and will take anything they wrote before enter and return it in a string variable. The Double.Parse() function takes this string and attempts to convert it to a number. The final step is that the gross monthly income variable will have the estimated monthly taxes subtracted from it to a seperate variable, this would be repeated for the other expenses. To go an extra step, you should include some checks to verify the inputs. For example:
double netMonthlyIncome = 0;
Console.WriteLine("Enter gross monthly income:");
String inputText = Console.ReadLine();
while(!Double.TryParse(inputText)) {
Console.WriteLine("That couldn't be interpreted, please re-enter a number:")
inputText = Console.ReadLine();
}
double gmi = Double.Parse(inputText);
In this example, the user would be prompted once to input the gross monthly income, but the TryParse function checks to see if the input is able to be converted to a double, and returns true if it can be. The ! will reverse whatever the result is, so if the TryParse returns true, the ! makes it false and the while() statement is skipped. If the TryParse returns false, the ! makes it true, and the while loop is entered where the user is prompted to re-enter a number, and will continue to be prompted until the TryParse is able to get a number out of it. This is, in some form, good practice to prevent a user from entering something like "Apples" and breaking the program.
After that, you would use similar prompts with new variables to get the cost of groceries, utilities, travel, etc. and use:
netMonthlyIncome = netMonthlyIncome - groceries - utilities - travel - ...;
You'd also use similar prompts to get the loan values, in this example I'll use 'a' as the loan amount, 'r' as the interest, and 'n' as the number of months. The formula should be double monthlyLoanPayment = a * (r(1+r)^n)/((1+r)^n - 1). It's maybe not the most efficient but personally I like to separate out everything to avoid any accidental syntax issues with order of operations.
So, you'd have:
r = r/12; // convert yearly interest to monthly interest
double numerator = r*Math.pow((1+r),n); //this is equivalent to r*(1+r)^n
double denominator = Math.pow(1+r,n) - 1; //this is equivalent to (1+r)^n - 1
double monthlyLoanPayment = a * (numerator/denominator);
if(monthlyLoanPayment >gmi/3) {
Console.WriteLine("This loan will probably get denied");
} else {
Console.WriteLine("This loan will probably get approved");
}
netMonthlyIncome = netMonthlyIncome - netMonthlyLoanPayment;
Console.WriteLine("Money Available each month:");
Console.WriteLine(netMonthlyIncome);
Related
Is there a way to have a paragraph of text get spit out when you have a certain input, from say a google questionnaire?
And make it so you could have say 5 inputs, and it would spit out 5 paragraphs of information, into one document?
For example:
If someone fills out a questionnaire where the first question is year of birth, the tool would spit out the first paragraph with a description of what the year they were born was like.
Second question would be their birth country, the tool would place a paragraph of text about their birth country into the document.
etc etc
Many thanks in advance for any help
It is possible to create documents using a specific criteria based in form responses. I created the following sample script using Google Apps Script so you can get the idea:
function docCreation() {
var ss = SpreadsheetApp.getActive().getSheetByName("Form Responses 1");
var range = ss.getDataRange();
var values = range.getValues().reverse(); //reverses the array to get the last value in the first position
var doc = DocumentApp.create("Testing doc"); // You can change the name to match a username or any other variable instead
switch (getMonth(values[0][1].toString())) {
case 'Aug':
doc.getBody().appendParagraph("This is a sample body for August");
break;
case 'Jul':
doc.getBody().appendParagraph("This is a sample body for July");
break;
}
}
// Second function that returns the month value of the date introduced by the user
// I separated it because it is not that relevant to the main goal
function getMonth(val){
var month = val.split(" ");
return month[1];
}
It is a very simple script that checks if the month of the date introduced by the user is August or July, and if so, it creates a doc with a simple text as paragraph.
The script is bounded to the Google Sheet of the form responses and you can create a trigger so that every time a user fills out the form, the script starts running to create the needed documents. Now as I mentioned, this is just a sample, and the logic and docs format would depend on your specific needs and usage.
References:
Class Body
Create document
I'm trying to insert an adjustment record via the SOAP API using the following code.
Dim NewAdjustment As Adjustment = New Adjustment With {
.ExternalRef = New StringValue With {.Value = "TEST1234"},
.Description = New StringValue With {.Value = "1234TEST"},
.[Date] = New DateTimeValue With {.Value = "12/20/2018"},
.Details = {New AdjustmentDetail With {
.BranchID = New StringValue With {.Value = "PRODWHOLE"},
.InventoryID = New StringValue With {.Value = "18r.5"},
.WarehouseID = New StringValue With {.Value = "RETAIL"},
.Qty = New DecimalValue With {.Value = 100}
}}
}
Dim InsertAdjustment As Adjustment = CType(soapClient.Put(NewAdjustment), Adjustment)
I get an error px.data.pcexception: Error: 'Branch' cannot be empty. Error: 'Post Period' cannot be empty. Error Inserting 'Receipt' record raised at least one error.
I'm guessing I need to fill those values but I'm not sure how to do that. I see them in the table but not the API interface. I'm new to Acumatica, so I'm guessing this is just something I'm missing.
Thanks in advance.
I have never seen the usage of the Date property as [Date], but that does not mean it will not work. The Posting period is defaulted based on the value of the date property. Make sure that the December 2018 posting period is open on the company that you are logged into with the API. I have seen this error from time to time when the accounting department does not open the period in a timely fashion.
The BranchID is defaulted based on the login parameters of the soapClient. One thing to be aware of is that your API login user needs to have permissions to the BranchID being used, or you will definitely get an error about the Branch being invalid.
Depending on the Inventory costing methodology used by your company, Inventory Adjustments might require that they be processed against an inventory Receipt. This can be tricky to figure out what to do, especially if you have never received anything for this Item in a new implementation, and you want to increase inventory levels. For positive Adjustments in your business case, you might want to consider creating Inventory Receipts instead of Adjustments. The entity is very similar to the Adjustments. For negative Adjustments you might want to consider using Inventory Issues which is again, quite similar.
If you decide to use adjustments, you will have to search the Inventory Receipts for an appopriate Receipt number to use when populating the transaction details. One for each line you insert.
I am having a hard time getting a statement to render in SS2, I had found an answer is SS1 and hadn't used it sometime back but it doesn't seem to work in ss2. I am using the SS2 render.statement method but I am getting an "error.SuiteScriptError","name":"UNEXPECTED_ERROR","message":null,"stack":["renderStatement(N/render.js)" I am unclear as to what some of the arguments actually are. the entityid I think is the customer id, the printMode is the pdf enum, the formId I have no idea, it says it wants a number but I don't see internal ids next to the forms in the list like other objects in NetSuite, I have the InternalIds on. StartDate is a date before you want to start pulling in transactions from? Statement date? Todays Date? OpentransactionOnly true. Any help with this is appreciated.
thanks
Many of the parameters in this API call mimic the UI options on the 'Print Individual Statement' page. I've copied some of the field level help there to help explain each setting.
entityId - internal ID of the customer. NOTE: I have had errors in the past which were solved by using parseInt(customer).
printMode - the print mode to render this statement in (eitherrender.PrintMode.HTML or render.PrintMode.PDF)
formId - internal ID of the form to use to print the statement. Leave this option off to use the default statement form.
startDate - If you choose to enter a date, this is the date of the oldest transaction that appears on the statement. If you choose to note enter a date, all transactions in the customer's history appear on the statement.
statementDate - Statement date. The date in this field is the date used to calculate aging and the date that appears on the statement form.
openTransactionsOnly - Select this option to include only open transactions on statements. If you have entered a start date, open transactions from that start date appear. If you have not entered a start date, all open transactions appear. The Show Only Open Transaction option is most useful for statements printed as of your current today date. If you select Show Only Open Transactions and are using a date other that today’s date, you may have balance discrepancies.
Here is an code snippet. It uses the moment.js for calculating the dates of the first and last day of the previous month.
var startDate = format.format({
value: moment().subtract(1, 'months').startOf('month').toDate(),
type: format.Type.DATE
});
var statementDate = format.format({
value: moment().subtract(1, 'months').endOf('month').toDate(),
type: format.Type.DATE
});
var statement = render.statement({
entityId: parseInt(customer),
printMode: render.PrintMode.PDF,
startDate: startDate,
statementDate: statementDate
});
My project is a simple shopping game where the user types in the quantity amount, and the value of the individual prices appears and then a total sum can appear below.
I have managed to create the part of displaying the individual product price but i am confused on how to add the total sum and display correctly at the instance that i defined.
Some info
Actionscript will check for keypress event
sample of code snippet:
if(e.keyCode == 49){ //1
trace("Key Code Pressed: " + e.keyCode);
amount1.text = "1.00"
}
...
var total:Number = amount1+ amount2+amount3+amount4+amount5;
output1.text = String(total);
From the code above, when the user types 1, the price will change to "1.00" on the price instance field (dynamic text type).
Picture below:
A sample of my game running:
Total price should be $13.00 dollars..
Is there any way to make this happen? I believe is it something to do with parseint.
You should be able to string together multiple parseint statements like this:
var total:number = parseint(amount1.text) + parseint(amount2.text) + parseint(amount3.text) + parseint(amount4.text) + parseint(amount5.text);
output1.text = total;
If you go this route, you will need to handle stituations that involve NaN
Here is the documentation on parseint if you haven't already, you should look at it. http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000590.html
For a future project we have been assigned to create a simple concept (inside Magento) that would has to do the following:
A customer has the ability to choose between different shipping methods, one of them being "Ship2Shop", which sends the product to a physical store of choice and the customer has to go an pick it up.
When a customer selects this "ship2shop" shipping method, a certain percentage (eg: 25%) of the total amount has to be paid online (via a pre-defined payment method) and the remaining 75% has to be paid in the physical store when the customer goes and pick up the products he ordered.
How would you go about this?
Idea that we were having is modify the checkout/order session and modify the "grand total" amount (saving the original in a session ofcourse). When the customer is then sent to the external payment processor the "modified grand total" is sent along. Once the customer returns on the magento platform we would modify the order by restoring the original grand total the way it was and updating the total paid and total due amount.
Anyone got any other ideas about this?
EDIT:
After feedback from Anton S below I managed to add an "advance payment total". However Im still having a problem
In the config.xml I have added the following in the tag:
acsystems_advancepayment/total_custom
grand_total
I want my advance payment to show AFTER the grand total, for some reason, magento won't do that...
EDIT2: Collect method
public function collect(Mage_Sales_Model_Quote_Address $address)
{
parent::collect($address);
$quote = $address->getQuote();
$advancePaymentAmount = 0;
$baseAdvancePaymentAmount = 0;
$items = $address->getAllItems();
if (!count($items)) {
$address->setAdvancePaymentAmount($advancePaymentAmount);
$address->setBaseAdvancePaymentAmount($baseAdvancePaymentAmount);
return $this;
}
$address->setBaseAdvancePayment($address->getGrandTotal()*(0.25));
$address->setAdvancePayment($address->getGrandTotal()*(0.25));
$address->setAdvancePaymentAmount($address->getGrandTotal()*(0.25));
$address->setBaseAdvancePaymentAmount($address->getGrandTotal()*(0.25));
$address->setGrandTotal($address->getGrandTotal() - $address->getAdvancePaymentAmount());
$address->setBaseGrandTotal($address->getBaseGrandTotal()-$address->getBaseAdvancePaymentAmount());
return $this;
}
refer to this thread where adding total objects is explained Magento: adding duties/taxes to a quote during review
Basically you should add your own total object based on your shipping method selection, then it will also be shown in totals as separate row and you can show this in every e-mail or place where totals are exposed
public function collect(Mage_Sales_Model_Quote_Address $address)
{
//this is for the loop that you are in when totals are collected
parent::collect($address);
$quote = $address->getQuote();
//variables for your own object context
$advancePaymentAmount = 0;
$baseAdvancePaymentAmount = 0;
$items = $address->getAllItems();
if (!count($items)) {
$address->setAdvancePaymentAmount($advancePaymentAmount);
$address->setBaseAdvancePaymentAmount($baseAdvancePaymentAmount);
return $this;
}
//calculated based on other total object and don't edit other totals inside your own as your calculations would be always false and so would be next total object in the cycle and so on
$baseAdvancePaymentAmount = $address->getBaseGrandTotal()*(0.25);
$advancePaymentAmount = $address->getQuote()->getStore()->convertPrice($baseAdvancePaymentAmount, false);
//this is just for your own object context
$address->setBaseAdvancePaymentAmount($baseAdvancePaymentAmount);
$address->setAdvancePaymentAmount($advancePaymentAmount);
/*
* this is for the loop that you are in when totals are collected and
* those are set to 0 for each totals collecting cycle
*/
$this->_setBaseAmount($baseAdvancePaymentAmount);
$this->_setAmount($advancePaymentAmount);
return $this;
}
Another option is to change the "grand_total" in your payment module, that way the sessions aren't altered..