Current location: Hot Scripts Forums » Programming Languages » Everything Java » BankAccount object oreinted help


BankAccount object oreinted help

Reply
  #1 (permalink)  
Old 03-14-06, 01:31 AM
psi3000 psi3000 is offline
Newbie Coder
 
Join Date: Feb 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
BankAccount object oreinted help

Hey guys,
I need to wright a program that would be for a bank that lets the user input the name, ss#, type, address, balance and date. This program should figure out the interest with the equation interest = (total amount *number of days * interest rate)/365. The interest rate is quarterly with 6%,5%,4% and 3% respectivly. this is what i have so far:

import javax.swing.JOptionPane;
import javax.swing.Spring;

public class customer {

public static void main(String[] args)
{
String namei;
String soci;
String typei;
String input;
String addressi;
String datei;

Person cus = new Person();

namei =
JOptionPane.showInputDialog("What is" +
"the customers name?");
cus.setN(namei);

soci =
JOptionPane.showInputDialog("What is the customers"+
"social security number?");
cus.setSoc(soci);
typei =
JOptionPane.showInputDialog("What type of account is it?");
input =
JOptionPane.showInputDialog("What is the balance of the customer?");
cus.balance = Double.parseDouble(input);

addressi =
JOptionPane.showInputDialog("What is the address of the customer?");
cus.setAdd(addressi);
datei =
JOptionPane.showInputDialog("What is the date?");
cus.setD(datei);

JOptionPane.showMessageDialog(null, "Name: " + namei +
"\nsocial security #:" + soci + "\ntype:" + typei + "\nbalance:" +
input + "\naddress:" + addressi + "\ndate:" + datei);
}
}



HERE IS THE OTHER CLASS:

public class Person {
// data fields
public String name = "";
public String socSecNum = "";
public String type = "";
public double balance;
public String address = "";
public String date = "";
public double interest;



public Person(String n, String soc, String t,
double b, String add, String d, double in){

name = n;
socSecNum = soc;
type = t;
balance = b;
address = add;
date = d;
interest = in;
}

/**
*
*/
public Person() {

// TODO Auto-generated constructor stub
interest = (total * days * rate)/365;
}

//modifiers
public void setN(String n) {
name = n;
}
public void setSoc(String soc) {
socSecNum = soc;
}
public void setT(String t) {
type = t;
}
public void setB(double b) {
balance = b;
}
public void setAdd(String add) {
address = add;
}
public void setD(String d) {
date = d;
}
//accessors
public String getN(){
return name;
}
public String getSoc(){
return socSecNum;
}
public String getT(){
return type;
}
public double getB(){
return balance;
}
public String getAdd(){
return address;
}
public String getD(){
return date;
}

//postcondition:Returns the object's state as a string
public String toString(){
return"name: "+name+", social security " + socSecNum +
", type: " + type + "\naddress: " + address +
", balance: " + balance + ", date: " + date;
}}
AND I WANT TO INCLUDE THIS IF STATEMENT:

if (month == 1)
rate = .6
else if (month == 2)
days = 31 && rate = .6
else if (month == 3)
days = 28 && rate = .6
else if (month == 4)
days = 31 && rate = .5
else if (month == 5)
days = 30 && rate = .5
else if (month == 6)
days = 31 && rate = .5
else if (month == 7)
days = 30 && rate = .4
else if (month == 8)
days = 31 && rate = .4
else if (month == 9)
days = 31 && rate = .4
else if (month == 10)
days = 30 && rate = .3
else if (month == 11)
days = 31 && rate = .3
else if (month == 12)
days = 30 && rate = .3

THE STATEMENT TO COMPUTE THE INTEREST RATE DOESNT WORK AND I DONT KNOW WHY. Can someone help me fix this and put the if statement in the right place. And is there anything you would change?
thanks
Reply With Quote
  #2 (permalink)  
Old 03-15-06, 01:58 AM
psychotropic psychotropic is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
here's what it would be in c# for that last if/else thing

switch (month)
{

case 1:
rate = .6;
break;

case 2:
days = 31 && rate = .6;
break;

}

etc. etc. obviously look up how to do the syntax for the switch statement in java.
Reply With Quote
  #3 (permalink)  
Old 03-15-06, 02:04 AM
psychotropic psychotropic is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
using System;

