d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Do-while Loop Problem...? > 'do' Section Marked As Error In Eclipse
12Next
Add Reply New Topic New Poll
Member
Posts: 5
Joined: Oct 28 2012
Gold: 0.00
Oct 28 2012 06:06pm
While this is pulled up in Eclipse, it's marked as a syntax error at the line with do {.

Code
import java.text.DecimalFormat;
import java.util.Scanner;
import javax.swing.JOptionPane;


public class SavingsAccount {

/**
 * Program by (myname)
 */

 double balance=0, annualIntRate=0, depositAmt, withdrawnAmt, monthlyInt, balancePlusInt;
 int moCount=0;
 double totalInterest=0, totalDeposits=0, totalWithdrawals=0;
 String input, input2, input3;
 char repeat = 'Y';
   
 
 public SavingsAccount(String input, String input2)
 {
 input = JOptionPane.showInputDialog("What is your account's starting balance?");
 
 balance = Double.parseDouble(input);
 
 input2 = JOptionPane.showInputDialog("What is the annual interest rate?");
 
 annualIntRate = Double.parseDouble(input2);
 
 }
 
do {
 public void deposit (String input3)
 {
  input3 = JOptionPane.showInputDialog("Enter deposit for Month:");
 
  depositAmt = Double.parseDouble(input3);
 
  balance += depositAmt;
 
  totalDeposits = totalDeposits + depositAmt;
 }

 public void withdrawal (String input4)
 {
  input4 = JOptionPane.showInputDialog("Enter withdrawal for Month:");
 
  withdrawnAmt = Double.parseDouble(input4);
 
  balance -= withdrawnAmt;
 
  totalWithdrawals = totalWithdrawals + withdrawnAmt;
 }
 
 public void calcMonthlyInt (double monthlyInt)
 {
  monthlyInt = annualIntRate/12;
 }

 public void addMonthlyInt (double balancePlusInt)
 {
  balancePlusInt = monthlyInt * balance;
 
  balance += balancePlusInt;
 
  totalInterest = totalInterest + balancePlusInt;
 }

 
 
 public double getFinalCalculations()
 {
  JOptionPane.showMessageDialog(null, "Your balance is" + balance);
  JOptionPane.showMessageDialog(null, "Your total deposit amount is" + totalDeposits);
  JOptionPane.showMessageDialog(null, "Your total withdrawals are" + totalWithdrawals);
  JOptionPane.showMessageDialog(null, "Your total interest is" + totalInterest);
 }

 
 int y = JOptionPane.showConfirmDialog(
      null,
      "Calculate month" + moCount +"?",
      null, JOptionPane.YES_NO_OPTION);{  
 
 moCount++;
 
 while(y != JOptionPane.NO_OPTION);
 
 
      }}
 




Why is it showing up as an error?

Also, how do I include the system exit thing with the no option? Will it exit anyway if 'no' is selected?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 28 2012 06:08pm
you dont declare methods inside a loop; you invoke the methods.

Quote
do {
public void deposit (String input3)
{
Member
Posts: 5
Joined: Oct 28 2012
Gold: 0.00
Oct 28 2012 07:06pm
Quote (carteblanche @ Oct 28 2012 07:08pm)
you dont declare methods inside a loop; you invoke the methods.


So would it be:

--here's all the methods---

--begin loop--
--call methods---


.....?
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Oct 28 2012 07:21pm
Quote (ermahjav @ Oct 28 2012 08:06pm)
So would it be:

--here's all the methods---

--begin loop--
--call methods---


.....?


what was your inspiration for trying to put methods inside of a loop?
Member
Posts: 5
Joined: Oct 28 2012
Gold: 0.00
Oct 28 2012 07:28pm
Quote (Eep @ Oct 28 2012 08:21pm)
what was your inspiration for trying to put methods inside of a loop?


Honestly, no clue. I can't figure out how this all goes together, hence asking. I've got all the info in the program that I need to have in there, but I don't know how to get the whole looping part tied into it properly. I'm drawing a total blank and everything I find while searching just doesn't make sense.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 28 2012 07:35pm
Quote (ermahjav @ Oct 28 2012 09:06pm)
So would it be:

--here's all the methods---

--begin loop--
--call methods---


.....?


loops go inside methods
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Oct 28 2012 11:08pm
Quote (Eep @ Oct 28 2012 09:21pm)
what was your inspiration for trying to put methods inside of a loop?


TALKING LIKE HE KNEW WAHT METHODS WERE
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Oct 28 2012 11:39pm
Quote (AbDuCt @ Oct 29 2012 12:08am)
TALKING LIKE HE KNEW WAHT METHODS WERE


too many words similar to other words in cs
Member
Posts: 4,605
Joined: Sep 15 2011
Gold: 9,464.00
Oct 29 2012 12:20am
This thread reminds me of a class at my university that fulfilled some kind of mathematical/programming requirement for the finance/business majors. It was the butt of the jokes of all the CS majors because it was basically this super easy and simple class (taught in Java and super dumbed down for the audience), but it was a notoriously difficult class for the finance majors. My friends and I often joked about becoming an LA (lab assistant) for the class just so we could either hit on the girls (lol) or gather stories of really, really stupid programming questions and/or all the different ways someone could fuck up on "hello world".

This post was edited by irimi on Oct 29 2012 12:23am
Member
Posts: 9
Joined: Nov 7 2012
Gold: 0.00
Nov 8 2012 01:43pm
A do while loop is different from a LAMBDA expression which is what I think you were trying to use (It's unavailable in the JDK until version 8 sadly)

http://msdn.microsoft.com/en-us/library/bb397687.aspx
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll