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 BeginnersConstructors,
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 BeginnersConstructors,
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 JavaConstructors 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 - Java Beginnersconstructors 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 methodConstructors .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 methodConstructors .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
Java ConstructorsJava
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 IIObject 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 myBatisJava 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 pickerstruts2 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 struts2datetime 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
Struts 2.0.1
* Friendly Result
constructors and
setters
Following New
java - Java Beginners that wants to access the variables should access them through these
getters and
setters 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