Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: A question

  1. #1
    Junior Member
    Join Date
    Sep 2021
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post A question

    How can i display a percentage value in a table format?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: A question

    Use a format control character in a printf method or with the String format method.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2021
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: A question

    how can i display columns in the output and separate them?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: A question

    Set the width in the format string.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Sep 2021
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: A question

    Thandabantu runs a cinema in Sosh. A ticket costs R15-00. He contracts you to develop for him an application that will allow him sell tickets to the clients. The application must allow a client enter the number of tickets she/he wants, determine the final amount which includes VAT of 15%. The application must allow the user to enter the amount due and give change thereafter.

    Here is the code :

    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package ticketapp;
     
    import java.util.Scanner;
     
    /**
     *
     * @author SETH
     */
    public class TicketApp {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // declare variables
            final double TICKET_PRICE = 15.00;
            final double VAT = 0.15;
            double amtDue,change,paymentMade;
            int numOfTickets;
            Scanner sc = new Scanner(System.in);
     
            System.out.println("Please enter the number of tickets: ");
            numOfTickets = sc.nextInt();
     
            amtDue = TICKET_PRICE  * numOfTickets + VAT;
            System.out.println("The amount due is "+amtDue);
     
            System.out.println("Please enter the payment made: ");
            paymentMade = sc.nextDouble();
     
            change = paymentMade - amtDue;
            System.out.println("The change is: "+change);
        }
     
    }

    Here is the output:
    Please enter the number of tickets: 
    3
    The amount due is 45.15
    Please enter the payment made: 
    50
    The change is: 4.850000000000001

    I just wanted to know if i declared the VAT well.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: A question

    It is difficult using floating point variables to represent monetary values. Floating point is not accurate. There will be rounding or truncation errors. It is more accurate to use the BigDecimal class.

    If you use floating point numbers and want to display them to 2 decimal places, you need to use formatting. See the String class's format method or the output class's printf method.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Sep 2021
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: A question

    What is the method used in the character class to determine if a character is a special character?

    --- Update ---

    How to run a program as long as a user wants to?

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: A question

    What is the method used in the character class to determine if a character is a special character?
    Read the API documentation and see if any of the methods are useful for that.
    If you have any questions about what it says in the API doc, copy the text and paste it here.


    How to run a program as long as a user wants to?
    If the program does not exit the main thread, it should continue running.
    Do not exit the program until the user says to.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 1
    Last Post: November 4th, 2013, 05:38 AM