Constructors, setters, getters

Constructors, setters, getters

A bank charges $10 per month plus the following check fees for a commercial checking account:

$.10 each for less than 20 checks
$.08 each for 20-39 checks
$.06 each for 40-59 checks
$.04each for 60 or more checks

The bank also charges an extra $15 if the balance of the account falls below $400 (before any check fees are applied). Design a class BankCharges that stores the beginning balance of an account and the number of checks written. Create a constructor that allows a user of the class to initialize both values. The class should use a constant to represent the base fee, low balance threshold, and low balance fee. It should also have appropriate setters, getters, and a method that returns the bank?s service fees for the month. Use either DecimalFormat class or format specifiers to display service fees with exactly two digits after decimal point.

Write a driver program BankChargesTest.java to test your class.

It says in my book there should be 2 setters and 2 getters for the class program
View Answers

November 9, 2010 at 11:39 PM

import java.util.Scanner;

public class BankCharges { private String Acctype; private double bal; private int noofchecks=0; private int amt; private double charge; Scanner Keyboard=new Scanner(System.in);

public void setBal(double bal){
    this.bal=bal;
}
public double getBal(){
        if(bal<400){
        bal=bal-15;
        System.out.println("Balance is "+bal);
    }
    else{
    bal+=amt;
    System.out.println("Balance is "+bal);}
    return 0;
}
public void setnoofchecks(int noofchecks){
    this.noofchecks=noofchecks;
}
public double getNoofchecks(){


    if(noofchecks<=20){
        charge=(noofchecks*0.1);
        System.out.println("Charge is "+charge);
    }
    else if((noofchecks>20)&&(noofchecks<=39)){
        charge=(noofchecks*0.08);
        System.out.println("Charge is "+charge);
    }
    else if((noofchecks>40)&&(noofchecks<=59)){
        charge=(noofchecks*0.06);
        System.out.println("Charge is "+charge);
    }
    else{
        charge=(noofchecks*0.04);
        System.out.println("Charge is "+charge);
    }
    return 0;
}

}

public class user { public static void main(String[] args) { BankCharges bc=new BankCharges(); bc.setBal(1500); bc.getBal(); bc.setnoofchecks(20); bc.getNoofchecks(); }}









Related Tutorials/Questions & Answers:
Constructors, setters, getters - Java Beginners
Constructors, setters, getters  A bank charges $10 per month plus... balance threshold, and low balance fee. It should also have appropriate setters, getters, and a method that returns the bank?s service fees for the month. Use
Constructors, setters, getters 2 - Java Beginners
Constructors, setters, getters 2  A bank charges $10 per month plus... balance threshold, and low balance fee. It should also have appropriate setters, getters, and a method that returns the bank?s service fees for the month. Use
Advertisements
Getters and setters
the difference between Java and AS3 getters and setters? please give me the answer ASAP. Thanks   Ans: Getters and Setters are different in java and flex. In Flex ActionScript the getters and setters are the part of ECMA Script
getters and setters
getters and setters   Create a Pet class that contains the following properties: A species (cat, dog, hamster, etc) an age, and an age_factor... years) Create the following methods: A constructor, getters and setters
Constructors in Java
Constructors in Java  When do we use Constructors in JAva?   All object creation is done through constructors. If no constructor is specified, the compiler will supply a default empty constructor that basically does
constructors
constructors
How are this() and super() used with constructors?
How are this() and super() used with constructors?   Hi, How are this() and super() used with constructors? thanks
constructors - Java Beginners
constructors  can constructors be inherited???  Hi friend, Constructors cannot be inherited, basically a constructor is not a method.Constructors are used to give a valid state for an object at creation
Constructors .equals method
Constructors .equals method  Hi, my two dates never match using .equals method and two different constructors. o/p is like examples.Pdate@192d342Blah dateexamples.Pdate@6b97fd Code: package examples; public class Pdate
Constructors .equals method
Constructors .equals method  Hi, my two dates never match using .equals method and two different constructors. o/p is like examples.Pdate@192d342Blah dateexamples.Pdate@6b97fd Code: package examples; public class Pdate
Thread Constructors
Thread Constructors       Several constructors are available for creating new Thread instances.    Thread() ADS_TO_REPLACE_1 Thread(String)   Thread
why we use constructors instead of methods in java?
why we use constructors instead of methods in java?   why we use constructors instead of methods in java
What are constructors ? explain different types of constructor with example
What are constructors ? explain different types of constructor with example  Hi, What are constructors ? explain different types of constructor... constructor require. That's why the Constructors are used to initialize the instance
Exceptional Constructors - Java Tutorials
Java Constructors
Java Constructors In this tutorial we will discuss in java constructor and its type with example. Constructors : A constructor is a special kind of method... of constructors-ADS_TO_REPLACE_1 Constructor name must be same as the class
Objective C Constructors
Objective C Constructors       Objective-C enables user to define constructor with the help of self and super keywords. Like java Objective-C has parent class and programmer
Java Constructor Overloading Example
is achieved in the Java programming. Constructors in Java are a special type... class name, it may contain any number of parameters. Constructors defined... programming is called constructor overloading. Constructors with different
Object Oriented Programming II
Object Oriented Programming II  Instructions: ->each class to be created must have encapsulated fields, setters and getters methods, and constructors Create a class named "Paper" with the following attributes
Use Constructor in JSP
; This section illustrates you how to use constructors in jsp.ADS_TO_REPLACE_1 Constructors are used to initialize the object. They are just like method declaration but they do not return value. Constructors are defined
Java with myBatis
Java with myBatis  I have two java been. i have to pass these two class as the parameter in the sql query in the Mybatis. for ex: two classes are class A{}//some setters and getters class B{}//some setters and getters My DAO
Simple date formatter example
are going to describe you how you can use different constructors of SimpleDateFormat class to convert the date into the specified format. There are various constructors
Simple Date example
Simple Date example       In this section we have presented a simple Date example that shows how you can use different constructors of Date. We can construct the Date
Java Date
a simple Date example that shows how you can use different constructors of Date... are going to describe you how you can use different constructors
Constructor Inheritance
;    Constructors are used to create objects from...;   <title>Working With Constructors...;   <h1>Working With Constructors
How to write a file in Java?
. By default, constructors of this class assume that character encoding and byte... OutputStreamWriter on a FileOutputStream. There are various constructors..._TO_REPLACE_2 Some of these constructors are as follows: FileWriter(File file
struts2 datetime picker
struts2 datetime picker  i created a field with sx:datetimepicker with the name fromdate. and i wrote getters and setters for fromdate with datatype string. when im reading data im getting date+time but i want only date can u
datetime picker in struts2
datetime picker in struts2  i used datetimepicker and i created getters and setters with retutn type string when im reading date value which i entered through getter im getter date as well as time i want date only how can i get
Java API
, interfaces with their methods, constructors that come with JDK. Java API included
Entities in JPA 2.1
. You can load an entity and then access the state only using setters and getters... are private and can be accessed only through setters and getters methods. Primary... constructor in the Entity class. The entity class may have other constructors
Inheritance
will learn more about Constructor and how constructors are overloaded in Java... in Java. Constructors are used to assign initial values to instance... because JVM differentiates constructors on the basis of arguments passed
Inheritance
features like methods, data members, access controls, constructors, keywords...; int get(int p, int q){   x=p; y=q; ...;   int get(int p, int q){   x=p; y
Hibernate @ManyToOne persisting problem - Hibernate
Student student; (Constructor, getters, setters) class Student: @Id...(); (Constructor, getters, setters) because I use "hibernate.hbm2ddl.auto" all tables
Distinguishes JavaBeans from Java Classes
doesn't need any convention. 3)Java bean contains only setters and getters while
how to Use jsp:setProperty to set one bean in other bean while to be set bean is of type java.util.List<beantype>
price; private List<Chapter> chapters; // Getters and Setters...; private String name; private String address; // Getters and Setters...; private int numOfPages; // Getters and Setters I have a single jsp
DAO,DTO,VO Design patterns
) is mere accessors ie, getters and setters used to fetch the data. It can
collectionMapping using annotation
java.util.List friends; //setters and getters; but when i run
Struts 2.0.1
* Friendly Result constructors and setters   Following New
what is difreence between javabeans and enterprise beans - EJB
getters and setters for all its data members, along with other required
java - Java Beginners
that wants to access the variables should access them through these getters and setters
Java Servlets - Java Interview Questions
)POJO stands for Plain Old Java Object. It is a Java class that contains setters and getters and doesn't get extended or implemented. Benefits
how to get session object in simple java class??
setters and getters) 3) GroupServlet.java (a servlet class for control) 4
Java null pointer exception
and getters and setters. Now I've made a method to search for a given string
Persistent Fields and Properties in Entity Classes
specify the meta-data to the JPA runtime. The Java style getters and setters
Apache commons beanutils maven dependency
the properties of the bean through getters and using setters copying the values
Java Date
core java question - Java Interview Questions
why we use constructors????? or what is the need of constructors?? or what is the utility of constructors????  to intialize the instance variabe we will use the constructors
Diffrent EJB & Java Bean - EJB
and typically contain getters and setters for all its data members, along
How to save array of UserType in Oracle using Hibernate.
; //setters and getters } public class EmpAddressArrTY implements UserType
Why PriorityQueue gives such a strange behaviour?
with setters and getters. SortRequest class is something like this: class...Why PriorityQueue gives such a strange behaviour?  I am using priority Queue Queue<Request> q = new PriorityQueue<Request>(5, new

Ads