Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Constructors, setters, getters

Have Programming Question? Ask it here!
 
 
 


Chelsea
Constructors, setters, getters
1 Answer(s)      3 years and 10 months ago
Posted in : Java Beginners


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

Advertisement
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
. Constructors are used to initialize the instance variables (fields) of an object. Constructors are similar to methods, but with some important differences. Constructor name is class name. A constructors must have the same name as the class its
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
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 .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
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
Thread Constructors
Thread Constructors       Several constructors are available for creating new Thread instances.    Thread() Thread(String)   Thread(Runnable) 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
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- Constructor name must be same as the class name. It should
Constructors - super
is created, it's necessary to call the constructors of all super classes.... For example, the first Point constructor (see Constructors) could be be written... constructor with no parameters? Altho the previous example (see Constructors
Constructors - super example
the Constructors in details. Example code provided here will help you in learning the Java Constructors easily. While creating a class if any constructor is defined.... In a class you can define any number of constructors having different
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. Constructors are used to initialize the object. They are just like method declaration but they do not return value. Constructors are defined by their class name. Here
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
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 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...;Working With Constructors and Inheritance</title>...;Working With Constructors and Inheritance</h1>
Java API
, interfaces with their methods, constructors that come with JDK. Java API included
How to write a file in Java?
, constructors of this class assume that character encoding and byte-buffer size... OutputStreamWriter on a FileOutputStream. There are various constructors of FileWriter class... of these constructors are as follows: FileWriter(File file): This constructors creates
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
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
Inheritance
features like methods, data members, access controls, constructors, keywords...;   int y;   int get(int p, int q){   x=p; y=q; return(0);   }   void 
Entities in JPA 2.1
of the entity should only be accessed through setters and getters methos... an entity and then access the state only using setters and getters methods... through setters and getters methods. Primary Keys and Entity Identity Each
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
collectionMapping using annotation
java.util.List friends; //setters and getters; but when i run
DAO,DTO,VO Design patterns
) is mere accessors ie, getters and setters used to fetch the data. It can
Java null pointer exception
and getters and setters. Now I've made a method to search for a given string
how to get session object in simple java class??
setters and getters) 3) GroupServlet.java (a servlet class for control) 4
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
java - Java Beginners
that wants to access the variables should access them through these getters and setters
what is difreence between javabeans and enterprise beans - EJB
getters and setters for all its data members, along with other required
Persistent Fields and Properties in Entity Classes
-data to the JPA runtime. The Java style getters and setters methods are used
OOP Tutorial [first draft]
. This is sometimes done with so called getter and setter methods. Getters and Setters Naming..." followed by the attribute that should be obtained or set.. Getters and setters... the TimeOfDay class, rewritten with private instance variables and getters and setters
Struts 2.0.1
* Friendly Result constructors and setters   Following New
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
Advertisements
 

 

 

DMCA.com