HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaMinor

Business program for a computer shop

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
businessprogramforcomputershop

Problem

Any advice would be great. I watched a few videos over the last 3 weeks and made a program up; what do you think?

The program is a business ideal for a few computers in a shop, some computers with training and the rest of the computers without. (for gaming, etc.)

```
import java.util.Scanner;

public class n_com {

public static void main (String args []){

Scanner input = new Scanner (System.in);

double training,p_h,computer_training,computers,open;

double max,two,thre,four,five;
double two2,thre3,four4,five5,p;

System.out.print("please enter cost of training people up on the computer p/h £ ");
training =input.nextDouble();

System.out.print("please enter cost to use the pc p/h for general use £");
p_h=input.nextDouble();

System.out.print("please enter number of computer in the shop for training :");
computer_training =input.nextInt();

System.out.print("please enter number of computer in the shop for general use :");
computers =input.nextInt();

System.out.print("please enter hours open per week :");
open=input.nextDouble();

training = training computer_training open; //max income per week w/training
p_h = p_h computers open; //max income per week (gamers ect)

max = training + p_h;

two =0.2 * max; // 20% max total
thre =0.3 * max; // 30% max total
four =0.4 * max;
five =0.5 * max;

p = 0.45; // % of shop taking paid per week as wages

two2 = p * two; // 45% of the estimated shop taking (two = 0.20% of max)
thre3 = p * thre;
four4 = p * four;
five5 = p * five;

max = (max * 52 / 12);
System.out.println();

System.out.println ("maxim monthly income from the computers £ "+ max);

System.out.println();

System.out.println ("total income estimate

Solution

Wording

First, the terminology you chose seems a bit off. I believe that you are writing this program from the point of view of an entrepreneur or investor in a business, looking to earn income by making computers available for training and general use. Instead of "cost", you should be talking about price.

There are also some spelling mistakes ("Maximum" → "maxim", "number of computers" → "number of computer", and "month" → "mouth").

Misuse of variables

This program is basically a textual spreadsheet that accomplishes this (inputs in italic, outputs in bold):

As such, there are many variables to track, and therefore proper naming is critical to keep track of all of those numbers. More importantly, you should not repurpose a variable midway through the program, as you have done here:

training = training * computer_training * open;


and

max = (max * 52 / 12);


Such reassignments prevent you from naming the variable appropriately, and from reasoning about the code. In fact, the resulting confusion has led to a bug. The assignment two = 0.2 max is based on max as a weekly amount. You subsequently reassigned max = (max 52 / 12) as a monthly amount. You then report two as a monthly amount:

System.out.println("estimated monthly income at mouth 1-3 \t:"+ two );


You would be better off with fewer variables, by eliminating variables two, etc.

Style

Nobody likes to read huge declaration blocks:

double training,p_h,computer_training,computers,open;

double max,two,thre,four,five;
double two2,thre3,four4,five5,p;


Instead, declare the variables at the assignment point.

You can make use of import static to avoid writing System.out everywhere.

import java.util.Scanner;
import static java.lang.System.out;

public class BusinessEstimator {
    public static void main (String args []) {
        try (Scanner input = new Scanner(System.in)) {
            out.print("please enter price of training people up on the computer p/h: £");
            double trainingPrice = input.nextDouble();

            out.print("please enter price to use the pc p/h for general use: £");
            double generalPrice = input.nextDouble();

            out.print("please enter number of computers in the shop for training: ");
            double trainingComputers = input.nextInt();

            out.print("please enter number of computers in the shop for general use: ");
            double generalComputers = input.nextInt();

            out.print("please enter hours open per week: ");
            double hoursPerWeek = input.nextDouble();

            double trainingWeeklyIncome = trainingPrice * trainingComputers * hoursPerWeek;
            double generalWeeklyIncome = generalPrice * generalComputers * hoursPerWeek;
            double maxWeeklyIncome = trainingWeeklyIncome + generalWeeklyIncome;
            double maxMonthlyIncome = maxWeeklyIncome * 52 / 12;

            double WAGES_PCT = 0.45;  // % of shop taking paid as wages

            out.println();

            out.println ("maximum monthly income from the computers £ "+ maxMonthlyIncome);
            out.println();

            out.println ("total income estimated over the next 2 years");
            out.println();

            out.println("estimated monthly income at month 1-3 \t:"+ 0.2 * maxMonthlyIncome);
            out.println("estimated monthly income at month 3-6 \t:"+ 0.3 * maxMonthlyIncome);
            out.println("estimated monthly income at month 6-12\t:"+ 0.4 * maxMonthlyIncome);
            out.println("estimated monthly income at year  1-2 \t:"+ 0.5 * maxMonthlyIncome);
            out.println();

            out.println("wages will be 45% of total income at the end of each month" );
            out.println();

            out.println("estimated monthly wages for month 1 - 3  £ "+ 0.2 * WAGES_PCT * maxMonthlyIncome);
            out.println("estimated monthly wages for month 4 - 6  £ "+ 0.3 * WAGES_PCT * maxMonthlyIncome);
            out.println("estimated monthly wages for month 7 - 12 £ "+ 0.4 * WAGES_PCT * maxMonthlyIncome);
            out.println("estimated monthly wages after the first year £"+ 0.5 * WAGES_PCT * maxMonthlyIncome);
        }
    }
}

Code Snippets

training = training * computer_training * open;
max = (max * 52 / 12);
System.out.println("estimated monthly income at mouth 1-3 \t:"+ two );
double training,p_h,computer_training,computers,open;

double max,two,thre,four,five;
double two2,thre3,four4,five5,p;
import java.util.Scanner;
import static java.lang.System.out;

public class BusinessEstimator {
    public static void main (String args []) {
        try (Scanner input = new Scanner(System.in)) {
            out.print("please enter price of training people up on the computer p/h: £");
            double trainingPrice = input.nextDouble();

            out.print("please enter price to use the pc p/h for general use: £");
            double generalPrice = input.nextDouble();

            out.print("please enter number of computers in the shop for training: ");
            double trainingComputers = input.nextInt();

            out.print("please enter number of computers in the shop for general use: ");
            double generalComputers = input.nextInt();

            out.print("please enter hours open per week: ");
            double hoursPerWeek = input.nextDouble();

            double trainingWeeklyIncome = trainingPrice * trainingComputers * hoursPerWeek;
            double generalWeeklyIncome = generalPrice * generalComputers * hoursPerWeek;
            double maxWeeklyIncome = trainingWeeklyIncome + generalWeeklyIncome;
            double maxMonthlyIncome = maxWeeklyIncome * 52 / 12;

            double WAGES_PCT = 0.45;  // % of shop taking paid as wages

            out.println();

            out.println ("maximum monthly income from the computers £ "+ maxMonthlyIncome);
            out.println();

            out.println ("total income estimated over the next 2 years");
            out.println();

            out.println("estimated monthly income at month 1-3 \t:"+ 0.2 * maxMonthlyIncome);
            out.println("estimated monthly income at month 3-6 \t:"+ 0.3 * maxMonthlyIncome);
            out.println("estimated monthly income at month 6-12\t:"+ 0.4 * maxMonthlyIncome);
            out.println("estimated monthly income at year  1-2 \t:"+ 0.5 * maxMonthlyIncome);
            out.println();

            out.println("wages will be 45% of total income at the end of each month" );
            out.println();

            out.println("estimated monthly wages for month 1 - 3  £ "+ 0.2 * WAGES_PCT * maxMonthlyIncome);
            out.println("estimated monthly wages for month 4 - 6  £ "+ 0.3 * WAGES_PCT * maxMonthlyIncome);
            out.println("estimated monthly wages for month 7 - 12 £ "+ 0.4 * WAGES_PCT * maxMonthlyIncome);
            out.println("estimated monthly wages after the first year £"+ 0.5 * WAGES_PCT * maxMonthlyIncome);
        }
    }
}

Context

StackExchange Code Review Q#79026, answer score: 4

Revisions (0)

No revisions yet.