4 Replies - 1591 Views - Last Post: 07 December 2012 - 08:06 AM Rate Topic: -----

#1 punksryan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 31-January 10

Simple Enrollment java program

Posted 07 December 2012 - 07:15 AM

 import java.util.*;
public class enrollment{
	public static void main(String[]args){
		int balance, payment;
		balance = 20000;
		String partial = "partial";
		String full = "full";
		System.out.print("\nEnter Name: ");
		Scanner st = new Scanner(System.in);
		String name = st.nextLine();
		
		System.out.print("\nYour Remaining Balance is: "+balance);
		System.out.print("\nChoose your Payment term(Partial/Full): ");
		String term = st.nextLine();
		
		if(term == partial){
			System.out.print("\nHow much would you like to pay for this quarter: ");
			Scanner in = new Scanner(System.in);
			payment = in.nextInt();
			balance = balance - payment;
			
			System.out.print("\nYour Balance is: "+ balance);
			if(balance > payment){
				System.out.print("\nYou have remaining balance of: " + balance);
			}else if(balance == payment){
				System.out.print("You are already paid");
			}
		}
	}
}
I've been doing this for a week, I always tend to search for some alternative solution, but still it doesn't fit to my program, whenever I answer this question:
System.out.print("\nChoose your Payment term(Partial/Full): ");
		String term = st.nextLine();

it always execute to the end.

I don't know what is wrong about my If condition because I already declare partial as "partial" so I assume that it will take partial and execute the statement. Just need some advice so I can finish the program until to the end at full payment. Any suggestion is deeply appreciated.

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Simple Enrollment java program

#2 punksryan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 31-January 10

Re: Simple Enrollment java program

Posted 07 December 2012 - 07:33 AM

wow, no need to answer this, i had already solve my own problem, Boolean is the key. haha. thanks by the way dream in code. hope this helps other programmer :)
Was This Post Helpful? 0
  • +
  • -

#3 ipushmycar  Icon User is offline

  • D.I.C Regular

Reputation: 86
  • View blog
  • Posts: 390
  • Joined: 29-August 10

Re: Simple Enrollment java program

Posted 07 December 2012 - 07:37 AM

if(term == partial) //doesnt work you need to use .equals() to compare two strings.

if(term.equals(partial))


Was This Post Helpful? 0
  • +
  • -

#4 punksryan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 31-January 10

Re: Simple Enrollment java program

Posted 07 December 2012 - 07:48 AM

oh, I'm really a trash, its either way I make boolean, any thing I type, it always accept true, and still, I'm hopeless. Like what I have said before, any suggestions are deeply appreciated. :)
Was This Post Helpful? 0
  • +
  • -

#5 punksryan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 31-January 10

Re: Simple Enrollment java program

Posted 07 December 2012 - 08:06 AM

View Postipushmycar, on 07 December 2012 - 07:37 AM, said:

if(term == partial) //doesnt work you need to use .equals() to compare two strings.

if(term.equals(partial))



that .... yeah! thanks for the suggestion, it really works, thanks again :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1