2 Replies - 3724 Views - Last Post: 27 February 2009 - 10:20 PM Rate Topic: -----

#1 burning120  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-February 09

Java help needed

Posted 26 February 2009 - 07:52 PM

i got this assignment from my teacher and i just don't know how to start out. and i am struggling with understanding what the assignment wants overall.

this is my assignment that i have.
Create a class SavingsAccount . Use a static class variable to store the annualInterestRate for each of the savers. Each object of the class contains a private instance variable savingsBalance indicating the amount save currently has on deposit. Provide method calculateMonthlyInterest to calculate the monthly interest by multiplying the balance by annualInterestRate divided by 12; this interest should be added to savingsBalance. Provde a static method modifyInterestRate that sets the annualInterestRate to a new value. Write a driver program to test the class SavingsAccount. Instantiate two different savingsAccount objects, saver1 and saver2 with balances of $2000.00 and $3000.00, respectively. Set annualInterestRate to 4% then calculate the monthly interest and print the new balances for each of the savers. Then set the annualInterestRate to 5% and calculate the next months interest and print the new balances or each of the savers.
Write another class SpecialSavings that extends SavingsAccount to pay interest of 10% on accounts that have balances that exceed 10K. Also provide methods to deposit and take money out of savings account. Write a driver program to test the class SpecialSavings. Instantiate two different SavingAccount objects saver1 and saver2 with a balance of 2000.00 and 3000.00 Make a few deposits and withdrawls and show balance.
Include a scanner class to enter different deposit and withdraw amounts and display current interest rate and balance.

Is This A Good Question/Topic? 0
  • +

Replies To: Java help needed

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Java help needed

Posted 26 February 2009 - 07:57 PM

Please use more significant names in your topic title: "Java help" is kind of useless in a Java forum devoted to help Java programmers.

"Coding saving account assignment" would have been a more significant topic name

but, despite that we wont do your homework and:

[rules][/rules]

Happy coding

This post has been edited by pbl: 26 February 2009 - 07:59 PM

Was This Post Helpful? 0
  • +
  • -

#3 chaos386  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 28
  • Joined: 27-February 09

Re: Java help needed

Posted 27 February 2009 - 10:20 PM

mmmmmmmmmm i dont know but if i have to go about this i would start by braking down what is asked for then i would start programming small bits at a time name soming like this o this is by no mean "strong" code you will have to do alot of user testing but other then that this should be all you need to start with
first class

//from the fourm http://www.dreamincode.net/forums/showtopic89369.htm
//Created By Chaos386

/*i got this assignment from my teacher and i just don't know how to start out. and i am struggling with understanding 
 *what the assignment wants overall.

this is my assignment that i have. 
1)Create a class SavingsAccount . 
2) Use a static class variable to store the annualInterestRate for each of the savers.
 
3)Each object of the class contains a private instance variable savingsBalance indicating the amount save currently has 
on deposit. 

Provide method calculateMonthlyInterest to calculate the monthly interest by multiplying the balance by 
annualInterestRate divided by 12; 

this interest should be added to savingsBalance. 

*/
package cahos386.SavingsAccount;

public class SavingsAccount{
	public  double savingsBalance = 0.0;
	public  static double annualInterestRate = 0.0;
	public  double  monthlyInterest = 0.0;
	
	
	
	public SavingsAccount(){
		savingsBalance = 0;	  //start money in accont
		annualInterestRate = 0; // rate of interest
		
	}
	
	public SavingsAccount(double x,double y){ //contruder to set up the acconts
		
		savingsBalance = x;	  //start money in accont
		annualInterestRate = y; // rate of interest
		
	}

public double calculateMonthlyInterest(){ //calculate the monthly interest by multiplying the balance by annualInterestRate divided by 12
		
	 
		
		monthlyInterest =  savingsBalance * annualInterestRate / 12;
		System.out.println(monthlyInterest);
		
	return monthlyInterest;	
	

}

		public static void modifyInterestRate(double x){ //Provde a static method modifyInterestRate that sets the annualInterestRate to a new value. 
	
					annualInterestRate = x;
					return;
				}
	
		public  void showAccont(){ //this just shows you the vars in the command promt
	 
						System.out.println("Current Balance:			  "+ savingsBalance);
						System.out.println("Your Current Interest Rate:   "+annualInterestRate);
		
		monthlyInterest =  savingsBalance * annualInterestRate / 12; //do the interestrate cal
		
						System.out.println("Monthly Interest:			 " + monthlyInterest);
						System.out.println("Thank you for using Chaos386 banking;)");
						System.out.println("-------------------------------------------------");
	
	
	return;
	}

}


class 2
//coded by chaos386 
/*Write a driver program to test the class SavingsAccount. 

Instantiate two 
different savingsAccount objects, saver1 and saver2 with balances of $2000.00 and $3000.00, respectively. Set annualInterestRate
 to 4% then calculate the monthly interest and print the new balances for each of the savers. Then set the annualInterestRate to 5% 
 and calculate the next months interest and print the new balances or each of the savers.
*/

