This needs to be done in Java. Please use basic Java coding at an intro level. THANK YOU FOR YOUR HELP! I WILL LEAVE A GOOD RATING!
| Money |
| - dollars : int - cents : int |
| + Money (int, int) + getDollars() + getCents() + add (Money) : Money + subtract (Money) : Money + toString() : String + equals (Money) : boolean + compareTo (Money) : int |
| Account |
| - name : String - id : String - balance : Money |
| + Account (String, String, Money) + deposit (Money) + withdraw (Money) + transfer (Account, Money) + toString() : String + equals (Account) : boolean |
As per the problem statement I have solve the problem. Please let
me know if you have any doubts or you want me to modify the answer.
And if you find this answer useful then don't forget to rate my
answer as thumps up. Thank you! :)
//Money.java
public class Money
{
private long totalCents;
//constructor money with attributed bollars
and cents
public Money(int dollars, int cents)
{
this.totalCents =
dollars * 100L + cents;
}
//Constructor where initialise the attributes
cents
public Money(long cents)
{
this.totalCents =
cents;
}
//getter method for dollars
public int getDollars()
{
return (int)
this.totalCents / 100;
}
//getter method for get cents
public int getCents()
{
return (int)
this.totalCents % 100;
}
//method to add money
public Money add (Money money)
{
return new Money
(this.totalCents + money.totalCents);
}
//method to substract money
public Money subtract (Money money)
{
return new Money
(this.totalCents - money.totalCents);
}
//to string method to get dollars
public String toString()
{
String result = "$" +
this.getDollars() + ".";
if (this.getCents()
< 10) {
result += "0";
}
result +=
this.getCents();
return result;
}
//method equals to compare the two mone
attributes whether equal or not
public boolean equals (Money other)
{
return (this.totalCents
== other.totalCents);
}
//method to compare the value of two
money
public int compareTo (Money other)
{
if (this.totalCents ==
other.totalCents)
{
return 0;
}
else if (this.totalCents
< other.totalCents)
{
return -1;
}
else if (this.totalCents
> other.totalCents)
{
return 1;
}
return 99;
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//MoneyTest.java
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class MoneyTest
{
private Money amount;
// constructor for test class MoneyTest
public MoneyTest()
{
}
@Before
public void setUp() {
amount = new Money(0,
0);
}
@After
public void tearDown() {
amount = null;
}
// Test of Money objects.
@Test
public void testCreate()
{
assertEquals("Error in
testCreate", 0, amount.getDollars());
assertEquals("Error in
testCreate", 0, amount.getCents());
Money amount2 = new Money (4, 50);
assertEquals("Error
in testCreate", 4, amount2.getDollars());
assertEquals("Error in
testCreate", 50, amount2.getCents());
Money amount3 = new Money (-4, -50);
assertEquals("Error
in testCreate", -4, amount3.getDollars());
assertEquals("Error in
testCreate", -50, amount3.getCents());
}
// Test of Money object to String.
@Test
public void testToString()
{
// First test
Money amount = new Money
(7, 55);
String actual =
amount.toString();
String expected =
"$7.55";
assertTrue("Error in
testToString", actual.equals(expected));
// Second test
Money amount2 = new
Money (7, 5);
String actual2 =
amount2.toString();
String expected2 =
"$7.05";
assertTrue("Error in
testToString", actual2.equals(expected2));
}
// Test equality of money values
@Test
public void testEquality()
{
Money myCash = new Money
(3, 75);
Money yourCash = new
Money (3, 75);
assertTrue ("Error in testEquality", myCash.equals(yourCash));
Money myAmount = new
Money (50, 0);
Money yourAmount = new
Money (50, 0);
assertTrue ("Error in
testEquality", myAmount.equals(yourAmount));
}
// Test inequality of money values
@Test
public void testInequality()
{
Money myCash = new Money
(3, 75);
Money
difftDollarsSameCents = new Money (4, 75);
Money
difftDollarsDifftCents = new Money (4, 80);
Money
sameDollarsDifftCents = new Money (3, 80);
assertFalse ("Error
in testInequality", myCash.equals(difftDollarsSameCents));
assertFalse ("Error in
testInequality", myCash.equals(difftDollarsDifftCents));
assertFalse ("Error in
testInequality", myCash.equals(sameDollarsDifftCents));
}
// Test addition of money values
@Test
public void testSimpleAdd()
{
Money amount2 = new
Money (2, 30);
Money amount3 = new
Money (3, 50);
Money actualAmount =
amount2.add (amount3);
Money expectedAmount =
new Money (5, 80);
assertTrue ("Error in
testSimpleAdd", actualAmount.equals(expectedAmount));
}
// Test complex addition of two money
values
@Test
public void testComplexAdd()
{
Money myCash = new
Money (3, 50);
Money yourCash = new
Money (4, 50);
Money expectedAmount = new Money (8, 0);
Money actualAmount = myCash.add(yourCash);
assertTrue ("Error in
testComplexAdd", actualAmount.equals(expectedAmount));
Money myCash2 = new
Money (4, 60);
Money yourCash2 = new
Money (5, 80);
Money expectedAmount2 = new Money (10, 40);
Money actualAmount2 = myCash2.add(yourCash2);
assertTrue ("Error in testComplexAdd", actualAmount2.equals(expectedAmount2));
}
@Test
public void testSubtract()
{
Money cash1 = new Money
(4, 50);
Money cash2 = new Money
(3, 50);
Money expectedAmount = new Money (1, 0);
Money actualAmount = cash1.subtract(cash2);
assertTrue ("Error in testSubtract", actualAmount.equals(expectedAmount));
Money cash3 = new
Money (4, 70);
Money cash4 = new Money
(4, 50);
Money expectedAmount2 = new Money (0, 20);
Money actualAmount2 = cash3.subtract(cash4);
assertTrue ("Error in
testSubtract", actualAmount2.equals(expectedAmount2));
}
@Test
public void testCompare()
{
Money testCash = new
Money (3, 50);
Money cash1 = new Money
(3, 50);
Money cash2 = new Money
(4, 50);
Money cash3 = new Money
(2, 50);
assertEquals ("Error in
testCompare", 0, testCash.compareTo(cash1));
assertEquals ("Error in testCompare", -1, testCash.compareTo(cash2));
assertEquals ("Error
in testCompare", 1, testCash.compareTo(cash3));
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Account.java
public class Account
{
private String name;
private String id;
private Money balance = new Money(0, 0);
//constructor for Account wiht attributes like
name , id and balance
public Account(String nameInput, String idInput,
Money balanceInput)
{
this.name =
nameInput;
this.id = idInput;
this.balance =
balanceInput;
}
public Account(Account other)
{
this.name =
other.name;
this.id =
other.id;
this.balance =
other.balance;
}
//deposit method will add money to
taccount
public void deposit(Money other)
{
if(other.compareTo(new
Money (0, 0)) == 0 || other.compareTo(new Money (0, 0)) == 1)
{
this.balance = this.balance.add(other);
}
}
//withdraw will withdraw the money from
account
public void withdraw(Money other)
{
if(other.compareTo(this.balance) == 0 ||
other.compareTo(this.balance) == -1)
{
this.balance = this.balance.subtract(other);
}
}
//method to transfer the money
public void transfer(Account other, Money
cash)
{
this.balance =
this.balance.add(cash);
other.balance =
other.balance.subtract(cash);
}
//to string method
public String toString()
{
return "" + this.name +
", " + this.id + ", " + this.balance.toString();
}
//method to return the ID
public String returnID()
{
return new
String(id);
}
//boolean equal method to check if attributed
of two accounts are equal or not.
public boolean equals(Account other)
{
if(this.name.equals(other.name) && this.id.equals(other.id)
&& this.balance.equals(other.balance))
{
return true;
}
return false;
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//AccountTest.java
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
//Test class for account
public class AccountTest
{
private Account account;
//default constructor for account test
public AccountTest()
{
}
@Before
public void setUp()
{
account = new
Account("Name", "001", new Money (0, 0));
}
@After
public void tearDown()
{
account = null;
}
// test if money deposited into the account or
not
@Test
public void testDeposit()
{
Money depositCash = new
Money (5, 0);
Account expectedResult =
new Account("Name", "001", depositCash);
account.deposit(depositCash);
assertTrue ("Error in
testDeposit", account.equals(expectedResult));
}
@Test
public void testWithdraw()
{
Money withdrawCash = new
Money (5, 0);
Account account2 = new
Account("Name", "001", new Money (10, 0));
Account expectedResult =
new Account("Name", "001", new Money (5, 0));
account2.withdraw(withdrawCash);
assertTrue ("Error in
testWithdraw", account2.equals(expectedResult));
}
@Test
public void testTransfer()
{
Money transferCash = new
Money (5, 0);
Account account2 = new
Account("Name", "001", new Money (12, 0));
account.transfer(account2, transferCash);
Account expectedResult1
= new Account("Name", "001", new Money (5, 0));
Account expectedResult2
= new Account("Name", "001", new Money (7, 0));
assertTrue ("Error in
testTransfer", account.equals(expectedResult1));
assertTrue ("Error in
testTransfer", account2.equals(expectedResult2));
}
@Test
public void testToString()
{
String expectedResult =
"Name, 001, $0.00";
String actualResult =
account.toString();
assertTrue ("Error in
testToString", expectedResult.equals(actualResult));
}
@Test
public void testEquals()
{
Account account2 = new
Account("Name", "001", new Money (0, 0));
assertTrue ("Error in
testEquals", account.equals(account2));
Account account3 =
new Account("Nam", "001", new Money (0, 0));
Account account4 = new
Account("Name", "00", new Money (0, 0));
Account account5 = new
Account("Name", "001", new Money (10, 0));
assertFalse ("Error in
testEquals", account.equals(account3));
assertFalse ("Error in
testEquals", account.equals(account4));
assertFalse ("Error in
testEquals", account.equals(account5));
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Program Output:


This needs to be done in Java. Please use basic Java coding at an intro level....
in java please Purpose: To practice designing a class that can be used in many applications. To write and implement a thorough test plan. You are NOT to use any of the Java API date classes (Gregorian calendar, Date…) except for the constructor method to set the date fields to the current data. Write a class to hold data and perform operations on dates. Ie: January 2, 2019 or 3/15/2018 You must include a toString( ), an equals( ) and...
Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...
Follow program instructions carefully. spacing is important. I think It needs a static void main too. Need to run it! You are to write a class called Point – this will represent a geometric point in a Cartesian plane (but x and y should be ints). Point should have the following: Data: that hold the x-value and the y-value. They should be ints and must be private. Constructors: A default constructor that will set the values to (2,-7) A parameterized...
java problem
here is the combination class
class Combination
{
int first,second,third, fourth;
public Combination(int first, int second, int
third,int fourth)
{
this.first=first;
this.second=second;
this.third=third;
this.fourth=fourth;
}
public boolean equals(Combination other)
{
if ((this.first==other.first)
&& (this.second==other.second) &&
(this.third==other.third) &&
(this.fourth==other.fourth))
return
true;
else
return
false;
}
public String toString()
{
...
Write in java and the class need to use give in the end copy it is fine. Problem Use the Plant, Tree, Flower and Vegetable classes you have already created. Add an equals method to Plant, Tree and Flower only (see #2 below and the code at the end). The equals method in Plant will check the name. In Tree it will test name (use the parent equals), and the height. In Flower it will check name and color. In...
Implement a Java class that is called RainFall that uses a double array to store the amount of rainfall for each month of the year. The class should have only one instance variable of type double[]. Implement the following methods in the RainFall class: 1. A constructor that creates and initializes all entries in the array to be -1. 2. toString: a method that returns a one-line String representation of the object that includes 12 double numbers that represent the...
Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...
in
java
Part 1 In this section, we relook at the main method by examining passing array as parameters. Often we include options/flags when running programs. On command line, for example, we may do “java MyProgram -a -v". Depending on options, the program may do things differently. For example, "a" may do all things while "-v" display messages verbosely. You can provide options in Eclipse instead of command line: "Run ... Run Configurations ... Arguments". Create a Java class (Main.java)....
this is for java programming Please Use Comments I am not 100% sure if my code needs work, this code is for the geometric if you feel like you need to edit it please do :) Problem Description: Modify the GeometricObject class to implement the Comparable interface and define a static max method in the GeometricObject class for finding the larger (in area) of two GeometricObject objects. Draw the UML and implement the new GeometricObject class and its two subclasses...
in java no mathcall please
ennas are out of date.Please sign was wkollieemail.cpeedu so we can verily your subscription Sign In ASSIGNMENT Unit 9 Methods, Arrays, and the Java Standard Class Library Reimplementing the Arrays class (60 points) The Arrays class, which is also part of the Java standard class library, provides various class methods that perform common tasks on arrays, such as searching and sorting. Write a public class called MyArrays, which provides some of the functionality which is...