How do I add charges based when a user enter yes or no [closed]
up vote
0
down vote
favorite
Working on a coding assignment and we have to incorporate methods and returning it. However, that is the beside the point. I am struggling on the price calculation portion. Okay, here's the gist of what I am stuck with. When the program asks, is your car and import. If the answer is yes, you will be charge with a 7% import tax, if no, the charge is negated. Now, the program asks for four services, depending on yes or no, the charge will be added based on their answer.
So, if the user wants an Oil Change and Tune Up and if their car is an import the services price will be added along with the import tax or if the car is not an import but want all services then the charges will be displayed without the import tax added, etc... The final outcome would display "Before taxes, it would be $# and after taxes, your total is..." An if statement is required but I do not know where to start because I am mainly struggling with the yes or no... Any help? No avail, I am lost using conditions based on the yes or no, any help would be greatly appreciated.
import java.util.Scanner;
public class CarMaintenance
{
public static void main(String args)
{
Scanner keyboard = new Scanner(System.in);
String car;
//capture car
System.out.println("What is the make of your car");
car = keyboard.nextLine();
String answer;
boolean yn;
System.out.println("Is your car an import?");
while (true)
{
answer = keyboard.nextLine();
if (answer.equalsIgnoreCase("yes"))
{
yn = true;
break;
}
else if (answer.equalsIgnoreCase("no"))
{
yn = false;
break;
}
else
{
System.out.println("Sorry, I didn't catch that. Please answer yes or no");
}
}
String services = {"Oil Change", "Coolant Flush", "Brake Job", "Tune Up"};
for(int i=0; i<services.length; i++)
{
System.out.println("Do you want a " +services[i]);
answer = keyboard.next();
}
double amount = 0;
double price = {39.99, 59.99, 119.99, 109.99};
for(int i =0; i<price.length; i++)
{
amount = (price[i] + price [i]);
}
// double total = 0;
double c = 0;
c = car(amount);
// c = car(total);
System.out.println("The price for your services for your" + " " + car + " " + "is" + " "+ c + ".");
}
public static double car(double amount)
{
return (double) ((amount-32)* 5/9);
}
}
java beginner homework
closed as off-topic by IEatBagels, Sᴀᴍ Onᴇᴌᴀ, Jamal♦ Nov 16 at 1:53
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – IEatBagels, Sᴀᴍ Onᴇᴌᴀ, Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
0
down vote
favorite
Working on a coding assignment and we have to incorporate methods and returning it. However, that is the beside the point. I am struggling on the price calculation portion. Okay, here's the gist of what I am stuck with. When the program asks, is your car and import. If the answer is yes, you will be charge with a 7% import tax, if no, the charge is negated. Now, the program asks for four services, depending on yes or no, the charge will be added based on their answer.
So, if the user wants an Oil Change and Tune Up and if their car is an import the services price will be added along with the import tax or if the car is not an import but want all services then the charges will be displayed without the import tax added, etc... The final outcome would display "Before taxes, it would be $# and after taxes, your total is..." An if statement is required but I do not know where to start because I am mainly struggling with the yes or no... Any help? No avail, I am lost using conditions based on the yes or no, any help would be greatly appreciated.
import java.util.Scanner;
public class CarMaintenance
{
public static void main(String args)
{
Scanner keyboard = new Scanner(System.in);
String car;
//capture car
System.out.println("What is the make of your car");
car = keyboard.nextLine();
String answer;
boolean yn;
System.out.println("Is your car an import?");
while (true)
{
answer = keyboard.nextLine();
if (answer.equalsIgnoreCase("yes"))
{
yn = true;
break;
}
else if (answer.equalsIgnoreCase("no"))
{
yn = false;
break;
}
else
{
System.out.println("Sorry, I didn't catch that. Please answer yes or no");
}
}
String services = {"Oil Change", "Coolant Flush", "Brake Job", "Tune Up"};
for(int i=0; i<services.length; i++)
{
System.out.println("Do you want a " +services[i]);
answer = keyboard.next();
}
double amount = 0;
double price = {39.99, 59.99, 119.99, 109.99};
for(int i =0; i<price.length; i++)
{
amount = (price[i] + price [i]);
}
// double total = 0;
double c = 0;
c = car(amount);
// c = car(total);
System.out.println("The price for your services for your" + " " + car + " " + "is" + " "+ c + ".");
}
public static double car(double amount)
{
return (double) ((amount-32)* 5/9);
}
}
java beginner homework
closed as off-topic by IEatBagels, Sᴀᴍ Onᴇᴌᴀ, Jamal♦ Nov 16 at 1:53
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – IEatBagels, Sᴀᴍ Onᴇᴌᴀ, Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.
2
Hi @GhettoLisa, I'm sorry but at the moment your question isn't really on the CodeReview's scope as we require working code that you'd like to make better. Debugging questions or help to implement a feature are off-topic. We'll gladly review your code once you get it working :)
– IEatBagels
Nov 15 at 20:46
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Working on a coding assignment and we have to incorporate methods and returning it. However, that is the beside the point. I am struggling on the price calculation portion. Okay, here's the gist of what I am stuck with. When the program asks, is your car and import. If the answer is yes, you will be charge with a 7% import tax, if no, the charge is negated. Now, the program asks for four services, depending on yes or no, the charge will be added based on their answer.
So, if the user wants an Oil Change and Tune Up and if their car is an import the services price will be added along with the import tax or if the car is not an import but want all services then the charges will be displayed without the import tax added, etc... The final outcome would display "Before taxes, it would be $# and after taxes, your total is..." An if statement is required but I do not know where to start because I am mainly struggling with the yes or no... Any help? No avail, I am lost using conditions based on the yes or no, any help would be greatly appreciated.
import java.util.Scanner;
public class CarMaintenance
{
public static void main(String args)
{
Scanner keyboard = new Scanner(System.in);
String car;
//capture car
System.out.println("What is the make of your car");
car = keyboard.nextLine();
String answer;
boolean yn;
System.out.println("Is your car an import?");
while (true)
{
answer = keyboard.nextLine();
if (answer.equalsIgnoreCase("yes"))
{
yn = true;
break;
}
else if (answer.equalsIgnoreCase("no"))
{
yn = false;
break;
}
else
{
System.out.println("Sorry, I didn't catch that. Please answer yes or no");
}
}
String services = {"Oil Change", "Coolant Flush", "Brake Job", "Tune Up"};
for(int i=0; i<services.length; i++)
{
System.out.println("Do you want a " +services[i]);
answer = keyboard.next();
}
double amount = 0;
double price = {39.99, 59.99, 119.99, 109.99};
for(int i =0; i<price.length; i++)
{
amount = (price[i] + price [i]);
}
// double total = 0;
double c = 0;
c = car(amount);
// c = car(total);
System.out.println("The price for your services for your" + " " + car + " " + "is" + " "+ c + ".");
}
public static double car(double amount)
{
return (double) ((amount-32)* 5/9);
}
}
java beginner homework
Working on a coding assignment and we have to incorporate methods and returning it. However, that is the beside the point. I am struggling on the price calculation portion. Okay, here's the gist of what I am stuck with. When the program asks, is your car and import. If the answer is yes, you will be charge with a 7% import tax, if no, the charge is negated. Now, the program asks for four services, depending on yes or no, the charge will be added based on their answer.
So, if the user wants an Oil Change and Tune Up and if their car is an import the services price will be added along with the import tax or if the car is not an import but want all services then the charges will be displayed without the import tax added, etc... The final outcome would display "Before taxes, it would be $# and after taxes, your total is..." An if statement is required but I do not know where to start because I am mainly struggling with the yes or no... Any help? No avail, I am lost using conditions based on the yes or no, any help would be greatly appreciated.
import java.util.Scanner;
public class CarMaintenance
{
public static void main(String args)
{
Scanner keyboard = new Scanner(System.in);
String car;
//capture car
System.out.println("What is the make of your car");
car = keyboard.nextLine();
String answer;
boolean yn;
System.out.println("Is your car an import?");
while (true)
{
answer = keyboard.nextLine();
if (answer.equalsIgnoreCase("yes"))
{
yn = true;
break;
}
else if (answer.equalsIgnoreCase("no"))
{
yn = false;
break;
}
else
{
System.out.println("Sorry, I didn't catch that. Please answer yes or no");
}
}
String services = {"Oil Change", "Coolant Flush", "Brake Job", "Tune Up"};
for(int i=0; i<services.length; i++)
{
System.out.println("Do you want a " +services[i]);
answer = keyboard.next();
}
double amount = 0;
double price = {39.99, 59.99, 119.99, 109.99};
for(int i =0; i<price.length; i++)
{
amount = (price[i] + price [i]);
}
// double total = 0;
double c = 0;
c = car(amount);
// c = car(total);
System.out.println("The price for your services for your" + " " + car + " " + "is" + " "+ c + ".");
}
public static double car(double amount)
{
return (double) ((amount-32)* 5/9);
}
}
java beginner homework
java beginner homework
asked Nov 15 at 19:59
Ghetto Lisa
1
1
closed as off-topic by IEatBagels, Sᴀᴍ Onᴇᴌᴀ, Jamal♦ Nov 16 at 1:53
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – IEatBagels, Sᴀᴍ Onᴇᴌᴀ, Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by IEatBagels, Sᴀᴍ Onᴇᴌᴀ, Jamal♦ Nov 16 at 1:53
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – IEatBagels, Sᴀᴍ Onᴇᴌᴀ, Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.
2
Hi @GhettoLisa, I'm sorry but at the moment your question isn't really on the CodeReview's scope as we require working code that you'd like to make better. Debugging questions or help to implement a feature are off-topic. We'll gladly review your code once you get it working :)
– IEatBagels
Nov 15 at 20:46
add a comment |
2
Hi @GhettoLisa, I'm sorry but at the moment your question isn't really on the CodeReview's scope as we require working code that you'd like to make better. Debugging questions or help to implement a feature are off-topic. We'll gladly review your code once you get it working :)
– IEatBagels
Nov 15 at 20:46
2
2
Hi @GhettoLisa, I'm sorry but at the moment your question isn't really on the CodeReview's scope as we require working code that you'd like to make better. Debugging questions or help to implement a feature are off-topic. We'll gladly review your code once you get it working :)
– IEatBagels
Nov 15 at 20:46
Hi @GhettoLisa, I'm sorry but at the moment your question isn't really on the CodeReview's scope as we require working code that you'd like to make better. Debugging questions or help to implement a feature are off-topic. We'll gladly review your code once you get it working :)
– IEatBagels
Nov 15 at 20:46
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
2
Hi @GhettoLisa, I'm sorry but at the moment your question isn't really on the CodeReview's scope as we require working code that you'd like to make better. Debugging questions or help to implement a feature are off-topic. We'll gladly review your code once you get it working :)
– IEatBagels
Nov 15 at 20:46