java hw
CSE 110 - ASSIGNMENT # 6
Maximum points : 20
What This Assignment Is About:
• Object Oriented Programming (Chapter 8) - Encapsulation - Implementing classes - Implementing methods - Object construction - Constructors
• Methods (Chapter 5) - Definition and Invocation.
Your programming assignments require individual work and effort to be of any benefit. Every student must work
independently on his or her assignments. This means that every student must ensure that neither a soft copy nor a
hard copy of their work gets into the hands of another student. Sharing your assignments with others in any way is
NOT permitted.
Violations of the University Academic Integrity policy will not be ignored. The university academic integrity
policy is found at http://www.asu.edu/studentlife/judicial/integrity.html
Use the following Coding Guidelines:
Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc).
Keep identifiers to a reasonably short length. User upper case for constants. Use title case (first letter is upper case) for classes. Use lower
case with uppercase word separators for all other identifiers (variables, methods, objects). Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes
classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent.
Use white space to make your program more readable. Use comments after the ending brace of classes, methods, and blocks to identify to which block it
belongs.
Assignments Documentation:
At the beginning of each programming assignment you must have a comment block with the following information: /*------------------------------------------------------------------------- // AUTHOR: your name // FILENAME: title of the source file // SPECIFICATION: description of the program // YOUR Lab Letter and Name of the TA for your Closed lab // FOR: CSE 110- homework #- days and time of your class // TIME SPENT: how long it took you to complete the assignment //----------------------------------------------------------------------*/
Part 1: There is no part 1 for this assignment
Part 2: Programming (20 points):
For this assignment you will be constructing 2 new classes, Project and Assignment6 which is a test driver for the class Project. (2 files)
Class Project: The Project class describes a project that people can participate in. It must have the
following attributes:
name type Description
projName String name of a project
projNumber int number of a project
projLocation String location of a project
initialFunding double initial funding of a project
spending double spending of a project
currentBalance double current balance of a project
Here are the methods for class Project:
Methods Description of the methods
public Project(double amount)
This constructor initializes all strings to "?" and the
project number to 0. The varibales spening is
assigned to 0.0. currentBalance and initial funding
are assigned to the amount passed as a parameter .
public String getName() Accessor method
public int getNumber() Accessor method
public String getLocation() Accessor method
public void setName(String aName) Mutator method
public void setNumber(int aNumber) Mutator method
public void setLocation(String aLocation) Mutator method
public boolean addSpending(double amount)
If the parameter value is positive and is less than or
equals to currentBalance, it should be added to
spending, and currentBalance should be re-
computed as initialFunding-spending, and the
method should return true. Otherwise, the method
should not change any value and return false.
public String toString() The toString() method constructs a string of the
following format:
\nProject Name:\tProject Name\n
Project Number:\tProject Number\n
Project Location:\tProject Location\n
Initial Funding\t$0.00\n
Spending\t$0.00\n
Current Balance\t$0.00\n
Hints: you can make use of the DecimalFormat or NumberFormat class in java.text package to format initialFunding, spending, and currentBalance, having two digits after the decimal point "$0.00".
Assignment6 Class:
The driver program will allow the user to interact with your class Project. The purpose of this
class is to handle all user input and screen output. The main method should start by displaying
the following menu in this format:
Choice\t\tAction\n
------\t\t------\n
A\t\tAdd Project\n
D\t\tDisplay Project\n
Q\t\tQuit\n
R\t\tAdd Expenditure\n
?\t\tDisplay Help\n\n
Next, the following prompt should be displayed:
What action would you like to perform?
Read in the user input and execute the appropriate command. After the execution of each
command, re-display the prompt. Commands should be accepted in both lowercase and
uppercase.
Hint:You can use toUpperCase() or toLowerCase() method of the Character class. Usage can be
seen in Common loop algorithms.
Add Project
Your program should display the following prompt:
Please enter the project information:
Enter a project name:
Read in the user input. Then the following prompt:
Enter a project number:
Read in the user input. Then the following prompt:
Enter a project location:
Read in the user input. Then the following prompt:
Enter a project initial funding:
Read in the user input, and use the constructor of the Project class to initialize a new Project
object, project1, and set the values read from the user input, using the mutator (setter) methods of
the Project class.
Note that there is only one Project object in this assignment. Thus when "Add Project" option is
selected more than once, the new one overwrites the old Project object.
Display Project (option ‘A’)
Your program should display the Project information using the toString method of the Project
class. The toString method is used together with System.out.print method.
Quit (aption ‘Q’)
Your program should stop executing and output nothing.
Add Expenditure (option ‘R’)
Your program should display the following prompt:
Please enter any additional expenditure:
Read in the user input and update the budget of the project accordingly by calling the
addExpenditure method of the project object. If it returns false, then it should display the error
message: The entered expenditure is not accepted.
Display Help (option ‘?’)
Your program should redisplay the "choice action" menu.
Invalid Command
If an invalid command is entered, display the following line:
Unknown action
Sample Output: user input is in RED
Choice Action ------ ------ A Add Project D Display Project Q Quit R Add Expenditure ? Display Help
What action would you like to perform? A Please enter the project information: Enter a project name: Helping Children Project Enter a project number: 123 Enter a project location: Phoenix Enter a project initial funding: 2450000 What action would you like to perform? d Project Name: Helping Children Project Project Number: 123 Project Location: Phoenix Initial Funding $2,450,000.00 Spending $0.00 Current Balance $2,450,000.00 What action would you like to perform? r Please enter any additional expenditure: 3500 What action would you like to perform? d Project Name: Helping Children Project Project Number: 123 Project Location: Phoenix Initial Funding $2,450,000.00 Spending $3,500.00 Current Balance $2,446,500.00 What action would you like to perform? r Please enter any additional expenditure: 20000 What action would you like to perform? d Project Name: Helping Children Project Project Number: 123 Project Location: Phoenix Initial Funding $2,450,000.00 Spending $23,500.00
Current Balance $2,426,500.00 What action would you like to perform? q
Helpful hints for doing this assignment:
· work on it in steps – write one method, test it with a test driver and make sure it works before
going on to the next method
· always make sure your code compiles before you add another method
· your methods should be able to be called in any order
Submit your homework by following the instructions below:
*********************************************************************************
Go to the course web site (my.asu.edu), and then click on the on-line Submission tab.
Submit all two files: Assignment6.java, and Project.java on-line. Make sure to choose
HW6 from drop-down box.
Important Note: You may resubmit as many times as you like until the deadline, but we will
only mark your last submission.
NO LATE ASSIGNMENTS WILL BE ACCEPTED