Note that there are some explanatory texts on larger screens.

plurals
  1. POJava - Constructor woes and System.out.print from within methods
    primarykey
    data
    text
    <p>Hey there, I'm stuck. I've got this hw assignment with 2 problems in the code that I'm at a loss on how to fix. The assignment is mostly nonsense:</p> <pre><code>import java.util.*; class Business { private String name, phone; private int employees, age; void Business(){ name = "Foo Inc."; phone = ""; employees = 0; age = 0; System.out.println("In default constructor!"); printVals(); } void Business(String name, String phone, int employees){ System.out.printf("%s %s %d\n", name, phone, employees); this.name = name; this.phone = phone; this.employees = employees; this.age = 0; System.out.println("In constructor!"); printVals(); } void printVals(){ System.out.printf("name: %s\n", name); System.out.printf("phone: %s\n", phone); System.out.printf("employees: %d\n", employees); System.out.printf("age: %d\n", age); } public static void main(String [] args) { Business[] mall = new Business[5]; String[] names = {"The Gap", "Savers", "Academy of Salon Professionals", "Ron's Farmhouse"}; String[] phones = {"555-555-5555", "555-555-5556", "555-555-5557", "555-555-5558"}; int[] emps = {20, 24, 75, 32}; int i, num = 4; mall[num - 1] = new Business(); for(i = 0; i &lt; num; i++){ mall[i] = new Business(names[i], phones[i], emps[i]); System.out.printf("init Business: %s %s %d\n", names[i], phones[i], emps[i]); } } } </code></pre> <p>And here's the output error from javac:</p> <pre><code>Business.java:51: cannot find symbol symbol : constructor Business(java.lang.String,java.lang.String,int) location: class Business mall[i] = new Business(names[i], phones[i], emps[i]); ^ 1 error </code></pre> <p>I don't see why it's tell me it can't find the constructor. As far as I can tell, the parameters are the same...</p> <p>Let's say I comment out the parameters of the Business() calls, such that it's only calling the default constructor. At least that way it compiles, but then, none of the System.out.print*'s from within the methods will print anything!</p> <p>Any help would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload