This week's book giveaway is in the Python forum.
We're giving away four copies of High Performance Python for Data Analytics and have Tiago Rodrigues Antao on-line!
See this thread for details.
Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Bad operand type " * " How do I fix it? Located near bottom

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Master Rancher
Posts: 4107
37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you getting an error from the compiler?
What source line is the error on?
 
Jason Petrie
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its a compiler error

System.out.println("Mug       $5.00    ");
       System.out.println("How many T-shirts do you want?");
       String numberShirts = input.nextLine();
       System.out.println("How many hats?");
       String numberhats = input.nextLine();
       System.out.println("How many mugs?");
       String numbermugs = input.nextLine();
      double tshirtTotal = Shirtprice * numberShirts;
       double chipsTotal = Hatprice * numberhats;
       double cokeTotal =  Mugprice  * numbermugs
;
 
Saloon Keeper
Posts: 7622
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jason, welcome to The Code Ranch!

When you post code please UseCodeTags (<--link). I fixed it for you this time.
 
Carey Brown
Saloon Keeper
Posts: 7622
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"numberShirts" is of type String. You can't multiply a double by a String. You'll have to convert the String to a number first, or just use input.nextInt() to get an int instead.
 
Norm Radder
Master Rancher
Posts: 4107
37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

A String can not be used in an arithmetic expression.
 
Marshal
Posts: 71760
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch again.

Why have you got those prices as constants in the receipt class? That looks like strange design. A receipt doesn't have a price; a product does. The object‑oriented way to do it would be to have a Product class with description and price fields. And maybe number bought.
Avoid nextLine(); if you want a number of items, the Scanner provides a method that does exactly that.
Why have you made everything static? That is usually a mistake unless you can find good justification for it; because it won't compile otherwise doesn't count as good justification.
 
yeah, but ... what would PIE do? Especially concerning this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic