I only need help with constructing the mutator method addExpenditure() for the P
ID: 3662264 • Letter: I
Question
I only need help with constructing the mutator method addExpenditure() for the Project class...
This is what I have so far:
public boolean addExpenditure(double amount){
if (true)
projBudget = projBudget.addspending(amount); //this code is wrong
return true;
}
else
{
return false;
}
How can I fix this so it meets the above criteria? I would appreciate any feedback, thanks!
Program Description Class Diagram: -proj Name: String="?" -projNumber int 0 projLocation: String -projBudget: Budget Budget -initialFunding: double spending: double 0.0 currentBalance: double +Project(double) getName:String +getNumberO:int tgetLocationo: String tgetBudgeto: Budget +setName(String):void tgetNumberO:int +setLocation(String): void +addExpenditure(double): boolean String( ): String Budget(double) +addSpending(double):boolean toStringO:String Assignment4 main(String):void printMenuO:void Arizona State University, CSE205, Assignment 4. Spring 2016 Assignment #4 will be the construction of 2 new classes and a driver program (the class containing a main method)Explanation / Answer
import java.io.*;
import java.util.*;
class Budget{
double initialFunding;
double spending;
double currentBalance;
public Budget(double fund){
initialFunding = fund;
spending = 0.0;
currentBalance = initialFunding-spending;
}
public boolean addSpending(double s){
if (currentBalance >= s){
spending += s;
currentBalance = initialFunding-spending;
return true;
}
return false;
}
public String toString(){
return "Budget: Initial Funding $"+initialFunding+" Spending $"+spending+" Current Balance $"+currentBalance+' ';
}
}
class Project{
String projName;
int projNumber;
String projLocation;
Budget projBudget;
public Project(double amount){
projName = "?";
projNumber = 0;
projLocation = "?";
projBudget = new Budget(amount);
}
public String getName(){
return projName;
}
public int getNumber(){
return projNumber;
}
public String getLocation(){
return projLocation;
}
public Budget getBudget(){
return projBudget;
}
public void setName(String aName){
projName = aName;
}
public void setNumber(int aNumber){
projNumber = aNumber;
}
public void setLocation(String aLocation){
projLocation = aLocation;
}
public boolean addExpenditure(double amount){
if (projBudget.addSpending(amount) == true) return true;
return false;
}
public String toString(){
return " Project Name: "+projName+" Project Number: "+projNumber+" Project Location: "+projLocation+" "+projBudget.toString();
}
}
class main{
public static void main(String[] args){
}
}