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
2. Reading Information
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.* ;
import java.io.BufferedReader;
import java.io.InputStreamReader;


class JavaApprentice {

public static void main(String args[])

{
InputStreamReader istream = new InputStreamReader(System.in) ;

BufferedReader bufRead = new BufferedReader(istream) ;

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 Your Department Name: ");

String firstDepartment = bufRead.readLine();

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

val1 = Double.parseDouble(bufRead.readLine());;

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

val2 = Double.parseDouble(bufRead.readLine());

System.out.println("Please Enter In Sales: ");

val3 = Double.parseDouble(bufRead.readLine());

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

System.out.println("Please Press Enter!");

String firstEnter = bufRead.readLine();

System.out.println("Please Enter In Your Department Name: ");

String secoundDepartment = bufRead.readLine();

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

val4 = Double.parseDouble(bufRead.readLine());;

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

val5 = Double.parseDouble(bufRead.readLine());

System.out.println("Please Enter In Sales: ");

val6 = Double.parseDouble(bufRead.readLine());

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

System.out.println("Please Press Enter!");

String secoundEnter = bufRead.readLine();

System.out.println("Please Enter In Your Department Name: ");

String thirdDepartment = bufRead.readLine();

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

val7 = Double.parseDouble(bufRead.readLine());;

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

val8 = Double.parseDouble(bufRead.readLine());

System.out.println("Please Enter In Sales: ");

val9 = Double.parseDouble(bufRead.readLine());

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

System.out.println("Please Press Enter!");

String thirdEnter = bufRead.readLine();

System.out.println("Please Enter In Your Department Name: ");

String fourthDepartment = bufRead.readLine();

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

val10 = Double.parseDouble(bufRead.readLine());;

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

val11 = Double.parseDouble(bufRead.readLine());

System.out.println("Please Enter In Sales: ");

val12 = Double.parseDouble(bufRead.readLine());

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

System.out.println("Please Press Enter!");

String pressEnter = bufRead.readLine();

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));

String pleaseContinue = bufRead.readLine();

}

catch (IOException err) {

System.out.println("Error reading line");

}

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...

Recommended Answers

All 7 Replies

You have to specify what you need help with. Frankly, nobody here wants to sort through your project description and your code to figure out why you're having trouble. If you want help you need to make the effort yourself. You should start by dividing your code into logical units (for example, if you were doing an ATM program, you might have these 'logical units': menu selection, withdraw money, deposit money, check account balance). It looks like you're too far into your program to do that now, so if you did, great. In any case, identify what portion of your code doesn't work and post that section of code, including what it is supposed to do and why it doesn't work. Ask specific questions. If your program is simply missing a section of code that it needs, write it and if you have problems, then ask us. I'm more than willing to help, but it doesn't seem like you really asked anything other than to have your work done for you. If this isn't the case than please elaborate.

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.* ;
import java.io.BufferedReader;
import java.io.InputStreamReader;


class JavaApprentice {

public static void main(String args[])

{
InputStreamReader istream = new InputStreamReader(System.in) ;

BufferedReader bufRead = new BufferedReader(istream) ;

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 Your Department Name: ");

String firstDepartment = bufRead.readLine();

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

val1 = Double.parseDouble(bufRead.readLine());;

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

val2 = Double.parseDouble(bufRead.readLine());

System.out.println("Please Enter In Sales: ");

val3 = Double.parseDouble(bufRead.readLine());

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

System.out.println("Please Press Enter!");

String firstEnter = bufRead.readLine();

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

String pleaseContinue = bufRead.readLine();

}

catch (IOException err) {

System.out.println("Error reading line");

}

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.

So I should add:???
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 Your Department Name: ");

String firstDepartment = bufRead.readLine();

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

val1 = Double.parseDouble(bufRead.readLine());;

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

val2 = Double.parseDouble(bufRead.readLine());

System.out.println("Please Enter In Sales: ");

val3 = Double.parseDouble(bufRead.readLine());
}

*This work?

To answer your question about the equation:
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.

Overall comments about your code
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.

The Answer is solved!

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.* ;
import java.io.BufferedReader;
import java.io.InputStreamReader;


class JavaApprentice {

     public static void main(String args[])

     {
          InputStreamReader istream = new InputStreamReader(System.in) ;

          BufferedReader bufRead = new BufferedReader(istream) ;

          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 Your Department Name: ");

               String firstDepartment = bufRead.readLine();

               System.out.println("Please Enter In The # of Employees: ");
               
               val1 = Double.parseDouble(bufRead.readLine());;

               System.out.println("Please Enter In The Cost Per Employee: ");         
               
               val2 = Double.parseDouble(bufRead.readLine());

               System.out.println("Please Enter In Sales: ");
               
               val3 = Double.parseDouble(bufRead.readLine());

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

               System.out.println("Please Press Enter!");
               
               String firstEnter = bufRead.readLine();

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

           }
 
          }

          catch (IOException err) {

               System.out.println("Error reading line");

          }

          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.