How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site. Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask LogicPro Your Own Question
LogicPro, Computer Software Engineer
Category: Programming
Satisfied Customers: 13425
Experience:  Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.
Type Your Programming Question Here...
LogicPro is online now

Help! I'm very new to java programming and am trying to write

This answer was rated:

I'm very new to java programming and am trying to write a code for an assignment but can only get so far. I must produce a Java console application that prompts user to enter child ages and displays cost of travel for the family.(Family consisting of 2 adults and 1 or more children) Adult ticket is 421eurs and a child is under 18. tickets for under 2 cost 25% of adult ticket and under 12 costs 50%, and under 18 75%.The program must prompt user to enter number of children or 0 to exit. Then they are prompted in turn for the number of children under 2 and under 12. The total cost of tickets is to be displayed and breakdown of cost and total child discount. This is as far as I've got:
import java.util.Scanner;
public class ChildDiscount {
public static void main(String[] args) {
// TODO Auto-generated method stub
double adultTicketPrice = 421.00;
double childUnder2Discount = 0.75;
double childUnder12Discount = 0.50;
double childUnder18Discount = 0.25;
int numAdults = 2;
//Create scanner to read input from keyboard
Scanner scan = new Scanner(;
//Prompt user
System.out.println("Number of Children");
int numKids = scan.nextInt();
// while number of children >0 add number to total
while (numKids > 0){
System.out.println("Number of Children under 2");
int numKidsUnder2 = scan.nextInt();
System.out.println("Number of Children under 12");
int numKidsUnder12 = scan.nextInt();
System.out.println("Number of Children under 18");
int numKidsUnder18 = scan.nextInt();
double costAdultTickets = numAdults * adultTicketPrice;
double grossCostTicketsUnder2 = numKidsUnder2 * adultTicketPrice;
double discountTicketsUnder2 = adultTicketPrice * childUnder2Discount * numKidsUnder2;
double netCostTicketsUnder2 = grossCostTicketsUnder2 - discountTicketsUnder2;
double grossCostTicketsUnder12 = numKidsUnder12 * adultTicketPrice;
double discountTicketsUnder12 = adultTicketPrice * childUnder12Discount * numKidsUnder12;
double netCostTicketsUnder12 = grossCostTicketsUnder12 - discountTicketsUnder12;
double grossCostTicketsUnder18 = numKidsUnder18 * adultTicketPrice;
double discountTicketsUnder18 = adultTicketPrice * childUnder18Discount * numKidsUnder18;
double netCostTicketsUnder18 = grossCostTicketsUnder18 - discountTicketsUnder18;
OOps, copy and paste makes it look messy. Any help would be appreciated. Mebh.
Hi,What is the deadline?
Customer: replied 2 years ago.
Next wednesday morning!!
Looking at the efforts, I am sending small revised offer. let me know once you accept it.
LogicPro and other Programming Specialists are ready to help you
thank you.Please check back in few hours for the answer.
Customer: replied 2 years ago.
A few hours??? ok.
10-12 hours
Customer: replied 2 years ago.
ok thanks
Here is working code: Please consider adding bonus\ You can ask me again using "For LogicPro only" at the start of your questions like other customers to get instant answers. It will ensure that question is for me.Please bookmark my profile page: you can come back and ask me a question anytime. Thank you for using this site! LogicPro
Customer: replied 2 years ago.
For LogicPro
Thank you!!! The program works wonderfully.
Thank you