This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2016/8/18

tell me what I am missing here, practicing but need some help

1
2
divinity divinity

2016/8/18

#
hi I havent been here for a long time. I really need some help. This program is just a practice on object oriented programming, dont have a fully understanding as yet but am trying. I am doing this loan officer program. I dont know if I did the right thing, but am getting nothing as the output. the other problem is, can you show me an example of a constructor and how do i get a constructor to work. here is the codes, can u just tell me what else I am missing there and how to fix it. I
import java.util.Scanner;

public class Loan
{
    public static void main(String[]args)
    {
        Scanner scnr = new Scanner(System.in);
    }
    private String loanOfficerID;
    private String fullName;
    private String lastName;
    private double loanInterest;
    private double fixedSalary;
    private double grossPay;
    private final double healthSurcharge = 8.50;
    private double totalDeduction;
    private double NIS;
    private double netpay;
    private double hoursWork;
    private double rateOfpay;
    
    HealthSurcharge hs = new HealthSurcharge();
    
    
    
    public String loanOfficerID()
    {
        return loanOfficerID;
    }
    public void setloanOfficerID(String loanOfficerID)
    {
        this.loanOfficerID = loanOfficerID;
    }
    public String getfullName()
    {
        return fullName;
    }
    public void setfullName(String fullName)
    {
        this.fullName = fullName;
    }
    public String getlastName()
    {
        return lastName;
    }
    public void setlastName(String lastName)
    {
        this.lastName = lastName;
    }
    public double gethoursWork()
    {
        hoursWork = hoursWork * rateOfpay;
        return hoursWork;
    }
    public void sethourWork(double hoursWork)
    {
        this.hoursWork = hoursWork;
    }
    public double getloanInterest()
    {
        loanInterest = loanInterest * 0.3;
        grossPay = loanInterest - grossPay;
        
        return loanInterest;
    }
    public void setloanInterest(double loanInterest)
    {
        this.loanInterest = loanInterest;
    }
    public double getfixedSalary()
    {
        fixedSalary = fixedSalary - grossPay;
        return fixedSalary;
    }
    public void setfixedSalary(double fixedSalary)
    {
        this.fixedSalary = fixedSalary;
    }
    public double gettotalDeduction()
    {
        totalDeduction = NIS + healthSurcharge;
        
        return totalDeduction;
    }
    public void settotalDeduction(double totalDeduction)
    {
        this.totalDeduction = totalDeduction;
    }
    public double getnetpay()
    {
        netpay = totalDeduction - grossPay;
        
        return netpay;
    }
    
    public void details()
    {
        System.out.println("The loan officer id number is: "+loanOfficerID);
        System.out.println("The loan officer full name is: "+fullName);
        System.out.println("The loan officer last name is: "+lastName);
        System.out.println("The gross pay is: "+grossPay);
        System.out.println("The total deduction is: "+totalDeduction);
        System.out.println("The netpay is: "+netpay);
        
    }

}
 and this is the health surcharge class dont know if it this is the correct way to make a constructor please help 

class HealthSurcharge 
{
    HealthSurcharge hs = new HealthSurcharge();//dont kno if this is the correct thing
    
}
danpost danpost

2016/8/18

#
Line 112, as written, will cause an inescapable execution of code. As soon as a HealthSurcharge object is created (which is first done when a Loan object is created), that line will execute to create another, which executes the line again ... and again, and again. Hence, why there is no output -- the processing never gets to those print lines (it never actually completes creating the first HealthSurcharge object; or, the Loan object, for that matter). From what I can tell with what is given, I do not see a need for a constructor for the HealthSurcharge class. In fact, I cannot tell what the purpose of the class is, at all. You should explain, in detail, what a HealthSurcharge object is to be used for (describe its possible states and what behaviors it should exhibit).
divinity divinity

2016/8/18

#
I thought that could have been used to help with the calculation of the total deduction in order to get the netpay. when I made the health surcharge object, I got an error message stating that I should make a health surcharge class, that was how I ended up making it.
divinity divinity

2016/8/18

#
I remove it and i am still getting no output
danpost danpost

2016/8/18

