Need help in a Java Coding

rochel1977

Well-known member
  • May 15, 2006
    11,466
    2,673
    113
    AKL, NZ and Kandy
    Pls is there any body able to help me with this java coding for the below question?

    A Price of a product is $99. Quantity discounts are given according to the following table:

    Quantity Discount
    10–19 20%
    20–49 30%
    50–99 40%
    100 or more 50%

    need to use the if else statement.

    I'm using JCreator.
     

    crazycombo

    Member
    Jul 4, 2008
    3,101
    13
    0
    A Land Like No Other!
    Code:
    import java.util.Scanner;
    Class Discount{
    	public static void main(String []args){
    		System.out.println("Enter Product Quantity: ");
    		Scanner sc = new Scanner(System.in);
    		int quan=sc.nextInt();
    		double disc;
    		int price=quan*99;
    		double disc_tot;
    
    		if (quan>=10 && quan<=19){
    			disc=price * .2;
    		}
    		else if (quan>=20 && quan<=49){
    			disc=price * .3;
    		}
    		else if (quan>=50 && quan<=99){
    			disc=price * .4;
    		}
    		else if (quan>=100 ){
    			disc=price * .5;
    		}
    		disc_tot=price-disc;
    		
    		System.out.println("Total Price: " + price);
    		System.out.println("Discount : " + disc);
    		System.out.println("Discounted Total : " + disc_tot);
    	}
    }


    for more java help Visit : http://dynamicadahas.wordpress.com/
     

    Ranhiru

    Member
    Feb 2, 2007
    6,438
    42
    0
    Inside FIREFOX
    Its really easy machan...
    what you need to do is first take the input. (how many products) I hope you know how to take the input from the user.

    Then keep a variable for the final price...

    then keep on testing for conditions

    if (value=>100)
    finalprice=value*0.2 //50%;
    else if ( (value=>50) && (value=<99)
    finalprice=value*0.4 //40%

    like this machan construct the whole if else structure and finally print the final value :)

    Hope this helps...

    Machan and if you wanna learn machan dont ask anyone 2 write the full code.
    Write your own code and paste it here and the people can see if its right or if its wrong can point out where u went wrong...

    gud luck
     
    Last edited:

    rochel1977

    Well-known member
  • May 15, 2006
    11,466
    2,673
    113
    AKL, NZ and Kandy
    crazycombo said:
    Code:
    import java.util.Scanner;
    Class Discount{
    	public static void main(String []args){
    		System.out.println("Enter Product Quantity: ");
    		Scanner sc = new Scanner(System.in);
    		int quan=sc.nextInt();
    		double disc;
    		int price=quan*99;
    		double disc_tot;
    
    		if (quan>=10 && quan<=19){
    			disc=price * .2;
    		}
    		else if (quan>=20 && quan<=49){
    			disc=price * .3;
    		}
    		else if (quan>=50 && quan<=99){
    			disc=price * .4;
    		}
    		else if (quan>=100 ){
    			disc=price * .5;
    		}
    		disc_tot=price-disc;
    		
    		System.out.println("Total Price: " + price);
    		System.out.println("Discount : " + disc);
    		System.out.println("Discounted Total : " + disc_tot);
    	}
    }


    for more java help Visit : http://dynamicadahas.wordpress.com/

    apata siri. ela macho thx. i will run this now. and thx for the link also. appreciate it machang. :)
     

    rochel1977

    Well-known member
  • May 15, 2006
    11,466
    2,673
    113
    AKL, NZ and Kandy
    Ranhiru said:
    Its really easy machan...
    what you need to do is first take the input. (how many products) I hope you know how to take the input from the user.

    Then keep a variable for the final price...

    then keep on testing for conditions

    if (value=>100)
    finalprice=value*0.2 //50%;
    else if ( (value=>50) && (value=<99)
    finalprice=value*0.4 //40%

    like this machan construct the whole if else structure and finally print the final value :)

    Hope this helps...

    Machan and if you wanna learn machan dont ask anyone 2 write the full code.
    Write your own code and paste it here and the people can see if its right or if its wrong can point out where u went wrong...

    gud luck

    ok macho. thx. i will try this on my own. actually java is not my comfortable zone macho. btw thx for ur advice macho. :)
     

    Ranhiru

    Member
    Feb 2, 2007
    6,438
    42
    0
    Inside FIREFOX
    rochel1977 said:
    ok macho. thx. i will try this on my own. actually java is not my comfortable zone macho. btw thx for ur advice macho. :)

    Neither is mine machan...even im not that comfy with java...i like the Dot Net platform...but machan get used to Java...because it is the future :)
    Anyway just write your own code and try and try to debug it... and if u cant post the code here :)
     

    x-pert

    Member
    Jun 13, 2006
    20,952
    77
    0
    Ranhiru said:
    Neither is mine machan...even im not that comfy with java...i like the Dot Net platform...but machan get used to Java...because it is the future :)
    Anyway just write your own code and try and try to debug it... and if u cant post the code here :)

    Java is not the future ;)

    There is a new language in development.... Enabling the capability of mixing java with .NET easily. I reckon that will be the future :D

    BTW, I like your advice :D That's how we should learn how to program :yes:
     

    crazycombo

    Member
    Jul 4, 2008
    3,101
    13
    0
    A Land Like No Other!
    x-pert said:
    Java is not the future ;)

    There is a new language in development.... Enabling the capability of mixing java with .NET easily. I reckon that will be the future :D

    BTW, I like your advice :D That's how we should learn how to program :yes:


    whoa....thanks for the info man.... btw just for the record my friend, the technologies are hybrid now. java is running on .NET framework. its named as J#.
     

    x-pert

    Member
    Jun 13, 2006
    20,952
    77
    0
    crazycombo said:
    whoa....thanks for the info man.... btw just for the record my friend, the technologies are hybrid now. java is running on .NET framework. its named as J#.

    Exactly. What I was talking about an enhanced version of J#.

    J# was in the arena from 2005.
     

    crazycombo

    Member
    Jul 4, 2008
    3,101
    13
    0
    A Land Like No Other!
    x-pert said:
    Exactly. What I was talking about an enhanced version of J#.

    J# was in the arena from 2005.

    yeah.... in 2005, J# was JDK 1.3 compatible. but as long as the development is concerned, the 1.6 compatible version is also released and available with VS 2008
     

    Ranhiru

    Member
    Feb 2, 2007
    6,438
    42
    0
    Inside FIREFOX
    x-pert said:
    Java is not the future ;)

    There is a new language in development.... Enabling the capability of mixing java with .NET easily. I reckon that will be the future :D

    BTW, I like your advice :D That's how we should learn how to program :yes:

    woahh!! didnt know abt that... can i integrate J# in to Visual Studio and code??
    I mean is it out yet???

    thanx 4 da info :)