Calculator does not work, does not add weekly, monthly or yearly correctly

Hi I am making a calculator where the user inputs his/her income (wages, loans, other) and spending (rent, food, other). I am an if else statement to add up the input fields as the user can input the numbers according to weekly, monthly or yearly. It allos me to run the code but when I input 10 pounds in each of the 3 fields the result is 30 but it should have calculated as 10 * 4.3333333 for each of the three fields.
The if else statement is below;
double totalIncome = num1 + num2 + num3;
double totalSpending = num4 + num5 + num6;
double result = 0;
if (op1.equals("Weekly"))
result = num1 * 4.3333333;
else if (op1.equals("Monthly"))
result = num1;
else if (op1.equals("Yearly"))
result = num1 / 12;
else if
(op2.equals("Weekly"))
result = num2 * 4.3333333;
else if (op2.equals("Monthly"))
result = num2;
else if (op2.equals("Yearly"))
result = num2 / 12;
else if
(op3.equals("Weekly"))
result = num3 * 4.3333333;
else if (op3.equals("Monthly"))
result = num3;
else if (op3.equals("Yearly"))
result = num3 / 12;
TotalIncomeField.setText( "" + totalIncome);
THE WHOLE STATEMENT LOOKS LIKE;
try {
double num1 = Double.parseDouble(LoansField.getText());
double num2 = Double.parseDouble(WagesField.getText());
double num3 = Double.parseDouble(OtherField.getText());
double num4 = Double.parseDouble(RentField.getText());
double num5 = Double.parseDouble(FoodField.getText());
double num6 = Double.parseDouble(OtherField2.getText());
String op1 = (String)LoanComboBox.getSelectedItem();
String op2 = (String)WagesComboBox.getSelectedItem();
String op3 = (String)OtherComboBox.getSelectedItem();
String op4 = (String)RentComboBox.getSelectedItem();
String op5 = (String)FoodComboBox.getSelectedItem();
String op6 = (String)Other2ComboBox.getSelectedItem();
double totalIncome = num1 + num2 + num3;
double totalSpending = num4 + num5 + num6;
double result = 0;
if (op1.equals("Weekly"))
result = num1 * 4.3333333;
else if (op1.equals("Monthly"))
result = num1;
else if (op1.equals("Yearly"))
result = num1 / 12;
else if
(op2.equals("Weekly"))
result = num2 * 4.3333333;
else if (op2.equals("Monthly"))
result = num2;
else if (op2.equals("Yearly"))
result = num2 / 12;
else if
(op3.equals("Weekly"))
result = num3 * 4.3333333;
else if (op3.equals("Monthly"))
result = num3;
else if (op3.equals("Yearly"))
result = num3 / 12;
TotalIncomeField.setText( "" + totalIncome);
if
(op4.equals("Weekly"))
result = num4 * 4.3333333;
else if (op4.equals("Monthly"))
result = num4;
else if (op4.equals("Yearly"))
result = num4 / 12;
else if
(op5.equals("Weekly"))
result = num5 * 4.3333333;
else if (op5.equals("Monthly"))
result = num5;
else if (op5.equals("Yearly"))
result = num5 / 12;
else if
(op6.equals("Weekly"))
result = num6 * 4.3333333;
else if (op6.equals("Monthly"))
result = num6;
else if (op6.equals("Yearly"))
result = num6 / 12;
TotalSpendingField.setText( "" + totalSpending);
} catch (NumberFormatException ex) {
}

