Unable to designate a particular value to a variable

For a recent project, I was tasked with implementing servlet handling to calculate the net pay salary of an employee based on user input. While most of the information was processing correctly, I encountered an issue when attempting to determine the rate. Instead of displaying the assigned hourly rate based on the user's input for position, the output was showing as 0. Below is a snippet of the code I have been working on: {

private int rate;
private int grosspay;
private int sss;
private double philhealth;
private double pagibig;
private double tax;
private double deductions;

private int bonus;
private double netpay;


public ComputeBean()
{}

public void setEmployeeid(int employeeid)
{
    this.employeeid = employeeid;
}

public int getEmployeeid()
{
    return employeeid;
}

public void setEmployeename(String employeename)
{
    this.employeename = employeename;
}

public String getEmployeename()
{
    return employeename;
}

public void setDepartment(String department)
{
    this.department = department;
}

public String getDepartment()
{
    return department;
}

public void setHour(int hour)
{
    this.hour = hour;
}

public int getHour()
{
    return hour;
}

public void setCategory(String category)
{
    this.category = category;
}

public String getCategory()
{
    return category;
}

public void setPosition(String position)
{
    this.position = position;
}

public String getPosition()
{
    return position;
}

private void setRate(int rate) 
{}

public void computeRate(int rate)
{
    getPosition();

    if(position.equals("clerk"))
    {
        setRate(rate = 100);
    }

    else if(position.equals("sup"))
    {
        setRate(rate = 200);
    }

    else if(position.equals("mana"))
    {
        setRate(rate = 300);
    }

    else if(position.equals("exec"))
    {
        setRate(rate = 500);
    }
}

public int getRate()
{
    return rate;
}

} }

Answer №1

To properly utilize a setter, simply provide the value to be set as shown below

if(position.equals("exec"))
{
    setRate(500);
}

It is essential that your setter method performs the desired action!

private void setRate(int rate) 
{
    this.rate = rate;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Width of ListBox Item

How can I adjust the width of items in my RadListBox that are being inserted programmatically to prevent multiple items from displaying on a single line? Currently, the items are added to the listbox in C# code like this: rlbAssigned.Items.Add(new RadLis ...

Utilizing a 100% width Bootstrap form with SelectBoxIt inputs

Utilizing SelectBoxIt inputs () in Bootstrap 3 horizontal forms is causing an issue. I want the input to adjust and collapse along with the form width, but setting the widths to 100% is causing them to collapse instead. To demonstrate the problem, I' ...

Hover effect for child element not activating CSS3 Transition

I need my list item to activate a css3 transition on its child element .pusher when it is hovered over. I usually achieve this using JS, but I want to try implementing it with css3 transitions. After reading some other questions on SO, I attempted to do it ...

"What is the most efficient method to display or hide multiple divs using

Hey, I'm trying to figure out how to work with showing or hiding multiple div elements quickly. Do I really need to number each div like "open,close,show_text"? It seems a bit repetitive if I have to do it for each div 10 times. Open 1 Close 1 hell ...

Difficulty executing for loop due to multiple buttons, resulting in malfunctioning buttons in JavaScript code

Currently encountering an issue while trying to implement modal windows on my first website. Everything works fine without the for loop, but I wanted to have multiple buttons and windows, so I decided to use a for loop to handle each button. Strangely, the ...

In PHP, my goal is to extract the XML ID when a button is clicked and display its contents on a separate page

I need assistance with extracting the ID from the hotellist.php page using XML. As I am relatively new to XML, I am unsure of how to achieve this. Can someone please provide a detailed explanation? <?php $xml=simplexml_load_file("data.xml") or die("Err ...

Utilizing multiple address parameters within a single-page application

Apologies for the lengthy post. I have encountered an issue with my code after running it through a bot that I can't seem to resolve. In my code, I aim to create functionality where you can visit the address #two, followed by two separate parameters ...

Create a left-aligned div that spans the entire width of the screen, adjusting its width based on the screen size and positioning it slightly

I have a parent container with two child elements inside. I want the first child to align to the left side and the second child to align to the right side, but not starting from the exact center point. They should be positioned slightly off-center by -100p ...

Creating a split hero section view using a combination of absolute/relative CSS techniques, Tailwind, and React

I'm in the process of creating a website using Nextjs, React, and TailwindCSS, and I aim to design a Hero section that resembles the one on the following website. https://i.sstatic.net/tq3zW.png My goal is to: Have a text title and buttons on the l ...

Issue with ListActivity within Tab Layout on Android

Sorry if this question has been asked before, but I couldn't find a solution anywhere. I've been following the android development tutorial to create a tabbed UI with separate activities for each tab. Everything was working perfectly until... N ...

Stop storing CSS data for nopCommerce

Currently, I am looking for a method to avoid caching CSS files on my nopCommerce website. In the past, I have achieved this by adding the date and another element at the end of the CSS call. Html.AppendCssFileParts("~/Themes/CustomTheme/Content/css/site. ...

Looking to implement a scroll bar in your PhoneGap mobile app for Android?

Encountering an issue with my Android PhoneGap mobile website application. I have implemented a scroll bar in the application which works perfectly on PC. However, when testing on an Android device (mobile phone), the scroll bar does not enable. ...

Is it possible to have the Save Success Alert fade out only once?

After incorporating this code snippet, I implemented a fade effect on the success alert whenever it is triggered. However, I noticed that the fade effect only occurs the first time I click "save". Subsequent clicks do not trigger the fade effect, causing ...

How to combine two arrays and sort them in ascending order using Java

As part of a project, I need to develop a method that merges two arrays into one sorted array in ascending order. While most of the code is working fine, there's a bug that's causing the last element in the merged array to be replaced with 0. Has ...

Storing data collected from a Google form into an Excel spreadsheet

I have created a form using table layout. My goal is to automatically shift the focus to the next input field once the current one reaches its maximum length. I tried implementing this functionality with jQuery, but it only seems to work with inputs and no ...

By simply clicking a button in a React component, I aim to alter the font style of the text

function makeTextBold() { const boldText = document.querySelector('.form-control'); boldText.style.fontWeight = 'bold'; setText(boldText); } When I click the button, it redirects me to a blank page in the browser. ...

What is the best way to run Selenide with Chrome using ChromeDriver?

After recently exploring selenide (selenium wrapper api), I can attest to its effectiveness as a tool. However, one challenge I have encountered is the lack of comprehensive documentation and usage examples available online. Can anyone provide guidance on ...

Is it possible to find and replace text within an HTML file using PHP after reading it?

I'm currently working on designing an email template and utilizing preg_replace to replace specific words in the content. Since I am new to PHP, I find myself unsure about the technical details involved. My intention is for the code to read an HTML/CS ...

Experiencing difficulty in storing django forms into sqlite

I am currently grappling with Django as I work on a new program that's still in the development phase. This is my first time working with Django and I am facing some challenges. My main issue lies in attempting to save a few form fields to a sqlite d ...

Initial size of ArrayList not functioning as expected

For my project, I decided to create a stack class named StackOfBook. Since I needed 2 stacks, I instantiated them in my main class like this: StackOfBook stack1 = new StackOfBook(); while (true) { long number = sc.nextLong(); if (number == -1) { ...