In: Computer Science
Using rscript
Let us assume that the credit rating of a company determines yield to maturity (YTM) of the bond. This leaves you now with three different YTM: 2% for AAA, 4% for AA, 8% for others. You want to run the following commends. If the credit rating is AAA, print “YTM of the bond is 2%.” If the credit rating is AA, print “YTM of the bond is 4%.” If the credit rating is neither AAA nor AA, print “YTM of the bond is 8%.” Somebody already wrote the following code for you, and you have to complete the next lines. bond.rating <- "A" a) To run the commends above, use if....else statement. b) To run the commends above, use if....else if statement.
PLEASE GIVE THUMBS UP, THANKS
a) CODE WITH OUTPUT SAMPLE :
Code:
bond.rating <- "A"
if (bond.rating =="AAA"){
print("YTM of the bond is 2%.")
}else {
if (bond.rating =="AA"){
print("YTM of the bond is 4%.")
}else{
print("YTM of the bond is 8%.");
}
}
b)
code:
bond.rating <- "A"
if (bond.rating =="AAA"){
print("YTM of the bond is 2%.")
}else if (bond.rating =="AA"){
print("YTM of the bond is 4%.")
}else{
print("YTM of the bond is 8%.");
}