is there any way to seperate input for two different objects for a currently declared variable in java? -
so i'm trying take input user 2 different products being bought. need have data inputted table believe i'm creating correctly. scanner method keeping information not outputting them table. question can create sub variables declare variable such p1 , p2 variable productname or qty1 , qty2 quantity. know why not outputting data table because incorrectly labeled placeholders example %f. haven't found information saying , i've found closely related creating array inputs needed. i'm not best appreciate help.
import java.util.scanner; import java.text.numberformat; public class project2 { public static void main(string[] args) { scanner scan = new scanner(system.in); int quantity; double unitprice; string productname; system.out.println("enter name product 1:"); productname = scan.nextline(); system.out.println("enter amount desired product 1:"); quantity = scan.nextint(); system.out.println("please enter price of product 1:"); unitprice = scan.nextdouble(); double total = unitprice * quantity; system.out.println("enter name product 2:"); productname = scan.nextline(); system.out.println("enter amount desired product 2:"); quantity = scan.nextint(); system.out.println("please enter price of product 1:"); unitprice = scan.nextdouble(); system.out.println("--------------------------------------------"); system.out.println("| product | qty | price | total |"); system.out.println("--------------------------------------------"); system.out.printf("| %c | %f | %d | %.2f |\n",productname, quantity,unitprice, total); system.out.printf("| %c | %f | %d | %.2f |\n",productname, quantity, unitprice, total); system.out.println("-------------------------------------------- "); } }
you should create 2 variables each property. if use 1 variable each property, end losing values product one.
Comments
Post a Comment