Here is the Data:

Department Name: Cool Casino
# of Employees: 543
Cost Per Employee: 0.75
Sales: 1000.432

Department Name: Trumpola Burgers
# of Employees: 43
Cost Per Employee: 19.725
Sales: 50

Department Name: Donoldio Clothing for Cats
# of Employees: 4.0001
Cost Per Employee: 5.233
Sales: 100

Department Name: Trumpola Leaning Tower
# of Employees: 1003
Cost Per Employee: 1.2123
Sales: 704.67

Bonus: Use a loop to ask how many departments Donaldio would like entered and then loop through that many requests!

Further Explanation of Assignment:

In this assignment you will use the concepts you have learned from "Input and Output."

1. Importing Packages
3. Converting Information
4. Formatting Output

Assignment Background:

Billionaire Donaldio Trumpola has hired you to help him run his many businesses. He has so many staff members in so many different companies that he is losing track of them all. What he would like you to do, is write a program, that he can use to enter in the information about his companies. He will want to input the following information for each department:

Department Name:
Employees:
Cost Per Employee:
Sales:

Below is the data he would like you to enter (you didn't think he would enter it himself did you?) Write your program to handle the amount of information that needs to be inputted. You do not need to use a loop, you can simply have multiple requests to ".readLine()" .

Finally, Donaldio would like your program to use all the information inputted to find out if he has made any money, or if he is bankrupt. Calculate the cost to run each department, and compare that to the sales for the department, come up with a total, and present all your numbers in a nice output that has been formatted - using the technique you have learned in the notes - to show money with two decimal places, comma's and a dollar sign. In the output you should present the statistics for each department, and the statistic for all departments.

The Code:

-------------------------------------------------------------------------------------------------

import java.io.* ;

class JavaApprentice {

public static void main(String args[])

{

System.out.println("Welcome To Java Apprentice!");

double val1 = 00.00;
double val2 = 00.00;
double val3 = 00.00;
double val4 = 00.00;
double val5 = 00.00;
double val6 = 00.00;
double val7 = 00.00;
double val8 = 00.00;
double val9 = 00.00;
double val10 = 00.00;
double val11 = 00.00;
double val12 = 00.00;
double val14 = 00.00;
try

{

System.out.println("Please Enter In The # of Employees: ");

System.out.println("Please Enter In The Cost Per Employee: ");

System.out.println("You're " + firstDepartment + ", Profit is: " + "\$" + (val1 * val2 - val3));

System.out.println("Please Enter In The # of Employees: ");

System.out.println("Please Enter In The Cost Per Employee: ");

System.out.println("You're " + secoundDepartment + ", Profit is: " + "\$" + (val4 * val5 - val6));

System.out.println("Please Enter In The # of Employees: ");

System.out.println("Please Enter In The Cost Per Employee: ");

System.out.println("You're " + thirdDepartment + ", Profit is: " + "\$" + (val7 * val8 - val9));

System.out.println("Please Enter In The # of Employees: ");

System.out.println("Please Enter In The Cost Per Employee: ");

System.out.println("You're " + fourthDepartment + ", Profit is: " + "\$" + (val10 * val11 - val12));

System.out.println("Hello, Donaldio. Your Final Financial Profit of all Departments are: " + "\$" + (val1 * val2 - val3 + val4 * val5 - val6 + val7 * val8 - val9 + val10 * val11 - val12));

}

catch (IOException err) {

}

catch(NumberFormatException err) {

System.out.println("Error Converting Number");

}

}

}

-------------------------------------------------------------------------------------

I have handed it in and gotten this reply from my teacher:

1) Profit = Sales -Cost (you have the incorrect equation)

2) Your program must handle multiple departments and give the final financial position for Donaldio.

It does work otherwise, but lacks the inhibition of what he says is the wrong equation and I need to handle multiple departments. So what am I doing wrong? *looking for simple Java, Nothing beyond If Else Etc...

The problem is the teacher wants multiple departments to be done, a simple loop command that is never ending? And the equation is wrong. Profit = Sales -Cost (you have the incorrect equation) So do forgive me if I don't know calculus as well as you would.

The code works otherwise. However the equation is wrong and I need a simple code to do a loop. *the code is easy to read. You just seem to miss my point I guess.

And I am not asking for people to do my assignment for me, as seen its pretty much done. The question is what does my teacher mean by:

1) Profit = Sales -Cost (you have the incorrect equation)

2) Your program must handle multiple departments and give the final financial position for Donaldio.

What is the proper equation? And how would I input a loop command to do x amount of departments? Or a infinite amount?

I have done my work, this project is making me block and frustrates me. Every time I submit he wants me to redo it. If someone who actually can help please tell me, which is the reason why I came here. For knowledge on programming so I myself can start somewhere too.

Sorry if I seem ignorant, almost 5am. Plus I don't feel as welcomed as I'd hoped either.

import java.io.* ;

