• 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
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Having trouble compiling this Java code. Any help?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I continue to receive the errors below.


Marios.java:55: error: constructor Marios in class Marios cannot be applied to given types;
Marios name = new Marios("Meatlovers","Deep Dish","Bacon, Sausuage, Ham, Pepperoni");
             ^
 required: String,String,String,int
 found: String,String,String
 reason: actual and formal argument lists differ in length
Marios.java:56: error: cannot find symbol
System.out.println(name.pizzaorder);
                      ^
 symbol:   variable pizzaorder
 location: variable name of type Marios
2 errors

 
Master Rancher
Posts: 4371
47
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your constructor has 4 parameters (3 Strings and an int).
The line in question is calling a constructor with only 3 parameters (3 Strings).
That's what the error is complaining about.

Either you need to provide a cost when creating your instance of Marios, or you need to provide a new constructor that only takes the 3 Strings.
Which one is correct is entirely down to your requirements.
 
Marshal
Posts: 14530
242
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Robert Daniels!

Please take a look at our wiki page that tells you how to UseCodeTags (←that's a link, click it) properly. Basically, the code you want to post goes between the start and end tags. I'll fix it for you this time.
 
Dave Tolls
Master Rancher
Posts: 4371
47
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yes, the second error:

Your Marios class doesn't have a pizzaorder attribute, but it does have a pizzasorder method.
I'm assuming that's what you meant to use, so just correct the spelling (pizzas plural) and add in the brackets for a method call.
 
Junilu Lacar
Marshal
Posts: 14530
242
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look through the error messages, it tells you what the problem is:

Marios.java:55: error: constructor Marios in class Marios cannot be applied to given types;
Marios name = new Marios("Meatlovers","Deep Dish","Bacon, Sausuage, Ham, Pepperoni");
             ^
 required: String,String,String,int  <-- requires a 4th int argument
 found: String,String,String  <-- you only passed three String arguments
 reason: actual and formal argument lists differ in length
Marios.java:56: error: cannot find symbol
System.out.println(name.pizzaorder);
                      ^
 symbol:   variable pizzaorder
 location: variable name of type Marios
2 errors

 
Junilu Lacar
Marshal
Posts: 14530
242
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look further down, it warns of another error:

Marios.java:56: error: cannot find symbol
System.out.println(name.pizzaorder);
                      ^
 symbol:   variable pizzaorder
 location: variable name of type Marios
2 errors

Compilers are very literal so you have to give very precise instructions. If you meant to call the pizzasorder() method, then you have to write exactly that. It won't let little typos like that slide. And names in Java are case-sensitive, too, so pizzaOrder() is NOT the same as pizzaorder() And when you're calling a method that takes no arguments, you still have to include the parentheses at the end of the name.
 
Robert Daniels
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to find my error for not having 'pizzaorder' as singular.

What I would like for the code to do is have (3) strings and (1) int. I'm confused how I would be able to add the int into the string code below so that the pizza costs $8.50.




Marios.java:55: error: incompatible types: String cannot be converted to int
Marios name = new Marios("Meatlovers","Deep Dish","Bacon, Sausuage, Ham, Pepperoni","$8.50");
                                                                                   ^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
 
Marshal
Posts: 7323
497
Mac OS X VI Editor BSD Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

"$8.50"
error: incompatible types: String cannot be converted to int


"$8.50" isn't an int, it is a string, those quotes (opening and closing) denote that. If you'd take quotes off, you'd get also an error about $ symbol.

Think about ints as about whole numbers. And about doubles as about fractional numbers.

Some examples of ints:
0, 1, 2, 100, -100, -1, ...

Some examples of doubles:
0.3, 8.5, 4.2, ...

So you really want not an int, but double maybe for your exercise. Or if you use ints, then convert the price to cents and then pass that amount, i.e. 850 $ cents = $ 8.5
 
lowercase baba
Posts: 12775
51
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as a general rule, you would not want to use a floating type when dealing with money.  you will inevitably get weird rounding errors.  You would want to deal with whatever your currency's base unit is.  For U.S. dollars, your base unit would be the penny.  so if something costs $8.50, you would want to represent that as 850 (pennies).  When you display it, you can convert it to whatever format you want.  
 
Marshal
Posts: 66637
251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Has nobody noticed there is a more serious error about the price field?
 
Sheriff
Posts: 6456
172
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean like it will never be set?  Only because you said something!
 
Campbell Ritchie
Marshal
Posts: 66637
251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it will remain 0. Of course, if you declare your fields with non‑private access, who knows what other errors might occur.
 
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!