Results 1 to 5 of 5
- 04-12-2012, 08:01 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 3
- Rep Power
- 0
Help needed: Basic subtraction problems
I'm trying to found out how to do basic subtraction in java. I'm semi-new so I don't know everything, and everywhere I search all I can find is how to make a calculator.
All I want to do is print a subtraction between two integers. I have tried doing,
System.out.print(balance-price);
but I am getting errors. Some places have told me to use two dashes but that doesn't work either. Please help!
- 04-12-2012, 08:07 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
- 04-12-2012, 08:26 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 3
- Rep Power
- 0
Re: Help needed: Basic subtraction problems
bad operand types for binary '-'
first type: java.lang.String; second type: int
Im using BlueJ here is the full code
Java Code:public class TicketMachine{ private int price; private int balance; public TicketMachine(int ticketPrice){ price = ticketPrice; balance = 0; } public void insertMoney(int moneyAmount){ balance = balance+moneyAmount; } public int getPrice(){ return price; } public int getBalance(){ return balance; } public void buyTicket(){ if(balance < price){ System.out.println("You do not have enough money to purchase a ticket. "); System.out.print("You need " + price-balance + " more dollars for a ticket."); } else if(balance >= price){ System.out.println("Here is your ticket. Your change is "); System.out.print(balance-price); System.out.println("Enjoy your day."); } } }Last edited by JosAH; 04-12-2012 at 08:33 PM. Reason: added [code] ... [/code] tags
- 04-12-2012, 08:35 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
- 04-12-2012, 08:42 PM #5
Member
- Join Date
- Apr 2012
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Basic Java help needed
By CaptainToenail in forum New To JavaReplies: 5Last Post: 03-03-2013, 01:18 AM -
Double subtraction
By bmbishop in forum New To JavaReplies: 21Last Post: 04-21-2011, 08:03 AM -
Problems with a basic project
By Goff256 in forum New To JavaReplies: 11Last Post: 04-08-2011, 06:24 AM -
ASAP PLZ- Having problems with basic pattern input/output
By ZetaPunk in forum New To JavaReplies: 3Last Post: 09-22-2009, 05:16 AM -
basic help needed
By CurtisJC in forum New To JavaReplies: 2Last Post: 03-02-2009, 07:21 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks