Search This Blog

If you have any problem or question please write in the comments. We will try to solve and send you the solution. Not just that we will also post your problems solution on our blog.

Thursday, 22 September 2011

Java program to calculate total cost of an item using methods (OOP)

import java.util.*;
class invoice
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
String name;
itemdata ob = new itemdata();
ob.get();
System.out.print ("\n\t Enter item name = ");
name=in.nextLine();
ob.cost();
ob.displyLine(name);

}
}


class itemdata
{
Scanner in = new Scanner (System.in);
int number;
double quantity,price,tcost=0;
void get()
{
System.out.print ("\n\t Enter item number = ");
number=in.nextInt();
}

void cost()
{
System.out.print ("\n\t Enter item quantity = ");
quantity=in.nextDouble();
System.out.print ("\n\t Enter item price per unit = ");
price=in.nextDouble();
tcost=quantity*price;
}

void displyLine(String name)
{
System.out.println ("\n\t Item number = "+number);
System.out.println ("\n\t Item nume = "+name);
System.out.println ("\n\t Item quantity = "+quantity);
System.out.println ("\n\t Item price per unit = "+price);
System.out.println ("\n\t Total cost = "+tcost);
}

}

22 comments:

  1. bookmarked!!, I love your website!
    Also visit my website :: my response

    ReplyDelete
  2. Hi there, I enjoy reading through your article post. I wanted to write a little comment to support you.
    Here is my site :: enquiry

    ReplyDelete
  3. What's Happening i am new to this, I stumbled upon this I have discovered It absolutely helpful and it has aided me out loads. I am hoping to give a contribution & assist different users like its aided me. Good job.
    Feel free to surf my web page ... here i found it

    ReplyDelete
  4. Undeniably believe that which you stated.
    Your favorite reason appeared to be on the internet
    the simplest thing to be aware of. I say to you, I certainly get annoyed while people think about worries that they plainly don't know about. You managed to hit the nail upon the top as well as defined out the whole thing without having side-effects , people can take a signal. Will probably be back to get more. Thanks
    Take a look at my web site ; his comment is here

    ReplyDelete
  5. Very rapidly this website will be famous amid all blog visitors,
    due to it's nice articles or reviews
    My web-site ; straight from the source

    ReplyDelete
  6. hello there and thank you for your info ? I have certainly picked up something new from right here.
    I did alternatively expertise several technical issues using this web site, since
    I experienced to reload the site lots of times prior to
    I could get it to load correctly. I have been brooding about in case your web host is OK?
    No longer that I'm complaining, however slow loading circumstances occasions will very frequently affect your placement in google and can damage your quality score if advertising and marketing with Adwords. Anyway I am adding this RSS to my e-mail and can glance out for much extra of your respective interesting content. Ensure that you replace this again soon..
    Look into my weblog a replacement

    ReplyDelete
  7. My relatives every time say that I am wasting my time here at net,
    however I know I am getting know-how every day by reading thes good content.
    Feel free to visit my weblog :: blog

    ReplyDelete
  8. Quality posts is the key to attract the people to pay a visit the web
    site, that's what this web site is providing.
    My webpage: home

    ReplyDelete
  9. Awesome blog! Do you have any tips and hints for aspiring writers?
    I'm planning to start my own site soon but I'm a little lost on everything.

    Would you recommend starting with a free platform like Wordpress
    or go for a paid option? There are so many options out there
    that I'm completely overwhelmed .. Any ideas? Many thanks!
    My web page - get redirected here

    ReplyDelete
    Replies
    1. Well i would recommend that you should start with a free platform. Once you get some experience then you can go for paid one.

      Regarding your first questing, i am a Java programmer. I post what i know or you can say what i experience. This is just a game of techniques the more techniques you have the more attractive content you will write.

      Delete
  10. .how to calculate all the fees that have been entered in text field and how to display it below?

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. Create a program named PrintingPrices that asks the user for the number of copies to print and then displays the price per copy and the total price for the job.
    please answer

    ReplyDelete
    Replies
    1. Number of copies Price per copy
      0 – 99 $0.30
      100 – 499 $0.28
      500 – 749 $0.27
      750 – 1000 $0.26
      over 1000 $0.25

      this is the problem to solve

      Delete
    2. Number of copies Price per copy
      0 – 99 $0.30
      100 – 499 $0.28
      500 – 749 $0.27
      750 – 1000 $0.26
      over 1000 $0.25

      this is the problem to solve

      Delete
  13. Create a program named PrintingPrices that asks the user for the number of copies to print and then displays the price per copy and the total price for the job.
    please answer

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. There are bunch of different ways. It's totally up to you how you create the card. If you are using any database (might be SQLite in your case), fetch details of cart items from DB and loop over each item in the result set and multiply item's unit price with selected number of that item. That is a simple way you can calculate total cost.

      If you are storing the cart items somewhere in cache or preferences, get the results and loop over items to calculate bill just like mentioned above.

      For example, user pushes 2 items to cart. The items can be:
      1- Chocolate (unit price $5)
      2- Juice (unit price $10)

      Assume that user want to checkout with 3 chocolates and 2 juices, then

      totalBill = (chocolate_unit_price * number_of_chocolates) + (juice_unit_price * number_of_juices);

      i.e. totalBill = (5*3) + (10*2);

      => totalBill = 35; // $35

      Delete
    2. Iam not used SQlite but I used Golang or API so that i need SubTotal cartshopping in android studio

      Delete
  16. This comment has been removed by the author.

    ReplyDelete
  17. Android studio How do I write a method to calculate total price for all products in a cartshopping?

    ReplyDelete