0

I'm designing a program that will help a user determine what GPU, CPU and RAM to buy based on their budget and use case for their PC. I've gone about this by letting them choose from a list of use cases and budgets in a JComboBox in a GUI class, then fed that information into a backend class to do the "work" with it. It receives the information from the GUI class perfectly, but the math doesn't seem to want to work for some reason.
Here is my code:
Backend Class:

package computerapp;

public class Configurator {
    
    private final String useCase;
    private double totalBudget, gpuBudget, cpuBudget, ramBudget, gpuBMin, gpuBMax, 
                cpuBMin, cpuBMax, ramBMin, ramBMax;
    
    Configurator(String inUseCase, double inBudget) {
        
        useCase = inUseCase;
        totalBudget = inBudget;
        
    }
    
    public void BudgetSort() {
               
        if (useCase.equals("Gaming")) {
            gpuBudget = (0.35*totalBudget);
            cpuBudget = (0.2*totalBudget);
            ramBudget = (0.1*totalBudget);
        }
        
        if (useCase.equals("General Processing Tasks")) {
            gpuBudget = 0.05 * totalBudget;
            cpuBudget = 0.4 * totalBudget;
            ramBudget = 0.15 * totalBudget;
        }
        
        if (useCase.equals("Video Editing")) {
            gpuBudget = 0.4 * totalBudget;
            cpuBudget = 0.25 * totalBudget;
            ramBudget = 0.2 * totalBudget;
        }
        
        if (useCase.equals("3D Modelling")) {
            gpuBudget = 0.4 * totalBudget;
            cpuBudget = 0.3 * totalBudget;
            ramBudget = 0.2 * totalBudget;
        }
        
        gpuBMin = gpuBudget - (5/100 * gpuBudget);
        gpuBMax = gpuBudget - (5/100 * gpuBudget);
        
        cpuBMin = cpuBudget - (5/100 * cpuBudget);
        cpuBMax = cpuBudget + (5/100 * cpuBudget);
        
        ramBMin = ramBudget - (5/100 * ramBudget);
        ramBMax = ramBudget + (5/100 * ramBudget);
    }

public void Configuration() {
        
        System.out.println(totalBudget);
        System.out.println(useCase);
        System.out.println(gpuBudget);
        System.out.println("GPU BUDGET: R" + gpuBMin + " - R" + gpuBMax);
    }
    
}

This is the code in the GUI class:

private void btnConfiguratorOutputMouseClicked(java.awt.event.MouseEvent evt) {                                                   
        
        String useCase = cbxUseCase.getSelectedItem().toString();
        double budget = Double.parseDouble(cbxBudget.getSelectedItem().toString());
        
        Configurator configure = new Configurator(useCase, budget);
        configure.Configuration();
        
    }

I used the outputs in the Configurator() class to help me troubleshoot. It knows what use case was selected and outputs it correctly, and the same for the totalBudget, but the individual budgets don't work; they are outputted as 0,0.
I plan on linking the program to a database with information on these components, which is the reason for the BMin and BMax fields - to incorporate into a SQL statement.

Zayaan
  • 1
  • 2
  • I think you should check if your code goes into one of your `if` blocks. It could be that you have a typo somewhere and none of your `if` conditions gets `true`. – JANO Aug 06 '22 at 10:01
  • 1
    5/100 uses integers and so the result is zero. – tgdavies Aug 06 '22 at 10:59
  • Please edit your question to include a complete, runnable example which reproduces the problem. – tgdavies Aug 06 '22 at 11:02

0 Answers0