HI, I NEED HELP WRITING THEFOLLOWING JAVA PROGRAM ! 1. writenon-void (value-retu
ID: 3613538 • Letter: H
Question
HI, I NEED HELP WRITING THEFOLLOWING JAVA PROGRAM !
1. writenon-void (value-returning) methods in Java
2. write voidmethods in Java
3. passprimitive values to void and non-void Java methods
4. use the Scannerclass or JOptionPane class to get user input and produce finalresults.
Last month Joe purchased stock inTexas Instruments. Here are the details of the purchase:
· Joepurchased 1000 shares of stock.
· Joe paid24.86 for each share of stock.
· Joe paidhis stockbroker a 2% commission based on the total price of thestock.
Two weeks later Joe sold thestock. Here are the details of the sale:
· Joe sold1000 shares of stock.
· Joe soldthe stock for 24.32 a share.
· Joe paidhis stockbroker another 2% commission on the amount of money Joereceived from the sale of the stock.
Programspecifications:
· The mainmethod of your program should have four major sections:
1. declaration section where allvariables are declared (follow naming conventions given innotes)
2. section that gets the input fromthe user (use JOptionPane or the Scanner class)
3. section that calls the methodsthat perform the calculations
Ø no calculations should appear in main
Ø method names should be meaningful and follow thesame naming convention as variables
Ø methods are like C++ functions but all of thesemethods should begin with the words public static)
4. section that calls a method thatdisplays the output
Ø amount of money paid for the stock
Ø amount of commission paid to the stockbroker whenthe stock was purchased
Ø amount of money received from the sale of thestock
Ø amount of commission paid to the stockbroker whenthe stock was sold
Ø amount of profit or loss after the sale of the stockand after the commission is paid to the stockbroker
· Thecommission rate should be declared as a final (follow namingconventions).
Second set of data: (you will need to change the value of the final)
Last month Jane purchased stock inGoogle. Here are the details of the purchase:
· Janepurchased 500 shares of stock.
· Jane paid461.30 for each share of stock.
· Jane paidhis stockbroker a 1 ½ % commission based on the total priceof the stock.
Two weeks later Joe sold the stock. Here are the details of the sale:
· Jane sold500 shares of stock.
· Jane soldthe stock for 465.01 a share.
· Jane paidhis stockbroker another 1 ½ % commission on the amount ofmoney Joe received from the sale of the stock.
THANKS
Explanation / Answer
please rate - thanks change the commission rate for the 2nd set of data import java.util.*; public class untitled { public static void main(String []args) {Scanner in=new Scanner(System.in); String stock; int sharesBought,sharesSold; double paid,commToBuy,pricePaid,salePrice,sold,commToSell,value; final double commRate = .02; System.out.print("Enter name of stock purchased: "); stock=in.nextLine(); System.out.print("Enter number of shares purchased: "); sharesBought=in.nextInt(); System.out.print("Enter amount paid per share: "); pricePaid=in.nextDouble(); paid=calculatePrice(sharesBought,pricePaid); commToBuy=calculateComm(paid,commRate); System.out.print("Enter number of shares sold: "); sharesSold=in.nextInt(); System.out.print("Enter amount sold each share for: "); salePrice=in.nextDouble(); sold=calculatePrice(sharesSold,salePrice); commToSell=calculateComm(sold,commRate); value=calculateValue(paid,commToBuy,sold,commToSell); report(stock,paid,commToBuy,sold,commToSell,value); } public static double calculateValue(double paid,double commbuy,double sold, double commsell) {return (sold+commsell)-(paid+commbuy); } public static double calculatePrice(int num, double price) {return num*price; } public static double calculateComm(double num, double rate) {return num*rate; } public static void report(String name,double paid, double commbuy,double sold, double commsell, double value) {System.out.println(" Stockname: "+name); System.out.printf("Amount paid for stock:$%.2f ",paid); System.out.printf("Purchasecommission: $%.2f ",commbuy); System.out.printf("Total purchase price: $%.2f ",paid+commbuy); System.out.printf("Amount sold stock for:$%.2f ",sold); System.out.printf("Salecommission: $%.2f ",commsell); System.out.printf("Total saleprice: $%.2f ",sold+commsell); if(value>0) System.out.printf("Profitafter sale: $%.2f ",value); else if(valueRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.