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 3 of 3

Thread: Help with simple math in java

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

    Default Help with simple math in java

    Hey everyone, I am new to this and I'm having trouble with my code. I need to calculate gross pay and cannot get my code to work. any suggestions?

    import java.util.Scanner;
    public class theaterProject {
    public static void main(String[] args) {
    String price1;
    int tSold1, gross1;
    String movie;
    double average;
    String tSold11;


    // Robert Winter
    Scanner input = new Scanner(System.in);
    System.out.println("Welcome to Rob Winter's Calculator for calculating profit");


    //Movie Title
    System.out.println("Enter Movie:");
    movie = input.nextLine();
    System.out.println("The Movie is " + movie );


    //Ticket Price
    System.out.println("Enter Ticket Price:");
    price1 = input.nextLine();
    System.out.println("The price is " + price1 );


    //Tickets Sold
    System.out.println("How Many Tickets Sold:");
    tSold11 = input.nextLine();
    System.out.println("Sold Tickets= " + tSold11 );


  2. #2
    Member
    Join Date
    May 2013
    Posts
    106
    My Mood
    Amused
    Thanks
    16
    Thanked 9 Times in 9 Posts

    Default Re: Help with simple math in java

    First off, try wrapping your code in the forum's code tags. {code="java"} and {/code} but with square brackets instead of curly ones. It makes it easier to read.

    Second, your code seems to stop short of calculating anything. The tsold1, gross1, and average variables are never used. Using nextLine() to take in the title of the movie as a string is good, but I don't understand why the price and number of tickets sold are also taken in as strings.

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with simple math in java

    As the previous poster said, wrap the code to make it easier to read. Also I noticed there were no brackets at the very end of the code; only at the beginning.

Similar Threads

  1. Help with simple math game coding
    By jmd in forum Java Theory & Questions
    Replies: 17
    Last Post: February 28th, 2013, 10:49 PM
  2. I need help making a simple math game in java.?
    By bnichs5 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 3rd, 2013, 07:14 AM
  3. [SOLVED] Help with Math.tan and Math.atan
    By Dr.Code in forum Algorithms & Recursion
    Replies: 6
    Last Post: July 2nd, 2012, 05:54 AM
  4. Need help with simple Shopping cart math
    By I hate Java! in forum Loops & Control Statements
    Replies: 3
    Last Post: November 6th, 2011, 10:46 PM
  5. Confusion with Math.toDegrees() and Math.toRadians(). Please help.
    By marksquall in forum Java Theory & Questions
    Replies: 3
    Last Post: June 23rd, 2011, 01:28 AM