Turn the Pseudocode into Java program. GetTransNumber. { Input transNum. } GetTr
ID: 3831050 • Letter: T
Question
Turn the Pseudocode into Java program.
GetTransNumber.
{
Input transNum.
}
GetTransDetails.
{
Input transType, transAmt.
}
CalcInterest.
{
If(supplierMonthlyPymts <balForward)
{
interest = yrInterest/12 * currentBal.
}
Else
{
interest = 0.
}
}
CalcBalances.
{
overallSuppPurs = overallSuppPurs + supplierMonthlyPur.
overallSuppPymts = overallSuppPymts + supplierMonthlyPymts.
finalMonthlyBal = currentBal + intrest.
overallFinalBal = overallFinalBal + finalMonthlyBal.
}
UpdateLow.
{
If(finalMonthlyBal < lowSuppFinalMonthlyBal)
{
lowSuppFinalMonthlyBal = finalMonthlyBal.
lowSuppName = supplierName.
}
}
DisplaySuppBalances.
{
Output finalMonthlyBal, supplierMonthlyPur, supplierMonthlyPymts.
}
CalcAverage.
{
avePursPerSupplier = overallSuppPurs / supplierCtr.
}
DisplaySummary.
[
Output date, overallFinalBal, overallSuppPurs, overallSuppPymts.
Output avePursPerSupplier, lowSuppFinalMonthlyBal, lowSuppName.
}
Explanation / Answer
Program:-
import java.util.*;
public class PseudoCode{
static int supplierCtr=0;
static String supplierName;
static float overallSuppPurs;
static float overallSuppPymts;
static float avePursPerSupplier;
static int lowSuppFinalMonthlyBal;
static int supplierMonthlyPymts;
static int supplierMonthlyPur;
static int transNum;
static String transType;
static String lowSuppName;
static int overallFinalBal;
static int finalMonthlyBal;
static int interest;
static int transAmt;
static int balForward;
static int yrInterest;
static int currentBal;
public static void main(String arr[]){
InitializeReport();
GetDate();
while(!(supplierName.equalsIgnoreCase("Done")))
{
ProcessSupplier();
}
CalcAverage();
DisplaySummary();
}
static void InitializeReport(){
supplierName="Let's go!";
supplierCtr =0;
overallSuppPurs = 0.0f;
overallSuppPymts = 0.0f;
lowSuppFinalMonthlyBal = 250000;
}
static Date GetDate()
{
Date d1 = new Date();
return d1;
}
static void ProcessSupplier()
{
InitSupplier();
supplierName = GetSupplierName();
if(!(supplierName.equalsIgnoreCase("Done")))
{
supplierCtr = supplierCtr + 1;
GetSupplierDetails();
DisplaySupplier();
//UpdateCurrentBal();
while(transNum!=0)
{
ProcessTrans();
}
CalcInterest();
CalcBalances();
UpdateLow();
DisplaySuppBalances();
}
}
static void InitSupplier()
{
supplierMonthlyPymts = 0;
supplierMonthlyPur = 0;
transNum = 9999;
}
static String GetSupplierName()
{
Scanner sc =new Scanner(System.in);
supplierName = sc.next();
return supplierName;
}
static void GetSupplierDetails()
{
Scanner sc1 =new Scanner(System.in);
balForward = sc1.nextInt();
yrInterest = sc1.nextInt();
}
static void DisplaySupplier()
{
currentBal = balForward;
}
static void ProcessTrans()
{
transNum=GetTransNumber();
if(transNum != 0)
{
GetTransDetails();
UpdateTrans();
DisplayTrans();
}
}
static int GetTransNumber()
{
Scanner sc =new Scanner(System.in);
transNum = sc.nextInt();
return transNum;
}
static void GetTransDetails()
{
Scanner sc =new Scanner(System.in);
transType = sc.next();
transAmt =sc.nextInt();
}
static void UpdateTrans()
{
switch (transType.charAt(0))
{
case 'B':
case 'b':
currentBal = currentBal + transAmt;
supplierMonthlyPur = supplierMonthlyPur + transAmt;
break;
case 'P':
case 'p':
currentBal = currentBal - transAmt;
supplierMonthlyPymts = supplierMonthlyPymts + transAmt;
break;
}
}
static void DisplayTrans()
{
System.out.println("TransNum="+transNum);
System.out.println("TransType="+transType);
System.out.println("TransAmt="+transAmt);
System.out.println("CurrentBal="+currentBal);
}
static void CalcInterest()
{
if(supplierMonthlyPymts <balForward)
{
interest = yrInterest/12 * currentBal;
}
else
{
interest = 0;
}
}
static void CalcBalances()
{
overallSuppPurs = overallSuppPurs + supplierMonthlyPur;
overallSuppPymts = overallSuppPymts + supplierMonthlyPymts;
finalMonthlyBal = currentBal + interest;
overallFinalBal = overallFinalBal + finalMonthlyBal;
}
static void UpdateLow()
{
if(finalMonthlyBal < lowSuppFinalMonthlyBal)
{
lowSuppFinalMonthlyBal = finalMonthlyBal;
lowSuppName = supplierName;
}
}
static void DisplaySuppBalances()
{
System.out.println("finalMonthlyBal="+finalMonthlyBal);
System.out.println("supplierMonthlyPur="+supplierMonthlyPur);
System.out.println("supplierMonthlyPymts="+supplierMonthlyPymts);
}
static void CalcAverage()
{
avePursPerSupplier = overallSuppPurs / supplierCtr;
}
static void DisplaySummary()
{
System.out.println("date="+GetDate());
System.out.println("overallFinalBal="+overallFinalBal);
System.out.println("overallSuppPurs="+overallSuppPurs);
System.out.println("overallSuppPymts="+overallSuppPymts);
System.out.println("avePursPerSupplier="+avePursPerSupplier);
System.out.println("lowSuppFinalMonthlyBal="+lowSuppFinalMonthlyBal);
System.out.println("lowSuppName="+lowSuppName);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.