How To Read User Inputs in A Typical Java Application?
How To Read User Inputs in A Typical Java Application?
CS F213
LAB-2 [Class Design Basics - Part-1]
DATE: 15/08/2015
TIME: 02 Hours
class Example1 {
public static void main(String args[]) throws IOException{
/* instantiate InputStreamReader class and pass
System.in to its constructor */
InputStreamReader isr =
new InputStreamReader(System.in);
/* instantiate BufferedReader class and pass the
reference
variable
isr
which
id
of
type
InputStreamReader created in the previous line to the
constructor of BufferedReader */
BufferedReader br = new BufferedReader(isr) ;
System.out.println("Enter Your First Name: ");
/* call readLine method on br reference variable which
is of type BufferedReader */
b)
c)
d)
e)
f)
and idNo fields only. If an Customer instance is created by providing the value for
name and idNo fields only then value for balance is by default initialized to 5000.
Accessor methods(s) are provided for every instance field.
Mutator methods(s) are provided for the instance field name and idNo.
Method print() to print the details of item (itemName, itemidNo, iemQuantity and
itemPrice) purchased by the customer and balance amount of the customer after
purchasing the item.
A method named buyItem(Item item) is supplied. This operation displays details of the
item bought and the current balance, if the customer has sufficient balance and the
quantity specified by the user is greater than or equal to one. If the customer dont have
the sufficient balance, this method displays the message Insufficient balance .If the
quantity specified by the user is less than one, this method displays the message Order
is not valid.
All the field(s) have private visibility and all methods have a public visibility.
(iv)
b. if salary < 180000 and isPANsubmitted = false, then tax payable is 5% of the
salary
c. if 180000 < salary < 500000, then tax payable is 10% of the salary
d. if 500000 < salary < 1000000, then tax payable is 20% of the salary
e. if 1000000 < salary, then tax payable is 30% of the salary
A method named inputSalary() is supplied to read the value for the salary as an
input from the user [consider reading this value from keyboard] and to assign
the value to the corresponding instance variable salary.
Exercise 5:
A. Define a class Car which encapsulates following attributes and methods
Attributes: private scope
year - The year field is an int that holds a car's year model (e.g. 2010)
make - The make field is a String object that holds the make of the car (e.g. "TATA")
speed - The speed field is an double that holds a car's current speed (e.g. 25.0)