package cahos386.SavingsAccount;

public class AccountSavingsDriver{

 
			static SavingsAccount saver1 = new SavingsAccount(2000.00, .04);	//saver1 and saver2 with balances of $2000.00 and $3000.00, respectively.
			static SavingsAccount saver2 = new SavingsAccount(3000.00, .04);
			
		
	
	public static void main(String arg[]){
		
			
		AccountSavingsDriver asd = new AccountSavingsDriver();
		
		System.out.println("Saver Accont 1");
		saver1.showAccont();
		
		saver1.modifyInterestRate(.05);	
		System.out.println("Saver Accont 1 with 5% interesset");
		saver1.showAccont();
					
			System.out.println("Saver Accont 2");
		saver2.showAccont();
		saver2.modifyInterestRate(.05);
		System.out.println("Saver Accont 2 with 5% interesset");
		saver2.showAccont();
	} //end main
}//end AccountSavingsDriver class


class3
/*Write another class SpecialSavings that extends SavingsAccount to pay interest of 10% on accounts that have balances that exceed 10K.
 *
  Also provide methods to deposit and take money out of savings account.  
*/

package cahos386.SavingsAccount;
import cahos386.SavingsAccount.*;

public class SpecialSavings extends SavingsAccount{

		
		public void deposit(String x){
			
			double aDouble = Double.parseDouble(x); //coverts string to double

			savingsBalance = savingsBalance + aDouble; //adds to balance
			
			if(savingsBalance>10000){
	
			tenK();	//runns the method tenK
			}else{
					
		
			}
			
				return;
		}
		public void withdrawls(String y){
			
			double aDouble = Double.parseDouble(y); //coverts string to double
			
			if(savingsBalance>10000){
				savingsBalance = savingsBalance - aDouble;
				if(savingsBalance<100000){
					notTenK();
					System.out.println("----------------------------------");
					showAccont();
					return;
				}
				
			}else{
				savingsBalance = savingsBalance - aDouble;
				System.out.println("----------------------------------");
				showAccont();
				return;
				
			}
			
			
			
			return;
			}
	
	public void tenK(){ //test for the 10k
		
		if (savingsBalance>10000){
			System.out.println("your current Interestrat is 	:" + annualInterestRate);// shows new rate
			System.out.println("But becouse your accont is over 10,000 we have changed your interestRate ");
			annualInterestRate = .10; // change the rat to .10
			System.out.println("your new interest Rate is 		:" + annualInterestRate); //shows new rate
			System.out.println("thank you for using chaos386 backing");
			return;
		} else{
			return;
		}
	}
	
	public void notTenK(){ //test for the 10k
		
		if (savingsBalance<10000){
			System.out.println("your current Interestrat is 	:" + annualInterestRate);// shows new rate
			System.out.println("But becouse your accont is lower then 10,000 we have changed your interestRate ");
			annualInterestRate = .04; // change the rat to .4
			System.out.println("your new interest Rate is 		:" + annualInterestRate); //shows new rate
			System.out.println("thank you for using chaos386 backing");
			return;
		} else{
			return;
		}
	}
			public SpecialSavings(double x,double y){ //contruder to set up the acconts
		
		savingsBalance = x;	  //start money in accont
		annualInterestRate = y; // rate of interest

	}
	public static void main(String arg[]){
		
	}
} 	//end class (crated by Chaos386)


and class 4 i thnik this will help you out with your studys/home work/ assiment / what ever
/*Write a driver program to test the class SpecialSavings.
  Instantiate two different SavingAccount objects saver1 and saver2 with a balance of 2000.00 and 3000.00 Make a few deposits and 
  withdrawls and show balance.
Include a scanner class to enter different deposit and withdraw amounts and display current interest rate and balance.*/
package cahos386.SavingsAccount; //cerated by Chaos386
import java.io.*;
import java.util.*;
import java.util.Scanner;
public class TestDrive {
		
		 //setup the acconts
		 static SpecialSavings saver1 = new SpecialSavings(2000.00, .04);	//saver1 with balances of $2000.00 
		 	
		 
		 public static void main(String arg[])throws IOException{
		 	
		 	TestDrive td = new TestDrive();
		 	saver1.showAccont();
		 	System.out.println("How Mutch would you like to disposit?");
		 	
		 	
		 	
		 	Scanner in = new Scanner (System.in);
		 	String s = in.next();
		 	
		 	saver1.deposit(s);
		 	
		 	System.out.println("Thank you for your money");
		 	saver1.showAccont();
		 	
		 	System.out.println("How Mutch would you like to take out?");
		 	
		 	Scanner out = new Scanner (System.in);
		 	String o = out.next();
		 	saver1.withdrawls(o);
		 	
		 	
		 		//im not realy doing the best code ever you will have to do the number checks for the code a good website that is fast is http://www.cse.iitk.ac.in/users/dsrkg/cs210/html/javaio.html
		 		
		 }
}


Happy coding

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1