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

This is a java program ... I dont know how to do it....please typeit and paste i

ID: 3812420 • Letter: T

Question

This is a java program... I dont know how to do it....please typeit and paste it...

The purpose of this assignment is to grow more familiar with the ArrayList class and related operations through a small application that tracks purchases. You will write a program that tracks a series of floating point numbers (transactions). It allows the user to add a new transaction on to the end, print out the transactions, and print a total of all transactions. These values are not persistent - when the person quits the program, the values are lost. These values must be stored in an ArrayList. Specific requirements: Implement a Transaction class that holds an ArrayList as it's member function. Implement addItem (takes in a float), printItems (prints items in list), and sumItems (returns a float) methods. Implement a class called Register that contains an instance of the Transaction class. Write a main method that prints the menu, as shown below, gathers inputs using the Scanner class, and loops repeatedly until the person presses "q". Pay close attention to the language given below, online testing is dependent on strings matching exactly. Note that while my example is an old Python assignment, you should implement using Java. cayenne: tmp jtogen$ python3 test.py Please type an option and press enter o: Add to register p: Print register s: Sum Register q: Quit Your Choice: a Enter value: 10.50 Please type an option and press enter a: Add to register p: Print register s: Sun Register q: quit Your Choice: a Enter value: 20 Please type an option and press enter a: Add to register p: Print register s: Sun Register q: Quit Your Choice: p $10.50 $20.00 Please type an option and press enter a: Add to register p: Print register s: Sum Register q: quit Your Choice: 5 Total is $30.50 Please type an option and press enter a: Add to register p: Print register s: Sun Register q: quit Your Choice: q cayenne: tmp jtogen$

Explanation / Answer

Transaction.java

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class Transaction {
  
   List item= new ArrayList<>();
  
   public void addItems(float val){
       item.add(val);
   }
  
   public void printItems(){
       Iterator itr= item.iterator();
       while(itr.hasNext())
       {
           float val= (float) itr.next();
           System.out.println("$"+val);
       }
   }
  
   public float sumItems(){
       float sum=0;
       Iterator itr= item.iterator();
       while(itr.hasNext())
       {
           float val= (float) itr.next();
           sum=sum+val;
       }
       return sum;
   }
  

}

Register.java

import java.util.Scanner;


public class Register {

   /**
   * @param args
   */
   public static void main(String[] args) {
       Transaction t= new Transaction();
       Scanner scan = new Scanner(System.in);
       String choice=null;
       do{
           System.out.println("Please type an option and press enter");
           System.out.println("a: Add to register");
           System.out.println("p: Print register");
           System.out.println("s: Sum register");
           System.out.println("q: Quit");
           System.out.print("Your Choice: ");
           choice=scan.nextLine();
          
           switch (choice) {
           case "a":
               System.out.print("Enter value: ");
               String val=scan.nextLine();
               t.addItems(Float.parseFloat(val));
               break;
           case "p":
               t.printItems();
               break;
           case "s":
               System.out.println("$"+t.sumItems());
               break;
           default:
               break;
           }
       }while(!choice.equals("q"));
      
   }

}

---output-------

Please type an option and press enter
a: Add to register
p: Print register
s: Sum register
q: Quit
Your Choice: a
Enter value: 10.50
Please type an option and press enter
a: Add to register
p: Print register
s: Sum register
q: Quit
Your Choice: a
Enter value: 20
Please type an option and press enter
a: Add to register
p: Print register
s: Sum register
q: Quit
Your Choice: p
The values are [10.5, 20.0]
$10.5
$20.0
Please type an option and press enter
a: Add to register
p: Print register
s: Sum register
q: Quit
Your Choice: s
$30.5
Please type an option and press enter
a: Add to register
p: Print register
s: Sum register
q: Quit
Your Choice: q

------output---

Note: I have tried to match the strings exactly. let me know if you found some error. Thanks and god bless you!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote