OOPs, Classes, Methods
DISPLAY ITEM TYPE
Sample Input and Output 1:
Enter the item type name
Catering
Enter the cost per day
25000.00
Enter the deposit
10000.50
Item type details
Name : Catering
CostPerDay : 25000.00
Deposit : 10000.50
Enter the item type name
Catering
Enter the cost per day
25000.00
Enter the deposit
10000.50
Item type details
Name : Catering
CostPerDay : 25000.00
Deposit : 10000.50
CODE:
import java.util.Scanner;
//getters and setters!
public class ItemType {
private String name;
private double costPerDay;
private double deposit;
public String getName() {
return name;
}
public void setName(String name) {
this.name=name; //this- used to refer to current object
}
public double getCostPerDay() {
return costPerDay;
}
public void setCostPerDay(double costPerDay) {
this.costPerDay=costPerDay;
}
public double getDeposit() {
return deposit;
}
public void setDeposit(double deposit) {
this.deposit=deposit;
}
public void display(){
System.out.println("Item type details");
System.out.println("Name: "+name);
System.out.println("CostPerDay: "+String.format("%.2f",costPerDay));
System.out.println("Deposit: "+String.format("%.2f",deposit));
}
}
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
ItemType s1=new ItemType();
System.out.println("Enter the item type name");
String name=sc.nextLine();
s1.setName(name);
System.out.println("Enter the cost per day");
double costPerDay=sc.nextDouble();
s1.setCostPerDay(costPerDay);
System.out.println("Enter the deposit");
double deposit=sc.nextDouble();
s1.setDeposit(deposit);
s1.display();
}
}
Comments
Post a Comment