class JavaApprentice {

public static void main(String args[])

{

System.out.println("Welcome To Java Apprentice!");

double val1 = 00.00;
double val2 = 00.00;
double val3 = 00.00;

try

{

System.out.println("Please Enter In The # of Employees: ");

System.out.println("Please Enter In The Cost Per Employee: ");

System.out.println("You're " + firstDepartment + ", Profit is: " + "\$" + (val1 * val2 - val3));

System.out.println("Hello, Donaldio. Your Final Financial Profit of all Departments are: " + "\$" + (val1 * val2 - val3));

}

catch (IOException err) {

}

catch(NumberFormatException err) {

System.out.println("Error Converting Number");

}

}

}

You don't sound ignorant and that is not what I was suggesting. You sounded like you want a ready made solution, but that isn't what we help with. For the profit comment your teacher is simply telling you that you have the wrong equation. It isn't calculus. And it appears that your teacher gave you the correct equation (Sales - Cost = Profit). You just need to implement that in your code.

What is the proper equation? And how would I input a loop command to do x amount of departments? Or a infinite amount?

You could have a do while loop that requests the user to enter information or Q to quit, and if the user entered Q, you would exit the do while loop. And I would think what the teacher wrote to you is the proper equation - what is the equation you used? I looked through your code but what I see is nowhere near Profit = Sales-cost.

You don't sound ignorant and that is not what I was suggesting. You sounded like you want a ready made solution, but that isn't what we help with. For the profit comment your teacher is simply telling you that you have the wrong equation. It isn't calculus. And it appears that your teacher gave you the correct equation (Sales - Cost = Profit). You just need to implement that in your code.

So:

System.out.println("You're " + firstDepartment + ", Profit is: " + "\$" + (val1 * val2 - val3));

It should be Val 2 - Val 3? Not x employees X cost per - sales? *Should just be employees - sales? *This is my dilemma. Its a real pain in the butt! I am asking in code form what is the proper way to do it? IE: (val1 * val2 - val3)); *which seems wrong, so what is right?

You could have a do while loop that requests the user to enter information or Q to quit, and if the user entered Q, you would exit the do while loop.

for (i = 1; i <= 100; i = i + 1)
{
System.out.println(i);
}
*I need any specific IO packages? Plus could I have 4 Departments calculate one mass final outcome if in a loop?

Example:

for (i = 1; i <= 100; i = i + 1)
{
ouble val1 = 00.00;
double val2 = 00.00;
double val3 = 00.00;

System.out.println("Please Enter In The # of Employees: ");

System.out.println("Please Enter In The Cost Per Employee: ");

}

*This work?

According to your project description, Profit per department = Sales for that department - Cost for that department. Since the data you are provided with is cost per employee and total number of employees, Cost per department = (Cost per employee in that department)(Total number of employees in that department). You are already given the sales. Total profit is the profit for each department added up.

In code form, things are done the same way as they are logically. If your equation was Force = Mass * Acceleration, you would have the following code:

``````double force = 0;
double mass = 10;
double acceleration = 1.5;

force = mass * acceleration;

//Force is now equal to 15.``````

Java is an Object Oriented Programming Language. At the lowest level, think about being "Object Oriented" like this: If you were to program a Car program in Java, the "Car" would be represented as an object. The car would itself be an object, and it would contain other objects such as a Steering Wheel, Seat, Radio, Engine, etc. Objects are represented in Java by classes. For example,

``````public class Car{
int height;
int weight;
Engine carEngine;
}``````

And Engine would itself be defined in another class. FYI, this link contains a lot of helpful information: http://java.sun.com/docs/books/tutorial/java/javaOO/index.html. I'm giving you this comment because I think it might be helpful to you to think about each Department as being a class that has a number of employees and a cost per employee and a total sales amount.

Feel free to let me know any other help you need but try to look through some of these things and figure them out on your own first.

In code form, things are done the same way as they are logically. If your equation was Force = Mass * Acceleration, you would have the following code:

``````double force = 0;
double mass = 10;
double acceleration = 1.5;

force = mass * acceleration;

//Force is now equal to 15.``````

Your help with how to show profit helps, and it works too!

("You're " + firstDepartment + ", Profit is: " + "\$" + (profit = val3 - val1 * val2));

("Hello, Donaldio. Your Final Financial Profit of all Departments are: " + profit);

Also I figured out how to make loop commands too!

``````import java.io.* ;

class JavaApprentice {

public static void main(String args[])

{

System.out.println("Welcome To Java Apprentice!");

double val1 = 00.00;
double val2 = 00.00;
double val3 = 00.00;
double profit = 00.00;

try

{

for(int i=1; i<11; i++)

{

System.out.println("Please Enter In The # of Employees: ");

System.out.println("Please Enter In The Cost Per Employee: ");

System.out.println("You're " + firstDepartment + ", Profit is:  " + "\$" + (profit = val3 - val1 * val2));

System.out.println("Hello, Donaldio. Your Final Financial Profit of all Departments are: " + profit);

}

}

catch (IOException err) {

}

catch(NumberFormatException err) {

System.out.println("Error Converting Number");

}

}

}``````

As this thread is solved, Thank you for the tutelage and I will continue to ask for help! :P

I have more to the code *needs 4x departments but provided one for example. Works overall!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.