Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Test

import java.util.Scanner.*;
class Sample {

public static void main (String[] args){

Scanner sc = new Scanner(System.in)

def name, assetNumber, model, lastAssignedDate, price

Asset asset = null;
println("1.First admin");
println("2.Second admin");
println("3.Third admin");
println("Enter the choice:")
int selectChoice = Integer.parseInt(sc.nextLine());

switch(selectChoice){
case 1:
println("Asset number:")
assetNumber = Integer.parseInt(sc.nextLine())
println("Assigned date:")
lastAssignedDate = sc.nextLine().replace("/","-");
println("Price:")
price = Double.parseDouble(sc.nextLine());
asset = new Asset(assetNumber, name, model, lastAssignedDate, price)
break;

case 2:
println("Asset name:")
name = sc.nextLine()

println("Assigned date:")
lastAssignedDate = sc.nextLine().replace("/","-");

println("Price:")
price = Double.parseDouble(sc.nextLine());
asset = new Asset(assetNumber, name, model, lastAssignedDate, price)
break;
case 3:

println("Asset model:")
model = sc.nextLine()

println("Assigned date:")
lastAssignedDate = sc.nextLine().replace("/","-");

println("Price:")
price = Double.parseDouble(sc.nextLine());
asset = new Asset(assetNumber, name, model, lastAssignedDate, price)
break;

}


println(asset.toString())
sc.close()

}
}
class Asset{

def assetNumber
def name
def model
def lastAssignedDate
def price

public Asset( def assetNumber, def name,def model, def lastAssignedDate, def price){

this.assetNumber = assetNumber
this.name = name
this.model = model
this.lastAssignedDate = lastAssignedDate
this.price = price
}

@Override

public String toString() {

return "Asset.No : ${assetNumber} | Name : ${name} | Model : ${model} | Last Assigned Date : ${lastAssignedDate.toString().replaceAll('/','-')} | Price : ${price}"
}

}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.