Results 1 to 4 of 4
Thread: Adding 2
- 11-01-2012, 12:45 AM #1
Member
- Join Date
- Nov 2012
- Posts
- 2
- Rep Power
- 0
Adding 2
In the code I am trying to add "2" if you enter a higher number than 10 (in package A). I want to add "2" to the value of "one" for example
if you enter:
11 you get 11.95 (since one = 9.95 + 2)
12 you get 13.95 (since two = 11.95+2)
etc
Im trying to do this WITHOUT using a loop i know how to do it with a loop but i am trying to find a way to do an algorithm instead.
Any help would be great thanks.
Java Code:package months; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; public class Months { public static void main(String[] args) throws IOException { Scanner user_input = new Scanner( System.in ); String Name,LetterAsString; char packages; int hours; double one = 9.95; double two = 14.95; double three = 19.95; //input System.out.print("Customer Name:"); Name = user_input.next(); System.out.print("Which package was purchased:"); packages = (char)System.in.read(); if(packages == 'A' || packages == 'B' || packages == 'C' || packages == 'a' || packages == 'b' || packages == 'c') { System.out.print("How Many hours were used:"); hours = user_input.nextInt(); if (packages == 'A' || packages == 'a') { if (hours <= 10) { System.out.println("Customer Name: " + Name); System.out.println("Package: " + packages); System.out.println("The total amount due is: $" + one); } else if (hours > 10) { double num = 0; hours= (int) (one +2); System.out.println("The total amount due is: $" + hours); } } if (packages == 'B' || packages == 'b') { if (hours <= 20) { System.out.println("Customer Name: " + Name); System.out.println("Package: " + packages); System.out.println("The total amount due is: $" + two); } else if (hours > 20) { System.out.println("The total amount due is: $" + two); } } if (packages == 'C' || packages == 'c') { System.out.println("Customer Name: " + Name); System.out.println("Package: " + packages); System.out.println("The total amount due is: $" + three); } } else if(packages != 'A' || packages != 'B' || packages != 'C' || packages != 'a' || packages != 'b' || packages != 'c') { System.out.println("Invalid Entry"); } } }
- 11-01-2012, 12:48 AM #2
Re: Adding 2
So... what's the problem? Does it give an error? Does it not do what you want it to do? If so, what did it do, and what did you expect it to do?
- 11-01-2012, 01:23 AM #3
Re: Adding 2
If I understand correctly then perhaps you need: (n-10) * 2 + 9.95
- 11-01-2012, 01:31 AM #4
Member
- Join Date
- Nov 2012
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
adding two objects
By apiwowar in forum New To JavaReplies: 4Last Post: 09-15-2011, 03:38 AM -
Adding all elements of an Array together, not adding up correctly
By Teclis in forum New To JavaReplies: 1Last Post: 04-05-2011, 08:58 PM -
Adding to a HashSet
By Neivaed in forum New To JavaReplies: 6Last Post: 12-05-2010, 06:16 PM -
Adding folders to a Jar
By IamKira in forum NetBeansReplies: 5Last Post: 01-22-2010, 06:03 PM -
Adding
By natep67 in forum New To JavaReplies: 2Last Post: 04-22-2009, 07:51 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks