Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

solve two parts: Part 1: The Portfolio Object Class This is based on Programming

ID: 3885437 • Letter: S

Question

solve two parts:

Part 1: The Portfolio Object Class

This is based on Programming Project P8.13 in Big Java: Late Objects

As part of a NetBeans Java application project, implement a class Portfolio. This class has two objects (data fields), checking and savings, of the type BankAccount that was developed in How To 8.1 (BankAccount.java).

Declare private data fields for the checking and savings BankAccounts.

Implement a default (no-arg) constructor that creates the BankAccount object for each data field.

Implement four methods:

public void deposit(double amount, String account)

public void withdraw(double amount, String account)

public void transfer(double amount, String account)

public double getBalance(String account): returns the current account balance

public String toString(): returns the Portfolio as a String (see test program and output, below)

In each of these methods, the account string is "S" or "C":

For the deposit or withdrawal, it indicates which account is affected.

For a transfer, it indicates the account from which the money is taken; the money is automatically transferred to the other account.

You should, of course, also create a test program as the main method of your application. One suggestion:

public static void main(String[] args) {
    Portfolio folio = new Portfolio(); // start with a new Portfolio
    
    folio.deposit(10000, "S"); // deposit $10,000.00 in savings
    folio.transfer(1500, "S"); // transfer $1,500.00 to checking
    
    // get the savings balance (should be $8,500.00)
    System.out.println(" savings: " + folio.getBalance("S"));
    // get the checking balance (should be $1,500.00)
    System.out.println(" checking: " + folio.getBalance("C"));
   
    System.out.println("---------------------------------------------------------------------");
   
    System.out.println(folio); // display the Portfolio (calls toString())
   
    System.out.println("---------------------------------------------------------------------");
   
    folio.withdraw(500, "C"); // withdraw $500.00 from checking
    folio.transfer(1000, "S"); // transfer $1,000.00 to checking
    folio.deposit(3000, "S"); // deposit $3,000.00 in savings
   
    // get the savings balance (should be $10,500.00)
    System.out.println(" savings: " + folio.getBalance("S"));
    // get the checking balance (should be $2,000.00)
    System.out.println(" checking: " + folio.getBalance("C"));
   
    System.out.println("---------------------------------------------------------------------");
   
    System.out.println(folio); // display the Portfolio (calls toString())
} // end main

run:
    savings: 8500.0
    checking: 1500.0
---------------------------------------------------------------------
Savings: 8500.0
Checking: 1500.0
---------------------------------------------------------------------
    savings: 10500.0
    checking: 2000.0
---------------------------------------------------------------------
Savings: 10500.0
Checking: 2000.0
BUILD SUCCESSFUL

Design Note: For those who wish to make their output look more "currency-like" (e.g., $8,500.00 instead of 8500.0), I suggest you look at the Java object class java.text.DecimalFormat.

Part 2: The Portfolio Object Class

This is based on Programming Projects P8.20 and P8.21 in Big Java: Late Objects

1. The colored bands on the top-most resistor shown in the photo below indicate a resistance of 6.2 k ±5 percent. The resistor tolerance of ±5 percent indicates the acceptable variation in the resistance. A 6.2 k ±5 percent resistor could have a resistance as small as 5.89 k or as large as 6.51 k. We say that 6.2 k is the nominal value of the resistance and that the actual value of the resistance can be any value between 5.89 k and 6.51 k.

As part of a NetBeans Java application project, implement a class Resistor. Make sure to include:

data fields for the nominal resistance, tolerance, and actual resistance

a single constructor that accepts values for the nominal resistance and tolerance and then determines the actual value randomly

public getter methods for the data fields (nominal resistance, tolerance, and the actual resistance)

Write a main method for the program that demonstrates that the class works properly by displaying actual resistances for ten 330 ±10 percent resistors.

Then, once your Resistor class is fully tested and working ...

2. Create a new NetBeans Java application project, copy your Resistor class into it, and then add a method to the Resistor class that returns a description of the “color bands” for the resistance and tolerance. A resistor has four color bands:

The first band is the first significant digit of the actual resistance value.

The second band is the second significant digit of the actual resistance value.

The third band is the decimal multiplier.

The fourth band indicates the tolerance.

For example (using the values from the table as a key), a resistor with red, violet, green, and gold bands (left to right) will have 2 as the first digit, 7 as the second digit, a multiplier of 105, and a tolerance of ±5 percent, for a resistance of 2,700 k, plus or minus 5 percent.

Use the following main method to demonstrate this modified Resistor class:

public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    System.out.print("Resistance: ");
    double resistance = in.nextDouble();

    System.out.print("Tolerance in percent: ");
    double tolerance= in.nextDouble();
    Resistor r = new Resistor(resistance, tolerance);

    System.out.print(r.colorBands(5)); // multiplier of 10^5
} // end main

Note that in the sample run shown below, user input is shown in color.

run:
Resistance: 6.2
Tolerance in percent: 5
gray yellow yellow gold
BUILD SUCCESSFUL

Explanation / Answer


Portfolio.java
--------------------
public class Portfolio {
private BankingAccount checkingAccount;
private BankingAccount savingAccount;
public Portfolio() {
this.checkingAccount = new BankingAccount(1, 0.0, 'C');
this.savingAccount = new BankingAccount(2, 0.0, 'S');
}
public void deposit(double amount, String account) {
if ("C".equals(account)) {
this.checkingAccount.setBalance(this.checkingAccount.getBalance()
+ amount);
} else if ("S".equals(account)) {
this.savingAccount.setBalance(this.savingAccount.getBalance()
+ amount);
}
}
public void withdraw(double amount, String account) {
if ("C".equals(account)) {
this.checkingAccount.setBalance(this.checkingAccount.getBalance()
- amount);
} else if ("S".equals(account)) {
this.savingAccount.setBalance(this.savingAccount.getBalance()
- amount);
}
}
public void transfer(double amount, String account) {
if ("C".equals(account)) {
this.checkingAccount.setBalance(this.checkingAccount.getBalance()
- amount);
this.savingAccount.setBalance(this.savingAccount.getBalance()
+ amount);
} else if ("S".equals(account)) {
this.savingAccount.setBalance(this.savingAccount.getBalance()
- amount);
this.checkingAccount.setBalance(this.checkingAccount.getBalance()
+ amount);
}
}
public double getBalance(String account) {
double balance = 0;
if ("C".equals(account)) {
balance = this.checkingAccount.getBalance();
} else if ("S".equals(account)) {
balance = this.savingAccount.getBalance();
}
return balance;
}
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("Saving " + this.savingAccount.getBalance()).append(" ")
.append("Checking " + this.checkingAccount.getBalance());
return buffer.toString();
}
}
class BankingAccount {
private int accountNumber;
private double balance;
private char accoutnType;
public BankingAccount(int accountNumber, double balance, char accoutnType) {
super();
this.accountNumber = accountNumber;
this.balance = balance;
this.accoutnType = accoutnType;
}
public int getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(int accountNumber) {
this.accountNumber = accountNumber;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public char getAccoutnType() {
return accoutnType;
}
public void setAccoutnType(char accoutnType) {
this.accoutnType = accoutnType;
}
}
-------------- End--------------------------
public class TestPortFolio {
public static void main(String[] args) {
Portfolio folio = new Portfolio(); // start with a new Portfolio
folio.deposit(10000, "S"); // deposit $10,000.00 in savings
folio.transfer(1500, "S"); // transfer $1,500.00 to checking
// get the savings balance (should be $8,500.00)
System.out.println(" savings: " + folio.getBalance("S"));
// get the checking balance (should be $1,500.00)
System.out.println(" checking: " + folio.getBalance("C"));
System.out
.println("---------------------------------------------------------------------");
System.out.println(folio); // display the Portfolio (calls toString())
System.out
.println("---------------------------------------------------------------------");
folio.withdraw(500, "C"); // withdraw $500.00 from checking
folio.transfer(1000, "S"); // transfer $1,000.00 to checking
folio.deposit(3000, "S"); // deposit $3,000.00 in savings
// get the savings balance (should be $10,500.00)
System.out.println(" savings: " + folio.getBalance("S"));
// get the checking balance (should be $2,000.00)
System.out.println(" checking: " + folio.getBalance("C"));
System.out
.println("---------------------------------------------------------------------");
System.out.println(folio); // display the Portfolio (calls toString())
}
}
---------------- End TestPortFolio.java ---------------
Output
---------------
savings: 8500.0
checking: 1500.0
---------------------------------------------------------------------
Saving 8500.0
Checking 1500.0
---------------------------------------------------------------------
savings: 10500.0
checking: 2000.0
---------------------------------------------------------------------
Saving 10500.0
Checking 2000.0


2.   Resistor.java
------------------------
public class Resistor {
private double nominalResistance;
private double tolerance;
private double[] actualResistance;
public Resistor(double nominalResistance, double tolerance) {
super();
this.nominalResistance = nominalResistance;
this.tolerance = tolerance;
actualResistance = new double[2];
}
public double getNominalResistance() {
return nominalResistance;
}
public void setNominalResistance(double nominalResistance) {
this.nominalResistance = nominalResistance;
}
public double getTolerance() {
return tolerance;
}
public void setTolerance(double tolerance) {
this.tolerance = tolerance;
}
public double getActualResistance() {
actualResistance[0] = this.nominalResistance
- ((this.nominalResistance * this.tolerance) / 100);
actualResistance[1] = this.nominalResistance
+ ((this.nominalResistance * this.tolerance) / 100);
int randomNum = 0 + (int) (Math.random() * 1);
return actualResistance[randomNum];
}
}
---------------------- End-----------------------
TestResistor.java
---------------------
public class TestResistor {
public static void main(String[] args) {
Resistor r = new Resistor(330, 10);
System.out.println(" Actual Calculated
System.out.println(" Actual Calculated
}
}
-- End -----------------------------

Output
------------
Actual Calculated Resistence 297.0
Actual Calculated Resistence 297.0


Description :
-------------------
I did not get the color table in actual question. If you can attach the same then i can code for it.
Please attach the same in test file format.
Please let me know if you need more assistence here on above given solution. Thanks