namespace _9_5_inheritance
{

public class Point
{
// point coordinate
private double x, y;
public Point()
{
//implicit call to Object constructor
}

//constructor
public Point( double xValue, double yValue)
{
X= xValue;
Y= yValue;
}

//property X
public double X
{
get
{
return x;
}

set
{
x= value;
}

}
//propoerty Y
public double Y
{
get
{
return y;
}
set
{
y= value;
}
}

//return string for point
public override string ToString()
{
return "[" + X + ", " + Y + "]";
}
}
}
Reply With Quote
  #4 (permalink)  
Old 03-15-06, 02:12 AM
psychotropic psychotropic is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
using System;

namespace _9_5_inheritance
{

public class Square : Point
{
//Side property
private double side;

public Square()
: base (0.0,0.0)
{
side=0.0;
}

//constructor
public Square( double xValue, double yValue, double sideValue)
:base (xValue, yValue)
{
Side=sideValue;
}

//property side
public double Side
{
get
{
return side;
}

set
{
if (value >= 0.0 ) //validation
side= value;
}
}

public virtual double Area()
{
return Math.Pow ( Side, 2);//use property
}

public override string ToString()
{
//base property returns x,y
return "Center= " + base.ToString() + "; Side = " + Side;
}
}
}
Reply With Quote
  #5 (permalink)  
Old 03-15-06, 02:14 AM
psychotropic psychotropic is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
using System;

namespace _9_5_inheritance
{

public class Cube : Square
{
private double depth;

public Cube()
: base (0.0, 0.0, 0.0)
{
Side=0.0;

}

//start constructor
public Cube( double xValue, double yValue, double sideValue, double depthValue)
: base (xValue, yValue, sideValue)
{
Depth= depthValue; //set depth value

}

public double Depth
{
get
{
return depth;
}
set
{
if (value >=0.0 ) //validate depth
depth=value;
}
}

//calculate area
public override double Area()
{
return base.Area() * 6.0;
}

//calculate volume
public double Volume()
{
return Math.Pow( Side, 3);
}

//convert to string
public override string ToString()
{
return base.ToString() + "; Depth= " + Depth;
}
}
}
Reply With Quote
  #6 (permalink)  
Old 03-15-06, 02:14 AM
psychotropic psychotropic is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
/*
* Name: Scott Huber
* Class: IFS-201
* Date: 2/6/06
* Assignment: PA01
*/
using System;
using System.Windows.Forms;

namespace _9_5_inheritance
{

class Stub
{


[STAThread]
static void Main(string[] args)
{
//instantiate object of cube
Cube cube = new Cube(2.5, 2.5, 3.0, 3.0);

//properties get initial x, y, side, and depth
string output = "X coordinate is " + cube.X + "\n" + "Y coordinate is " + cube.Y + "\nSide is " +
cube.Side + "\n" + "Depth is " + cube.Depth;

//properties set new x-y coords, side, and depth
cube.X = 2.0;
cube.Y = 2.0;
cube.Side = 4.5;
cube.Depth = 4.5;

// get new x-y coordinate and side
output += "\n\nThe new location, side, and depth of " + "cube are\n" + cube + "\n\n";

//display cube's area
output += "area is " + String.Format( "{0:F}", cube.Area() ) + "\n";

//display cube's volume
output += "volume is " + String.Format( "{0:F}", cube.Volume() ) + "\n";

//output
MessageBox.Show( output, "Demonstrating Class Cube" );


}
}
}
Reply With Quote
  #7 (permalink)  
Old 03-16-06, 10:07 AM
stdunbar stdunbar is offline
Newbie Coder
 
Join Date: Jan 2004
Location: Superior, CO, USA
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
psychotropic - I realize that you're trying to help but posting C# code is pretty much a waste time. There are too many subtle differences between Java and C# to be of much help to a beginner.

psi3000 - It would help to understand what you're confused about. It appears that you have most of the code - where are you having an issue putting it all together?
__________________
Need Java help? Want to help people who do? Sit down with a cup of Java at the hotjoe forums.
Sure they're new - come get them started!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Concerning Collection Object DevinG Windows .NET Programming 1 01-13-06 01:46 PM
Customer ObJect RobertG Windows .NET Programming 0 10-13-05 02:06 AM
Error in OleDBConnection : Object reference not set to an instance of an object pvsunil Windows .NET Programming 1 04-22-05 01:45 PM
Please help with object and moving <div> !! Bravi HTML/XHTML/XML 0 01-27-05 04:22 PM
javascript object hidden by flash object morlack JavaScript 1 03-09-04 05:36 AM


All times are GMT -5. The time now is 05:36 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.