#
divinity wrote...
I remove it and i am still getting no output
Where are you creating a Loan object from (where is 'new Loan()' within your code)? The only thing in your 'main' method is the creation of a Scanner object, which makes everything else in the class (except for the import statement for the Scanner class) ignored. The rest of the code basically requires that a Loan object be created somewhere.
divinity divinity

2016/8/18

#
I created it or is this the way to create it. and still getting no output have I created it in the right positon, and what else do i have to do to get it to work
public static void main(String[]args)
    {
        Scanner scnr = new Scanner(System.in);
        
         Loan loan = new Loan();
    }
    private String loanOfficerID;
    private String fullName;
    private String lastName;
    private double loanInterest;
    private double fixedSalary;
    private double grossPay;
    private final double healthSurcharge = 8.50;
    private double totalDeduction;
    private double NIS;
    private double netpay;
    private double hoursWork;
    private double rateOfpay;
    
   
    
    
    public String loanOfficerID()
    {
        return loanOfficerID;
    }
    public void setloanOfficerID(String loanOfficerID)
    {
        this.loanOfficerID = loanOfficerID;
    }
    public String getfullName()
    {
        return fullName;
    }
    public void setfullName(String fullName)
    {
        this.fullName = fullName;
    }
    public String getlastName()
    {
        return lastName;
    }
    public void setlastName(String lastName)
    {
        this.lastName = lastName;
    }
    public double gethoursWork()
    {
        hoursWork = hoursWork * rateOfpay ;
        return hoursWork;
    }
    public void sethourWork(double hoursWork)
    {
        this.hoursWork = hoursWork;
    }
    public double getloanInterest()
    {
        loanInterest = loanInterest * 0.3;
        grossPay = loanInterest - grossPay;
        
        return loanInterest;
    }
    public void setloanInterest(double loanInterest)
    {
        this.loanInterest = loanInterest;
    }
    public double getfixedSalary()
    {
        fixedSalary = fixedSalary - grossPay;
        fixedSalary = fixedSalary * 0.5;
        return fixedSalary;
    }
    public void setfixedSalary(double fixedSalary)
    {
        this.fixedSalary = fixedSalary;
    }
    public double gettotalDeduction()
    {
        totalDeduction = NIS + healthSurcharge;
        
        return totalDeduction;
    }
    public void settotalDeduction(double totalDeduction)
    {
        this.totalDeduction = totalDeduction;
    }
    public double getnetpay()
    {
        netpay = totalDeduction - grossPay;
        
        return netpay;
    }
    
    public void details()
    {
        System.out.println("The loan officer id number is: "+loanOfficerID);
        System.out.println("The loan officer full name is: "+fullName);
        System.out.println("The loan officer last name is: "+lastName);
        System.out.println("The gross pay is: "+grossPay);
        System.out.println("The total deduction is: "+totalDeduction);
        System.out.println("The netpay is: "+netpay);
        
    }
danpost danpost

2016/8/18

#
You need to continue (after creating the Loan object) with getting the input via keyboard (using the 'scnr' object) and assigning the fields of the Loan object accordingly (using the "setter" methods of the loan class), after which the 'details' method would need to be called to display the results.
divinity divinity

2016/8/19

#
oh shuck inno danpost I made a mistake, it was supposed to be loanInterest not a loan, how do i make an loanInterest object without getting an error, without it telling me to make a loanInterest class
divinity divinity

2016/8/19

#
when I created it it is telling me to create a loanInterest class in loan package or create a class in loan,
danpost danpost

2016/8/19

#
divinity wrote...
when I created it it is telling me to create a loanInterest class in loan package or create a class in loan,
It does no good to say you need to make a class. You should explain, in detail, what an object of the class is to be used for (describe its possible states and what behaviors it should exhibit). However, it sounds to me (although I could be mistaken as to what you want) that 'loanInterest' would be a value, which can be held by a simple 'float' field; not an Object that a class is needed for.
divinity divinity

2016/8/31

