Help how to simplify this problem code.
Is there a way to edit the code to enable that i don have so many if statements..
what can do to improve pls help.
my code is:
public class tradeFair1 {
public static void main(String[]arguments){
double studentM=1.00, studentA=1.20, studentE=3.50;
double SnrCitizenM=1.20,SnrCitizenA=1.50, SnrCitizenE=3.50;
double GenPubM=2.00, GenPubA=2.50, GenPubE=3.50;
boolean weekDays = false;
double price, status;
int day = Console.readInt("Enter 1 for Monday, 2 for Tuesday.....6 for Saturday, 7 for Sunday: ");
int buyer = Console.readInt("Enter 1 for Student, 2 for SnrCitizen, and 3 for GeneralPublic: ");
int timeOfDay = Console.readInt("Enter the timeOfDay 1 for Morning, 2 for afternoon, 3 for evening: ");
int numOfTickets = Console.readInt("Enter the number of Tickets");
if (day >= 1 && day <= 5) {
weekDays = true;
if (buyer==1 && timeOfDay==1) {
status = studentM;
price = numOfTickets*status;;
if (numOfTickets >=10 && numOfTickets <=15)
price = price -(price*0.1);
if (numOfTickets >15)
price = price - (price*0.15);
price = price + (price*0.05);
System.out.println("The price is: $" +price);
if (buyer==1 && timeOfDay==2) {
status = studentA;
price = numOfTickets*status;;
if (numOfTickets >=10 && numOfTickets <=15)
price = price - (price*0.1);
if (numOfTickets >15)
price = price - (price*0.15);
price = price + (price*0.05);
System.out.println("The price is: $" +price);
if (buyer==1 && timeOfDay==3) {
status = studentE;
price = numOfTickets*status;;
if (numOfTickets >=10 && numOfTickets <=15)
price = price - (price*0.1);
if (numOfTickets >15)
price = price - (price*0.15);
price = price + (price*0.05);
System.out.println("The price is: $" +price);
if (buyer==2 && timeOfDay==1) {
status = SnrCitizenM;
price = numOfTickets*status;;
if (numOfTickets >=10 && numOfTickets <=15)
price = price - (price*0.1);
if (numOfTickets >15)
price = price - (price*0.15);
price = price + (price*0.05);
System.out.println("The price is: $" +price);
if (buyer==2 && timeOfDay==2) {
status = SnrCitizenA;
price = numOfTickets*status;;
if (numOfTickets >=10 && numOfTickets <=15)
price = price - (price*0.1);
if (numOfTickets >15)
price = price - (price*0.15);
price = price + (price*0.05);
System.out.println("The price is: $" +price);
if (buyer==2 && timeOfDay==3) {
status = SnrCitizenE;
price = numOfTickets*status;;
if (numOfTickets >=10 && numOfTickets <=15)
price = price - (price*0.1);
if (numOfTickets >15)
price = price - (price*0.15);
price = price + (price*0.05);
System.out.println("The price is: $" +price);
if (buyer==3 && timeOfDay==1) {
status = GenPubM;
price = numOfTickets*status;;
if (numOfTickets >=10 && numOfTickets <=15)
price = price - (price*0.1);
if (numOfTickets >15)
price = price - (price*0.15);
price = price + (price*0.05);
System.out.println("The price is: $" +price);
if (buyer==3 && timeOfDay==2) {
status = GenPubA;
price = numOfTickets*status;;
if (numOfTickets >=10 && numOfTickets <=15)
price = price - (price*0.1);
if (numOfTickets >15)
price = price - (price*0.15);
price = price + (price*0.05);
System.out.println("The price is: $" +price);
if (buyer==3 && timeOfDay==3) {
status = GenPubE;
price = numOfTickets*status;
if (numOfTickets >=10 && numOfTickets <=15)
price = price - (price*0.1);
if (numOfTickets >15)
price = price - (price*0.15);
price = price + (price*0.05);
System.out.println("The price is: $" +price);
else if (weekDays = false) {
if (timeOfDay ==1) {
status = GenPubM;
price = numOfTickets*status+0.50;
price = price + (price*0.05);
System.out.println("The price is: $" +price);
if (timeOfDay ==2) {
status = GenPubA;
price = numOfTickets*status+0.50;
price = price + (price*0.05);
System.out.println("The price is: $" +price);
if (timeOfDay ==3) {
status = GenPubE;
price = numOfTickets*status+0.50;
price = price + (price*0.05);
System.out.println("The price is: $" +price);
this is total aircode - just to give you an idea
class TradeFair1
double[][] prices = {{1.00,1.20,3.50},{1.20,1.50,3.50},{2.00,2.50,3.50}};
double cost = 0;
public TradeFair1()
int buyer = Console.readInt("Enter 1 for Student, 2 for SnrCitizen, and 3 for GeneralPublic: ") - 1;
int timeOfDay = Console.readInt("Enter the timeOfDay 1 for Morning, 2 for afternoon, 3 for evening: ") - 1;;
int numOfTickets = Console.readInt("Enter the number of Tickets");
int day = Console.readInt("Enter 1 for Monday, 2 for Tuesday.....6 for Saturday, 7 for Sunday: ");
double disc;
if(numOfTickets < 10) disc = 1.00;
else if(numOfTickets < 16) disc = 0.90;
else disc = 0.85;
if(day < 6) cost = numOfTickets * prices[buyer][timeOfDay] * disc;
else cost = numOfTickets * prices[2][timeOfDay] + 0.50;
public static void main(String[]arguments){new TradeFair1();}
}
Similar Messages
-
Hi, when ever I'm using 3G, on my Iphone4 sim stops working and network is lost, this started after I updated my phone with 6.0.1(10A523)version. Please help how to solve this problem. Thanks.
Photos/videos in the Camera Roll are not synced. Photos/videos in the Camera Roll are not touched with the iTunes sync process. Photos/videos in the Camera Roll can be imported by your computer which is not handled by iTunes. Most importing software includes an option to delete the photos/videos from the Camera Roll after the import process is complete. If is my understanding that some Windows import software supports importing photos from the Camera Roll, but not videos. Regardless, the import software should not delete the photos/videos from the Camera Roll unless you set the app to do so.
Photos/videos in the Camera Roll are included with your iPhone's backup. If you synced your iPhone with iTunes before the videos on the Camera Roll went missing and you haven't synced your iPhone with iTunes since they went missing, you can try restoring the iPhone with iTunes from the iPhone's backup. Don't sync the iPhone with iTunes again and decline the prompt to update the iPhone's backup after selecting Restore. -
my Creative Cloud subscription has expired, and I assigned the monthly payment, but I can not open any progam creative cloud, I need help how to solve this problem
Carlos-
Start by signing out and back in to see if it will see the subscription:
How to sign in and sign out of creative cloud (activate/deactivate)
If the apps are installed fine and close after launch see this link:
CC applications close immediately after launch
If the problem is something different, please let us know the error you see or what is happening on the screen so we can advise you on a solution
Pattie -
Mozilla Firefox is not allowing me to Copy and Paste, please help how to fix this problem
i seem to have a problem with Mozilla Firefox, that when i tried copying a word or a sentence and then going to a different site, i Cannot Paste. and with Internet Explorer i able to do that. i would hate to stop using firefox cause of this but, it's really hurting me from browsing and moving forth in a fast paced , please help me how to fix it
See:
*http://kb.mozillazine.org/Granting_JavaScript_access_to_the_clipboard
*https://addons.mozilla.org/firefox/addon/allowclipboard-helper/ - AllowClipboard Helper -
HT4059 Help how to correct this problem?
How to correct : when you are in the I books store and you go to down load but a pop up say's: Account not in this store
Your account is not valid for use in the Canadian store. You must switch to the U.S. store before purchasing. When I thought I was in the U.S. store all along. I have tried several things but none have worked.Click here and follow the instructions to change the iTunes Store country.
(83678) -
I Try to open an Indesign document. The message: it is made in a newer version. Go tot CC: Help/Give your Adobe id/Start Indesign again and try to open the document. This doesn’t work. How to solve this problem?
What version are you running?
What version was it made with? -
Hello guys..!! I have got my new iphone 4 2 days ago.The same day it got a problem of auto restart in every 1, to 2 minutes. I updated and restored it many times...but of no use... can any one help me how to solve this problem..!!
Go to Settings/General/Reset - Erase all content and settings. the connecto to iTunes and restore as a New phone. Do not restore any backup. If the problem persists you have a hardware problem. Take it to Apple for exchange.
This assumes that the phone is not hacked or jailbroken. If it is you will have to go elsewhere on the internet for help. -
Hi, I'm unable to use my speaker when I'm using Mac OS, which means I'm unable to unmute, decrease or increase the volume. However, I'm able to do so for Windows 7 OS on Bootcamp. Can anyone please advise on how to rectify this problem? I would greatly appreciate your help, thank you.
Hi Zac, sorry to hear about your troubles, but that's why us other users are here to try to help in these instances.
Open Console in Utilities & see if there are any clues or repeating messages when this connection drop happens. -
I have a problem in my iphone 4 with wi-fi after update to IOS6 please can help my how can solve this problem?
Nope
One needs to press the home and sleep / wake keys together for the phone to reset
The other thing I could recommend
Let the battery run out and the phone completely "die"
It may take a day or two with it not being used
Then plug it in to charge and see if there is any change in behavior
If you cannot get this to work - you may need to bring it to an Apple store -
Hi my iphone 4 is disabled how can solve this problem? help me please
hi my iphone 4 is disabled how can solve this problem? help me please
What do you mean by "disabled"? Disabled by entering the wrong passcode? If so, you'll have to force the phone into recovery mode & restore it to get it working again & remove the passcode:
Turn your phone off, then force it into recovery mode & restore it:
Leave the USB cable connected to your computer, but NOT your phone, iTunes running, press & hold the home button while connecting the USB cable to your dock connector, continue holding the home button until you see “Connect to iTunes” on the screen. You may now release the home button. iTunes should now display that it has detected your phone in recovery mode, if not quit and reopen iTunes. If you still don’t see the recovery message repeat these steps again. iTunes will give you the option to restore from a backup or set up as new. -
Hello
THIS IS RAZA
I GOT A MACBOOK PRO
I HAVE A PROBLEM. PROBLEM IS how to solve this problem i have uploaded in .... all the time few days later on i face this problem in safari..... anyone can help me please.....thanksThis is a scam. Do not phone these people, at best they will charge you for unnecessary 'cleaning' and at worst they will gain access to your Mac and steal your data. You've probably managed to install some 'adware' which is producing this fake warning. 'Adwaremedic' should remove it and is safe to use - please see
http://www.adwaremedic.com/index.php -
I bought CS6 creative suite. As of now i need to work each application in separate separate system. Can any one please help me how to solve this problem.
I saw the below quote on Adobe forum
"You may install software on up to two computers. These two computers can be Windows, Mac OS, or one each."
If i install each application in single single system the system count is more than two. In this case, are we have any license issue? Please advice how the problem will solve?
If possible please send the advise to my mail id: <Removed by Moderator>
Thanks
Uvaraj SI already answered that. If you purchased a Suite then you can only install and activate it on two machines. Even if you only insdtall one of the applications of that suite, it counts as one activation of the suite. You cannot take the six or seven different applications that might be in a suite and install and activate them in six or seven different machines... only two machines.
If your scenario will allow for it, one thing you can do is install the programs on all the different machines and only activate two of the machines at any given time. If you need to activate a program on a third machine then you need to deactivate on one of the currently activate machines first so that you have an open activation to use again. I do not remember if there is a limit to the total number of activations you can process for the life of the software. -
when i tried to watch a tv channel on livetvchannelsfree.in it says that the source code is protected by html guardian. in firefox 3.6 beeta5 i did not come across this problem. but now in latest version i am unable to watch any tv channel. canyou please tell me how to solve this problem?
Forgotten Passcode or device disabled after entering wrong passcode
-
My Iphone 4s reciever is not working properly, when i call someone from my iphone 4s. can any one help me how to solve this problem?
You might like to define "not working properly".
-
Error with universalis responsive template. Prices appear with 163; code before them instead of £ sign. Does anyone know how to fix this problem?
Error with universalis responsive template. Prices appear with 163; code before them instead of £ sign. Does anyone know how to fix this problem?
Maybe you are looking for
-
Why iPhoto 9.4 get crash with the latest OSX 10.8.2 ?can you help
can't understand why this happen as soon as i updeate my iphoto to 9.4 the program screen start to run from one desktop to other !!!! can't even rename the faces and the program start to do the same ... is this problem due to the prgrams of to other
-
I cannot install several apps on my bb 9360 (Vodafone Ro) - qik, shazam, eagleeye, etc. For all of these i get the error message The Item is not available for your Device Model, Device OS, Carrier and Country combination. Pls advise.
-
How to enable soa gateway in oracle apps r12?
how to enable soa gateway in oracle apps r12?
-
How can I load images without XML, please?
Hello Everyone, I would highly appreciate it if someone can point me into the right direction. I have some AS2 code which loads up the images via an xml file. I have been asked to eliminate XML entirely and have images be loaded from with in the libr
-
Load Balancing in EJB ???
Hi everyone Can anyone guide me how can I achieve failover/IIOP load balancing in EJB. Thanks, AA