Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AJ Muni

macrumors 65816
Original poster
Aug 4, 2005
1,153
24
Miami
Hey guys, I just started taking computer programming 1, and our first assignment is due tonight at midnight. I had missed last week because my mom had major surgery, and my freakin book hasn't arrived yet from half.com. I thought that our first assignment was going to be quite easy, some string literals, system output, etc. but when I went to see it, I'm real confused about it. I was wondering if any of you can point me in the right direction on how to start this assignment. Here it is:

assignment 1 said:
COP 2250 Assignment 1: Basic I/O and Arithmetic
Andrew Allen Due: Midnight of Monday, September 17

Assignment 1.

Write a program to calculate the updated balance of a bank account after performing the following account transactions:
a deposit,
a withdrawal,
addition of interest.

Specific Requirements


Your program must consist of a single class named Assignment_1 and containing a single method, main().
Your program should declare and use the following variables…


double balance; // current balance for account
double depositAmount; // amount to be deposited to account
double withdrawalAmount; // amount to be withdrawn from account
double interestRate ; // e.g 5.0 for 5% interest rate
double interestAmount;// calculated interest

Use the Scanner class to get input from the user for:
balance, depositAmount, withdrawalAmount, interestRate

For example:

Scanner input = new Scanner(System.in);
System.out.print("Please enter current balance ");
balance = input.nextDouble();

For each input, display the value entered, then calculate and display the new balance. Displays should have appropriate messages.

I'm not looking for someone to give me the complete assignment, just to help me start. I've been reading up on java the past 3 hours so I kinda know the lingo and what not. I'd rather turn something in, even if it's not right, rather than not doing it and getting a zero.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Programming is done bits by bits, so first make sure you have the basics:

our program must consist of a single class named Assignment_1 and containing a single method, main()

Do you have this yet?

Also, what are you using for development? The command line? Xcode? Eclipse?
 

AJ Muni

macrumors 65816
Original poster
Aug 4, 2005
1,153
24
Miami
Programming is done bits by bits, so first make sure you have the basics:



Do you have this yet?

Also, what are you using for development? The command line? Xcode? Eclipse?

Sorry i wasnt too specific. I'm using JCreator over on parallels. I'm assuming that the class has the variables the professor pointed out, and I dont have the main method. This is two seperate java files right? one called assignment_1.java, and another one with the main method? I'm sure i sound like a complete idiot, but god you have no idea how much i regret missing class last week, because i'm sure he went over how to start the assignment.
 

AJ Muni

macrumors 65816
Original poster
Aug 4, 2005
1,153
24
Miami
Everything will be in one file ... Assignment_1.java

Code:
public class Assignment_1
{
  public static void main(String args[])
  {
    // your code goes here.
  }
}

ohhhh..ok thank you so much chris. I dont know why i was thinking it was 2 files..im thinking on the basis of a bank class, and then a bank tester, to test the class. thank you again.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
ohhhh..ok thank you so much chris. I dont know why i was thinking it was 2 files..im thinking on the basis of a bank class, and then a bank tester, to test the class. thank you again.

Based off the instructions and sample code, here's how I'd set it up:

Code:
public class Assignment_1
{
  public static void main(String args[])
  {
    double balance;           // current balance for account
    double depositAmount;     // amount to be deposited to account
    double withdrawalAmount;  // amount to be withdrawn from account
    double interestRate;      // e.g 5.0 for 5% interest rate
    double interestAmount;    // calculated interest
    
    Scanner input = new Scanner(System.in);
    System.out.print("Please enter current balance ");
    balance = input.nextDouble();
  }
}

That *should* compile, to get you going.

Disclaimer: I have only done about 10 minutes of Java in my life :p
 

AJ Muni

macrumors 65816
Original poster
Aug 4, 2005
1,153
24
Miami
Based off the instructions and sample code, here's how I'd set it up:

Code:
public class Assignment_1
{
  public static void main(String args[])
  {
    double balance;           // current balance for account
    double depositAmount;     // amount to be deposited to account
    double withdrawalAmount;  // amount to be withdrawn from account
    double interestRate;      // e.g 5.0 for 5% interest rate
    double interestAmount;    // calculated interest
    
    Scanner input = new Scanner(System.in);
    System.out.print("Please enter current balance ");
    balance = input.nextDouble();
  }
}

ok there is what i got so far...and I figured this out before your last post kainjow ;)

Code:
import java.util.Scanner;

public class Assignment_1
{
  public static void main(String args[])
  {
    double balance;   	// current balance for account
	double depositAmount;	// amount to be deposited to account
	double withdrawalAmount; // amount to be withdrawn from account
	double interestRate ;	// e.g 5.0 for 5% interest rate
	double interestAmount;// calculated interest
	
    Scanner input = new Scanner(System.in);
   	
   	System.out.print("Please enter current balance:   ");
   	balance = input.nextDouble();
	
	
   	System.out.print("Please enter deposit amount:   ");
   	depositAmount = input.nextDouble();
	
	
	}
  }

THis is what I get:

Please enter your balance: i enter a number (100) then...
Please enter your deposit amount: i enter another number (100)..

How do I get it to add my initial balance with my deposit amount?

I tried this: System.out.print("Your new balance is: " balance + depositAmount); but that didnt seem to work.. I get an error saying ")" expected...
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
9
USA
You may need to use some try blocks when you go to do some math on the input for it to handle someone entering "money" instead on 150.00. Just a heads up. Not sure if the compiler will complain if you don't have it, I didn't try coding it up.
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
9
USA
THis is what I get:

Please enter your balance: i enter a number (100) then...
Please enter your deposit amount: i enter another number (100)..

How do I get it to add my initial balance with my deposit amount?

I tried this: System.out.print("Your new balance is: " balance + depositAmount); but that didnt seem to work.. I get an error saying ")" expected...

System.out.print("Your new balance is: " + balance + depositAmount);

Check what I bolded above '+'. Read your code a little slower to pick up these small things. Those small typos will always be there.
 

AJ Muni

macrumors 65816
Original poster
Aug 4, 2005
1,153
24
Miami
You may need to use some try blocks when you go to do some math on the input for it to handle someone entering "money" instead on 150.00. Just a heads up. Not sure if the compiler will complain if you don't have it, I didn't try coding it up.

Acutally i figured it out..i just created a new variable called newBalance = balance + depositAmount. I think your right, because when I entered 100 for balance and 100 for depositAmount i get 200.0 I think its because Im going from an int to a double, or vice versa.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.