The stocks and thier current price are: facebook $34 ibm $20 hp $40 sprint $400
ID: 3643171 • Letter: T
Question
The stocks and thier current price are:facebook $34
ibm $20
hp $40
sprint $400
intel $38
Write a complete java program that uses arrays and loops that allows you to enter in what the stock actually closed at for the next day,and have the program tell you whether or not you should have bought the stock. You should have bought it if it was higher than the original price listed above.
A sample run should look msomething like the below(user input is the last price listed(32))
facebook--previous price was 34. What is the new price? 32
you should have not bought the stock.
sprint--previous price was 400. What is the new price? 440
you should have bought the stock!
Explanation / Answer
please rate - thanks
import java.util.*;
public class main
{public static void main(String[] args)
{String []name={"facebook","ibm","hp","sprint","intel"};
int []price= { 34, 20, 40, 400, 38};
int newPrice;
Scanner in=new Scanner(System.in);
for(int i=0;i<name.length;i++)
{System.out.print(name[i]+"--previous price was "+price[i]+". What is the new price? ");
newPrice=in.nextInt();
if(newPrice>price[i])
System.out.println("you should have bought the stock! ");
else
System.out.println("you should have not bought the stock! ");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.