Hi, I was assigned by my teacher to create a simple calculation program about movie tickets that are sold in a local movie theater. So, I created the coding, and it turned out perfect. Here it is:

import java.util.Scanner;

public class MovieTheater
{
    public static void main(String[] args)
    {

    String movieName;
    double adultPrice, childPrice, totalAdultPrice, totalChildPrice, grossAmount, percentageDonation, amountDonated, netSale;
    int adultNumber, childNumber, totalTickets;

    Scanner keyboard = new Scanner(System.in);
    System.out.println(" Enter the Movie Title: ");
    movieName = keyboard.nextLine();
    System.out.println(" Adult ticket price per person: ");
    adultPrice = keyboard.nextDouble();
    System.out.println(" Child ticket price per person: ");
    childPrice = keyboard.nextDouble();
    System.out.println(" Number of adult tickets sold: ");
    adultNumber = keyboard.nextInt();
    System.out.println(" Number of child tickets sold: ");
    childNumber = keyboard.nextInt();
    System.out.println(" Percentage of gross amount to be donated: ");
    percentageDonation = keyboard.nextDouble();

    totalTickets = adultNumber + childNumber;
    totalAdultPrice = adultPrice * adultNumber;
    totalChildPrice = childPrice * childNumber;
    grossAmount = totalAdultPrice + totalChildPrice; 
    amountDonated = (percentageDonation/100) * grossAmount;
    netSale = grossAmount - amountDonated;

    System.out.println(" Movie Name: " + movieName);
    System.out.println(" Number of tickets sold: " + totalTickets);
    System.out.println(" Gross Amount: " + " $ " + grossAmount);
    System.out.println(" Percentage of the gross amount to be donated: " + percentageDonation);
    System.out.println(" Amount Donated: " + " $ " + amountDonated);
    System.out.println(" Net Sale: " + " $ " + netSale);    
    }
    }

BUT, the outputs "Gross Amount", "Percentage", "Amount Donated" and "Net Sale" are not in the same decimal places as you can see in the output I got here:

 Enter the Movie Title: 
Anastasia
 Adult ticket price per person: 
10.50
 Child ticket price per person: 
5.50
 Number of adult tickets sold: 
42
 Number of child tickets sold: 
70
 Percentage of gross amount to be donated: 
20
 Movie Name: Anastasia
 Number of tickets sold: 112
 Gross Amount:  $ 826.0
 Percentage of the gross amount to be donated: 20.0
 Amount Donated:  $ 165.20000000000002
 Net Sale:  $ 660.8

I WANT THEM TO BE IN TWO DECIMAL PLACES ONLY. can someone help show me where to add/correct? Thanks in advance!

Alright, got it now. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.