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

# Thread: Help with simple math in java

1. ## 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. ## 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. ## 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.