First of all, you are calculating 'result', but you don't use it anywhere. Instead you use 'totalIncome' and 'totalSpending', which are calculated without the daily/yearly corrections.
Also, there are some 'else' keywords that should not be there. If (op1.equals("Weekly")) will be true, no other part of the if block for num1, num2, num3 will execute. It should look like this:
     if (op1.equals("Weekly")) {
          num1 *= 4.3333333;
     } else if (op1.equals("Yearly")) {
          num1 /= 12;
     if (op2.equals("Weekly")) {
          num2 *= 4.3333333;
     } else if (op2.equals("Yearly")) {
          num2 /= 12;
     if (op3.equals("Weekly")) {
          num3 *= 4.3333333;
     } else if (op3.equals("Yearly")) {
          num3 /= 12;
     double totalIncome = num1 + num2 + num3;
     TotalIncomeField.setText( "" + totalIncome);Similarly for the spending.

Similar Messages

  • Need working days for a particular month and year

    Hi,
    I need the number of working days for a particular month and year.Saturdays and Sundays are holidays.
    Regards,
    Vignesh

    Try this:
    SQL> var yr NUMBER;
    SQL> exec :yr := 2010;
    PL/SQL procedure successfully completed.
    SQL> with t as (select :yr yr from dual)
      2  SELECT TO_CHAR(dat,'MON-RR'),COUNT(*) FROM
      3  (select TO_DATE('01-JAN-'||yr) + lv dat FROM
      4  (select level - 1 lv,yr from t
      5  connect by level <= TO_DATE('31-DEC-'||yr) - TO_DATE('01-JAN-'||yr) + 1))
      6  WHERE TO_CHAR(Dat,'DY') NOT IN ('SAT','SUN')
      7  GROUP BY TO_CHAR(dat,'MON-RR');
    TO_CHAR(DAT,   COUNT(*)
    APR-10               22
    AUG-10               22
    DEC-10               23
    FEB-10               20
    JAN-10               21
    JUL-10               22
    JUN-10               22
    MAR-10               23
    MAY-10               21
    NOV-10               22
    OCT-10               21
    TO_CHAR(DAT,   COUNT(*)
    SEP-10               22
    12 rows selected.
    SQL> Edited by: AP on Jul 27, 2010 7:54 AM

  • How to get Week,Month and Year details from a date column

    Hi frenz,
    I've a column like tran_date which is a date column..... I need the next week details based on this column and so on...
    I need month and year details as well based on this tran_date column.... can any one tell me how...
    Thanks in advance

    My example for objects:
    create or replace type date_object as object
      centure number,
      year    number,
      month   number,
      day     number,
      hour    number,
      minute  number,
      second  number,
      daypart number,
      week    number,
      constructor function date_object(p_dt date)
        return SELF as result
    create or replace type body date_object is
      constructor function date_object(p_dt date)
        return SELF as result
      as
      begin
        SELF.centure:= trunc(to_char(p_dt,'YYYY')/100);
        SELF.year:=    to_char(p_dt,'YYYY');
        SELF.month:=   to_char(p_dt,'MM');
        SELF.day:=     to_char(p_dt,'DD');
        SELF.hour:=    to_char(p_dt,'HH24');
        SELF.minute:=  to_char(p_dt,'MI');
        SELF.second:=  to_char(p_dt,'SS');
        SELF.daypart:= p_dt-trunc(p_dt,'DD');
        SELF.week:=    to_char(p_dt,'IW');
        return;
      end;
    end;
    select date_object(sysdate),
           date_object(sysdate).year
    from dual;Regards,
    Sayan M.

  • UIX 2.1.21: Date OnBlurValidator automatically add current month or year?

    Would be nice if the OnBlurValidator for a UIX Date field could automatically add a missing month or year.
    e.g. Format dd.mm.yyyy
    When the user enters 01.01. the current year could be added automatically.
    Or when the users only enters 01. the current month and year could be added.
    Would be a nice feature additionally to the already existing lenient-date-formats = true.
    Really great would be to allow entering values like "now" / ".", "yesterday" / "-" or "tomorrow" / "+" that are evaluated to the according dates (of course internationalized).
    Thanks, Markus

    hey mill1640,
    Did you ever get your iPhone to register with iTunes? I just upgraded as well to Snow Leopard, and my my isn't recognized at all also.
    If you did get this resolved, I would appreciate a little suggestion in the right direction.
    Many thanks,
    Josh

  • Regarding Date data in the format of WEEKLY , MONTHLY , QUARTERLY , YEARLY

    hai
    i have one Infoobject(ZDATE) which is created based on the Reference Characteristic(ocalday) and contains data in the YYYYMMDD format.
    I want same date data in weekly , monthly , quarterly and yearly.
    So for this one i need to created ZWEEK , ZMONTH, ZQUARTER and ZYEAR infoobjects by using Reference Characteristics 0calweek , 0calmonth , 0calquarter , 0calyear and i need to write the formula for these InfoObjects for converting & getting data from the ZDATE.
    So please give the formulas for each InfoObject.
    I will assign the points
    bye
    rizwan

    Hi ,
    Try this for month and year in Transfer structure .
    zyear = zdate+0(4).
    zmonth = zdate+4(2).
    For quarter since it will be depend of what kind of fiscal period you are using.. say for ex april - march.
    For Week... whether you want find it based on calender year or fiscal period.
    Regards
    Balaji

  • Calculations do not add up, how to fix in Adobe Acrobat XI Pro

    I'm working on a budget sheet where I would like to have all expenses add up under the "Surplus/Shortage" However when I input the expenses on the expense columns the total "Surplus/Shortage" is one digit off.  Anyone know why that might be?  For the "Surplus/Shortage" field I used the simplified filed notation subtracting the income from expenses.  The "expenses" and "income" field above have their own calculations which I used the "Value is the Sum . . ." method.  Help!

    The Acrobat JavaScript Console (Your best friend for developing Acrobat JavaScript)
    How are you performing your calculations?
    Can you provide a link to the form so we can see how the calculations are being done?

  • Activity Monitor % User and % System do not add up

    Looking at my iMac i7 Activity Monitor/ All Processes/ CPU I find that the % User and % System do not add up to showing the correct % Idle.
    For example, a recent screenshot shows % user = 0.81, the % System = 0.41 and % idle shows 61.25. The CPU usage graph show nothing going on and the Process Name list shows nothing unusual.
    This constantly changes - sometimes the figures add up to 100% but usually the % Idle can be anywhere from 40% to a correct 98 - 99% based on nothing of any consequence running.
    I look at the Activity Monitor on my MacBook and % Idle shows correct addition and a constant 98 - 99%.
    What is going on?
    Thank you.

    This afternoon, it will be an entire week without a crash on my Squeezebox system!
    Totally removing Intego VirusBarrier X6 from my main computer (iMac i7) finally lets me enjoy my music again.
    The main problem is that X6 does not provide feedback as to what it is doing so the user cannot adjust the settings. In other words, no specific message as to what X6 just prevented.
    As a crash can occur anywhere from 10 minutes to 8 hours of play time, hit or miss setting adjustments waste an amazing amount of time. This has been going on for a year with the frequency of crashes escalating.
    I had already entered all my music devices on the Trusted List and had set up rules for all the ports that Squeezebox uses. Still crashed.
    There is no reason why Logitech and/or Intego engineers cannot provide security setup instructions. Unfortunately, Logitech only shows security help for PCs.
    Well the nightmare is over. Amazing what free time I now have.
    The next three paragraphs are for Squeezebox owners and may be of some help if you are having problems:
    A crash (for me) is defined in many ways. The worst crash is when the Squeezebox device shuts off and only pulling the electric plug will revive it. Another crash shows itself when the next song only plays for about 1 second and goes to the next song endlessly until the device shuts off. The Logitech manual says move the device closer to the wireless point when this happens but if they are connected by ethernet cables, this advice is useless. Another crash is when three units are synced and one of them suddenly is no longer in sync and playing a different song.
    Crashes can occur when units are in sync or not in sync. Connected wirelessly or by ethernet. And when a crash occurs, the loud 'crunching' noise that occurs is not kind to the speakers.
    BTW, if some devices are in sync, make sure these devices are connected the same way - either all wirelessly or all by ethernet. If you don't, you will experience sound lags of about 1/2 second. A very annoying echo effect.

  • Daily, Weekly, Monthly, Yearly Backups & Tapes Pooling

    We are running number of servers, and have recently migrated from HP Data Protector to System Center DPM 2012 SP1. I am facing two issues here in which the potential solution is requested. I have created one Protection Group with 1 week retention for Daily
    Backup. Different selections or sources are part of this protection group from different servers.
    1. The issue # 1, is that when I wanted to create more Protection Groups for Weekly, Monthly and Yearly Tape Backups, then I could not select those volumes which are already part of Protection Group that I created for the Daily Backup (probably due to the
    reason that same data source can't be part of multiple protection groups). The data source selection will repeat in all protection groups, so please advise how can I achieve daily, weekly, monthly and yearly backups?
    2. Can I restrict some specific tapes (by allocating through bar codes) to each protection group so that only specific tapes will be used for daily, weekly, monthly and yearly backup? This way the offsite tape movement will also be achieved.
    Need solution on both issues. Please help.

    Hi,
    For item 1. use following PG settings. 
    1) In the protection group, select short term tape and long term protection.
    2) Select daily, only full backup, or Full plus incremental based on your needs.
    3) For the long term goals, select weekly, monthly, and yearly.
    For item 2. - there is no provision in DPM to specify certain tapes for each goal, but if you create a colocation PGset, you can specify how long to write to a tape and control if different goals use the same tapes or not by adjusting expiry tolerance.
    See Colocate data from different protection groups on tape
    http://technet.microsoft.com/en-us/library/jj628040.aspx
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Mike J. [MSFT]
    This posting is provided "AS IS" with no warranties, and confers no rights.

  • Best Practice Table Creation for Multiple Customers, Weekly/Monthly Sales Data in Multiple Fields

    We have an homegrown Access database originally designed in 2000 that now has an SQL back-end.  The database has not yet been converted to a higher format such as Access 2007 since at least 2 users are still on Access 2003.  It is fine if suggestions
    will only work with Access 2007 or higher.
    I'm trying to determine if our database is the best place to do this or if we should look at another solution.  We have thousands of products each with a single identifier.  There are customers who provide us regular sales reporting for what was
    sold in a given time period -- weekly, monthly, quarterly, yearly time periods being most important.  This reporting may or may not include all of our product identifiers.  The reporting is typically based on calendar-defined timing although we have
    some customers who have their own calendars which may not align to a calendar month or calendar year so recording the time period can be helpful.
    Each customer's sales report can contain anything from 1,000-20,000 rows of products for each report.  Each customer report is different and they typically have between 4-30 columns of data for each product; headers are consistently named.  The
    product identifiers included may vary by customer and even within each report for a customer; the data in the product identifier row changes each week.  Headers include a wide variety of data such as overall on hand, overall on order, unsellable on hand,
    returns, on hand information for each location or customer grouping, sell-through units information for each location or customer grouping for that given time period, sell-through dollars information for each location or customer grouping for that given time
    period,  sell-through units information for each location or customer grouping for a cumulative time period (same thing for dollars), warehouse on hands, warehouse on orders, the customer's unique categorization of our product in their system, the customer's
    current status code for that product, and so on.
    Currently all of this data is stored in a multitude of Excel spreadsheets (by customer, division and time period).  Due to overall volume of information and number of Excel sheets, cross-referencing can take considerable time.  Is it possible to
    set-up tables for our largest customers so I can create queries and pivot tables to more quickly look at sales-related information by category, by specific product(s), by partner, by specific products or categories across partners, by specific products or
    categories across specific weeks/months/years, etc.  We do have a separate product table so only the product identifier or a junction table may be needed to pull in additional information from the product table with queries.  We do need to maintain
    the sales reporting information indefinitely.
    I welcome any suggestions, best practice or resources (books, web, etc).
    Many thanks!

    Currently all of this data is stored in a multitude of Excel spreadsheets (by customer, division and time period).  Due to overall volume of information and number of Excel sheets, cross-referencing can take considerable time.  Is it possible to
    set-up tables .....
    I assume you want to migrate to SQL Server.
    Your best course of action is to hire a professional database designer for a short period like a month.
    Once you have the database, you need to hire a professional DBA to move your current data from Access & Excel into the new SQL Server database.
    Finally you have to hire an SSRS professional to design reports for your company.
    It is also beneficial if the above professionals train your staff while building the new RDBMS.
    Certain senior SQL Server professionals may be able to do all 3 functions in one person: db design, database administration/ETL & business intelligence development (reports).
    Kalman Toth Database & OLAP Architect
    SELECT Video Tutorials 4 Hours
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • FM for week in a year

    is there any FM for
    how many weeks in a year and
    how to find the whether the year is leap year or not? and
    how many weeks are in the month ?
    i want the FM

    Hi there. You can use function module hr_99s_interval_between_dates.  Just pass a begin date and an end date, and then you can get the number of days, weeks, months, or years between the two dates.  So you can pass the begin date and end date of a month to get the number of weeks in the month, or the begin date and end date of a year to get the number of days and weeks in the year.  If the number of days is 366 then it is a leap year.  I hope this helps.
    - April King
    Message was edited by:
            April King

  • What do you use to manage daily\weekly\monthly tasks?

    I use Tasks (a clone of Astrid based on the source code) on Android which is synced to Google Tasks. Haven't really ever found anything that's a real replacement to Astrid since Yahoo killed it for no reason.

    Hey guys, just wanted to see what you guys use to manage your tasks on a daily\weekly\monthly\quarterly\yearly basis?We are currently using a product called VIP Task Manager Professional and we really love it. Ithttp://www.taskmanagementsoft.com/products/taskmanagerpro/It is pretty inexpensive and customizable. They offer a full-featured 30-day trial version of VIP Task Manager and there is a Standard edition as well.All the tasks have the ability to be assigned to the whole team or an individual member and can have notes, comments and even documentation attached to the task.There is a calendar feature, it has recurring tasks and you can set up different views too - daily - weekly - all tasks.BTW, our Operations team started using it 10 months ago and we have been using it for about 3 months. Operations just passed an audit with flying...
    This topic first appeared in the Spiceworks Community

  • Report by Day/Week/Month/Year

    Hi All,
    I have the table showing below
    Empid     name     tikcetno     Completed date
    694     anil     10051     23-Jun-09
    695     madhu     10052     23-Jun-09
    694     anil     10053     23-Jun-09
    695     madhu     10054     22-Jun-09
    695     madhu     10055     6-Jan-09
    I need to create the report which will show employee wise count of tickets in a day,week,month and year.                  
    Day: count(tickets) for current date
    Week: count(tickets) for current week
    Month: count(tickets) for current month
    Year: count(tickets) for current year
    I need to show all these four columns in a horizantal table. I am using crystal reports2008. Please help me. ur help would be appreciated.
    Anil.

    Hi,
    create 4 formulas for day, week, Month and year
    for ex, in Day formula
    IF Date Field = CurrentDate then 1 else 0... similarly for other ranges. Create a Group based on employee, and insert a SUM  summary field of these formulas in Group header.
    Hope this will help you.
    Jyothi
    Edited by: Jyothi Yepuri on Jul 13, 2009 3:04 AM

  • Crystal Week, Month and Quartely formula

    Hi experts,
    I have developed a crystal report with date fields. I want a formula that will make the dates range into weeks ,months and Quarter. Please Urgent Help will be appreciated.
    Regards
    Justice

    Hi Justice,
    Dateadd() function and lastfullmonth()  date in 1st qtr , 2nd qtr, etc will answer most of date rage formulas.
    example to get last week data then u can use {date} in lastfullweek()
    or you can arrive last week / month / qtr / year date using dateadd()
    dateadd('w',-1,{date})
    Thanks,
    Sastry

  • Magic mouse double click not operating. With iMac 24" and 10.6.8 bluetooth cannot discover the mouse and spins for ever, but mouse was working OK until 2 weeks ago. Now double click does not work, have to go to menu to open messages etc.. A nuisance.

    Magic mouse is not discovered by bluethooth software, but it worked OK until 2 weeks ago (10.6.8 and iMac 24). Now the double clik does not open messages, I must go to the file menu to do it. A nuisance. Closing a file takes exactly 2 or 3 seconds! Any idea? Mouse and batteries are OK and checked by retailer. Please help.

    Also using iMac 10.6.8
    My magic mouse works ok but I am getting the same message from Mouse prefs that no mouse is “discovered” and the progress gear spins forever. For the time being, at least, my mouse functions as expected.
    I have trashed mouse prefs and rebooted, but that did not solve the problem.

  • My program does not work properly. I run the program but it is not capable of adding any of my ebooks and when I connect my ereader, it recognises the device but  it does not add any ebook either.  I uninstalled the program and reinstalled again but nothi

    my program does not work properly. I run the program but it is not capable of adding any of my ebooks and when I connect my ereader, it recognises the device but  it does not add any ebook either.
    I uninstalled the program and reinstalled again but nothing gone better-
    What should I do?
    Best regards

    Do you have Logitech gaming software installed on the PC? If so, perhaps try the suggestion from the following post:
    Re: Everytime I close Itunes it loads back up

Maybe you are looking for

  • Error while checking the flow of bpel process in bpel console

    Hi Experts I have created one bpel process which invokes task manager for approving or rejecting the leave request. I ve successfully deployed the bpel process and also able to test approve or reject the leave request . But i am facing one error when

  • Problem in accessing Web Services developed using JDeveloper 10.1.3

    We have developed J2EE 1.4 JAX RPC Web Services using Jdeveloper 10.1.3. I take the WSDL document generated by JDev and created Web Proxy for that WSDL. I have developed the Swing Client for accessing the Web Service and when i tried to run from JDev

  • Regarding Program SAPRCKMZ

    Hi, In program SAPRCKMZ, while executing material and plant are obligatory fields, so my requirement was to copy this program into ZSAPRCKMZ and then remove the obigatory for material as the user wants details only based on plant. So when i copied an

  • Use of Variable - Refreshing the Queries in Workbook

    Hi All, I have a workbook which contains 5 Queries. All these queries uses the same variable. While I am refreshing all the  queries in the workbook, it pops-up the variable input screen 5 times. Here I just want the variable screen appear to be once

  • Mail & AOL

    I am actually posting this for my mom... She switched from PC to Macbook late last year. Ever since then, when she opens Mail, which is setup for her AOL account, several messages keep resending themselves until she Quits Mail (does not have to force