Java Newbie Help..

Discussion in 'Mac Programming' started by AJ Muni, Sep 17, 2007.

  1. AJ Muni macrumors 65816

    AJ Muni

    Joined:
    Aug 4, 2005
    Location:
    Miami
    #1
    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:

    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.
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    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?
     
  3. AJ Muni thread starter macrumors 65816

    AJ Muni

    Joined:
    Aug 4, 2005
    Location:
    Miami
    #3
    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.
     
  4. ChrisBrightwell macrumors 68020

    ChrisBrightwell

    Joined:
    Apr 5, 2004
    Location:
    Huntsville, AL
    #4
    Everything will be in one file ... Assignment_1.java

    Code:
    public class Assignment_1
    {
      public static void main(String args[])
      {
        // your code goes here.
      }
    }
    
     
  5. AJ Muni thread starter macrumors 65816

    AJ Muni

    Joined:
    Aug 4, 2005
    Location:
    Miami
    #5
    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.
     
  6. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    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
     
  7. AJ Muni thread starter macrumors 65816

    AJ Muni

    Joined:
    Aug 4, 2005
    Location:
    Miami
    #7
    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...
     
  8. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #8
    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.
     
  9. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #9
    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.
     
  10. AJ Muni thread starter macrumors 65816

    AJ Muni

    Joined:
    Aug 4, 2005
    Location:
    Miami
    #10
    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.
     
  11. CANEHDN macrumors 6502a

    CANEHDN

    Joined:
    Dec 12, 2005
    Location:
    Eagle Mountain, UT
    #11
    I doubt he will need try/catch statements here. This is basic programming. That stuff is later on.
     
  12. ChrisBrightwell macrumors 68020

    ChrisBrightwell

    Joined:
    Apr 5, 2004
    Location:
    Huntsville, AL
    #12
    I'd have to pull up the javadoc, but I'm pretty sure that most of the java.io.* calls throw IOException, meaning that you either have to catch it or throw it.
     

Share This Page