The current code I have is the following:
package uml;
public class uml {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
class Account {
private String accountID;
public Account(String accountID) {
this.accountID = accountID;
}
public String getAccountID() {
return accountID;
}
public void setAccountID(String accountID) {
this.accountID = accountID;
}
@Override
public String toString() {
return "Account [accountID=" + accountID + "]";
}
}
class SuppliesAccount extends Account {
private int numberOfItems;
private double pricePerItem;
public SuppliesAccount(String accountID, int numberOfItems, double pricePerItem) {
super(accountID);
this.numberOfItems = numberOfItems;
this.pricePerItem = pricePerItem;
}
public int getNumberOfItems() {
return numberOfItems;
}
public void setNumberOfItems(int numberOfItems) {
this.numberOfItems = numberOfItems;
}
public double getPricePerItem() {
return pricePerItem;
}
public void setPricePerItem(double pricePerItem) {
this.pricePerItem = pricePerItem;
}
@Override
public String toString() {
return "SuppliesAccount [numberOfItems=" + numberOfItems + ", pricePerItem=" + pricePerItem + "]";
}
}
class ServiceAccount extends Account {
private int numberOfHours;
private double ratePerHour;
public ServiceAccount(String accountID, int numberOfHours, double ratePerHour) {
super(accountID);
this.numberOfHours = numberOfHours;
this.ratePerHour = ratePerHour;
}
public int getNumberOfHours() {
return numberOfHours;
}
public void setNumberOfHours(int numberOfHours) {
this.numberOfHours = numberOfHours;
}
public double getRatePerHour() {
return ratePerHour;
}
public void setRatePerHour(double ratePerHour) {
this.ratePerHour = ratePerHour;
}
@Override
public String toString() {
return "ServiceAccount [numberOfHours=" + numberOfHours + ", ratePerHour=" + ratePerHour + "]";
}
}
I am tasked with the folllowing:
In Eclipse, implement your account class diagram created earlier. Complete the following:
Your Java project should include 3 classes:
Account.java, Services.java, and Supplies.java.
There should be implemented constructors for
each class.
The toString() method should be overridden to
provide a readable string representation of each object.
Getters and setters need to be implemented to
enforce data hiding.
The calculateSales() method should be
implemented for all classes
Consider having the
calculateSales() as an abstract method for the Abstract Account
class.
In addition, you need to create a test class
companySales.java that tests each subclass's constructor,
toString(), and computeSales().
You need to create an instance of each
subclass.
Input can be hard-coded or entered by the
user.
You need to call the method calculateSales() for
each instance.
You need to print each class info using its
method toString().
Code should be fully commented.
Program flow should be logical.
package inheritance;
abstract class Account
{
private String accountID;
public Account(String accountID)
{
this.accountID = accountID;
}
public String getAccountID()
{
return accountID;
}
public void setAccountID(String accountID)
{
this.accountID = accountID;
}
@Override
public String toString()
{
return "Account [accountID=" + accountID + "]";
}
abstract double calculateSales();
}
class SuppliesAccount extends Account
{
private int numberOfItems;
private double pricePerItem;
public SuppliesAccount(String accountID, int numberOfItems, double pricePerItem)
{
super(accountID);
this.numberOfItems = numberOfItems;
this.pricePerItem = pricePerItem;
}
public int getNumberOfItems()
{
return numberOfItems;
}
public void setNumberOfItems(int numberOfItems)
{
this.numberOfItems = numberOfItems;
}
public double getPricePerItem()
{
return pricePerItem;
}
public void setPricePerItem(double pricePerItem)
{
this.pricePerItem = pricePerItem;
}
@Override
public String toString()
{
return "SuppliesAccount [numberOfItems=" + numberOfItems +
", pricePerItem=" + pricePerItem + "]" +
"\n Total Sales: " + calculateSales();
}
double calculateSales()
{
return (numberOfItems * pricePerItem);
}
}
class ServiceAccount extends Account
{
private int numberOfHours;
private double ratePerHour;
public ServiceAccount(String accountID, int numberOfHours, double ratePerHour)
{
super(accountID);
this.numberOfHours = numberOfHours;
this.ratePerHour = ratePerHour;
}
public int getNumberOfHours()
{
return numberOfHours;
}
public void setNumberOfHours(int numberOfHours)
{
this.numberOfHours = numberOfHours;
}
public double getRatePerHour()
{
return ratePerHour;
}
public void setRatePerHour(double ratePerHour)
{
this.ratePerHour = ratePerHour;
}
@Override
public String toString()
{
return "ServiceAccount [numberOfHours = " + numberOfHours +
", ratePerHour=" + ratePerHour + "]" +
"\n Total Sales: " + calculateSales();
}
double calculateSales()
{
return (numberOfHours * ratePerHour);
}
}
public class CompanySales
{
// main method definition
public static void main(String[] args)
{
Account ac[] = new Account[2];
ac[0] = new SuppliesAccount("111", 12, 200.23);
ac[1] = new ServiceAccount("222", 32, 1250.11);
System.out.println(ac[0]);
System.out.println(ac[1]);
}
}
Sample Output:
SuppliesAccount [numberOfItems=12, pricePerItem=200.23]
Total Sales: 2402.7599999999998
ServiceAccount [numberOfHours = 32, ratePerHour=1250.11]
Total Sales: 40003.52
The current code I have is the following: package uml; public class uml { public...
java code ========= public class BankAccount { private String accountID; private double balance; /** Constructs a bank account with a zero balance @param accountID - ID of the Account */ public BankAccount(String accountID) { balance = 0; this.accountID = accountID; } /** Constructs a bank account with a given balance @param initialBalance the initial balance @param accountID - ID of the Account */ public BankAccount(double initialBalance, String accountID) { this.accountID = accountID; balance = initialBalance; } /** * Returns the...
java code ============= public class BankAccount { private String accountID; private double balance; /** Constructs a bank account with a zero balance @param accountID - ID of the Account */ public BankAccount(String accountID) { balance = 0; this.accountID = accountID; } /** Constructs a bank account with a given balance @param initialBalance the initial balance @param accountID - ID of the Account */ public BankAccount(double initialBalance, String accountID) { this.accountID = accountID; balance = initialBalance; } /** * Returns the...
Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...
Java: Please help with my Tester. I'm having a hard time figuring out my error. Thank you. What the tester requires: The AccountTester This class should consists of a main method that tests all the methods in each class, either directly by calling the method from the Tester or indirectly by having another method call a method. User and Bot information will be read from a file. A sample file is provided. Use this file format to aid in grading....
In Java. Please use the provided code Homework 5 Code: public class Hw05Source { public static void main(String[] args) { String[] equations ={"Divide 100.0 50.0", "Add 25.0 92.0", "Subtract 225.0 17.0", "Multiply 11.0 3.0"}; CalculateHelper helper= new CalculateHelper(); for (int i = 0;i { helper.process(equations[i]); helper.calculate(); System.out.println(helper); } } } //========================================== public class MathEquation { double leftValue; double rightValue; double result; char opCode='a'; private MathEquation(){ } public MathEquation(char opCode) { this(); this.opCode = opCode; } public MathEquation(char opCode,double leftVal,double rightValue){...
I Have a problem with my JAVA class "Directivo". In the " public double sueldo() " method, the instruction say "Calculate the salary of a Directivo the following way: Invoke method salary of the father and add him the extra bonus" My question is : How can I do this ? how can i implement that instruction in the public double sueldo() method public class Directivo extends Planta implements Administrativo{ private double bonoExtra; public Directivo( String nom, String...
Need help completing my instance method for deleteFront() as specified below To the class IntegerLinkedList, add an instance method deleteFront such that … Method deleteFront has no input. Method deleteFront returns … an empty Optional instance if the list is empty an Optional instance whose value is the integer that was deleted from the front of the list, otherwise Hints https://docs.oracle.com/javase/10/docs/api/java/util/Optional.html import java.util.Optional; public class IntegerLinkedList { private IntegerNode head ; private int numberOfItems ; public int getNumberOfItems() { return...
Templates Apartment.java package hwk7; public class Apartment { int numOfApartments; // the number of apartments of this type Room[] rooms; // rooms in this type of apartment Apartment(int numOfApartments, Room[] rooms) { this.numOfApartments = numOfApartments; this.rooms = rooms; } // Return the window orders for one apartment of this type as TotalOrder object TotalOrder orderForOneUnit() { // TODO } // Return the window...
COVERT TO PSEUDOCODE /****************************Vacation.java*****************************/ public abstract class Vacation { /* * private data field */ private double cost; private double budget; private String destination; /** * * @param cost * @param budget * @param destination */ public Vacation(double cost, double budget, String destination) { super(); this.cost = cost; this.budget = budget; this.destination = destination; } //getter and...
Please create two tests classes for the code down below that use all of the methods in the Transaction class, and all of the non-inherited methods in the derived class. Overridden methods must be tested again for the derived classes. The first test class should be a traditional test class named "Test1" while the second test class should be a JUnit test class named "Test2". All I need is to test the classes, thanks! Use a package that contains the...