#
hi danpost guide me thru this, I want in another programming forum for a second opion on dis same program that i am practicing on, the answer I received from one of the members is that I have a load of get methods that changes the values of my variables. ah was also told that calculated variable should not have setter methods(is this true) and to do the calulation should be done inside their getter methods. I was told also in order to see my calculation I would have to called the method that produces the output which is the details() methods,(how do I accomplish dis) kinda having ah difficult time understanding it as I am now getting to kno object program, I tried something else but was still not getting any output which I thought is what he meant (obvisously ah wasnt) so i tried again doing it as he said, using the getter method to do the calculation and yet again no output, what am I missing here, pray do tell, how do i called the details method to get the required output. how do i make dis ting work. here is what i have done again need some help plzzzzzzzzzz thanks in advance. what am i doing wrong here.
public static void main(String[]args)
    {
        Scanner scnr = new Scanner(System.in);
        
         Loan loan = new Loan();
         loan.getloanInterest();
    }
    
    private String OfficerID, fullName, lastName;
    private double loanInterest;
    private double fixedSalary;
    private double grossPay;
    private final double healthSurcharge = 8.50;
    private double TotalDeduction;
    private double netpay;
    private double hoursWork;
    private double rateOfpay;
    private double NIS;
    private double hrs;
    

    public String getOfficerID()
    {
        return OfficerID;
    }
    public void setOfficerID(String OfficerID)
    {
        this.OfficerID = OfficerID;
    }
    public String getfullName()
    {
        return fullName;
    }
    public void settfullName(String fullName)
    {
        this.fullName = fullName;
    }
    public String getlastName()
    {
        return lastName;
    }
    public void setlastName(String lastName)
    {
        this.lastName = fullName;
    }
    public double gethoursWork()
    {
         hrs = hoursWork * rateOfpay;
        
        return hoursWork;
    }
    public double getloanInterest()
    {
        loanInterest = loanInterest * 0.3/100;
        
        return loanInterest;
    }
    public double getgrossPay()
    {
        grossPay = loanInterest - grossPay;
        
        return grossPay;
    }
    public double getfixedSalary()
    {
        fixedSalary = fixedSalary + grossPay;
        
        return fixedSalary;
    }
    public double getTotalDeduction()
    {
        TotalDeduction = healthSurcharge + NIS;
        
        return TotalDeduction;
    }
    public double getnetpay()
    {
        netpay = grossPay - TotalDeduction;
        
        return netpay;
    }
    public void details()
    {
        System.out.println("The loan officer ID number is: "+OfficerID);
        System.out.println("The loan officer full and last name is: "+ fullName+" "+ lastName);
        System.out.println("The total deduction is:"+TotalDeduction);
        System.out.println("The gross pay is:$"+grossPay);
        System.out.println("The netpay is:$ "+netpay);
    }
danpost danpost

2016/8/31

#
divinity wrote...
guide me thru this
It would help if you show the entire class code (imports, the class declaration line, et al.). However, for now, I can say that just getting a loanInterest value is just not going to do it. I mean, if that is all you are going to do in the main method, then no more will be done. A program begins with the main method and it ends with the completion (or the final exit out of) the main method. Everything that your program will do stems from the main method. Right now, your program consists of creating Loan object and getting, not even assigning the value to a variable, the value of the loanInterest field of that Loan object. If you want to do more (which, obviously, you do), you will need to put more code in the main method.
danpost danpost

2016/8/31

#
To clarify about line 6 in the main method (the line that gets the 'loanInterest' value from the Loan object created from line 5), The line by itself does not really do anything that represents any progress in your program. It is equivalent to any of the following lines:
256;
true;
false;
new Actor(){};
16*16;
null;
if (true){}
Sure, some code may be executed, or the cpu may actually do something like create an object or do some calculation, but the result of what it does is irrelevant as nothing is actually done with that result. It is not saved to a variable or field for use later and not immediately used for anything. As soon as the execution proceed to the next line, if there is one, that value is inaccessible (unless you call 'getLoanInterest' on that Loan object again).
danpost danpost

2016/8/31

#
danpost wrote...
It would help if you show the entire class code (imports, the class declaration line, et al.)
You can ignore this as you had done so in a previous posting in this discussion thread.
divinity divinity

2016/9/2

#
I did not ignore this danpost. that is all the codes there from the beginning. as you say, i have to put in more codes for it to work and give it values but what, i dont know, do I n to remove this: Loan loan = new Loan(), if so I would like to know. how do I put values in the variable for it to work
There are more replies on the next page.
1
2