Java Project to Build a Trip Expense Or Budget Income Tracker on Command Line

If you want to know about “Java Project to Build a Trip Expense Or Budget Income Tracker on Command Line” then refer to this tutorial to learn about it. Let’s see the possibilities to do this task below.

Java Project to Build a Trip Expense Or Budget Income Tracker on Command Line

Java Project to Build a Trip Expense Or Budget Income Tracker on Command Line

expensetracker.java

import java.util.Scanner;
public class expensetracker
{
    public static void main(String args[])
    {    
        int sum = 0;
        Scanner sc = new Scanner(System.in);
        System.out.print("How many persons are there ? ");
        int n = sc.nextInt();
        int[] amounts = new int[n];
        for(int i = 1; i <= n; i++)
        {
            System.out.print("How much did person " + i + " pay ? ");
            int r = sc.nextInt();
            amounts[i - 1] = r;
        }
        for(int i = 0; i < amounts.length; i++)
        {
            sum += amounts[i];
        }
        int each = sum / n;
        System.out.println("\nEach person must contribute " + each);
        System.out.println();
        for(int i = 0; i < amounts.length; i++)
        {
            int payable = each - amounts[i];
            if (payable < 0)
            {
                System.out.println("Person " + (i + 1) + " will get " + Math.abs(payable));
                System.out.println();
            }
            else
            {
                System.out.println("Person " + (i + 1) + " has to pay " + payable);
                System.out.println();
            }
        }
    }
}

Final Thoughts

I hope this article helps you to know about the “Java Project to Build a Trip Expense Or Budget Income Tracker on Command-Line Python Program”. If you face any issues please let me know via the comment section. Share this article with other Java program developers via social networks. Thank You!

Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment