Write a program that computes the fare on the Copenhagen Transit system given two inputs from the user: The zone number. The passenger type. Your prompts to the user must be : Enter zone number :...

1 answer below »

Write a program that computes the fare on the Copenhagen Transit system given two inputs from the user:






  • The zone number.




  • The passenger type.






Your prompts to the user must be :


Enter zone number :

Enter adult or child :


The fare on Copenhagen Transit is specified as follows:




  • If the zone is 2 or smaller and the ticket type is "adult," the fare is 23.0.




  • If the zone is 2 or smaller and the ticket type is "child," the fare is 11.5.




  • If the zone is 3 and the ticket type is "adult," the fare is 34.5.




  • If the zone is 3 or 4 and the ticket type is "child," the fare is 23.0.




  • If the zone is 4 and the ticket type is "adult," the fare is 46.0.




  • If the zone is greater than 4, the fare is -1.00 (since your calculator does not handle inputs that high).






Your output must be of the format:


The fare for adultOrChild to zone number zoneNumber is fare.



Please note that your class should be named CopenhagenTransit.






Homework 4-2


Write a program that asks the user for their age in days. The program will compute the person's age in years (you can assume that all years have 365 days) and then prints one of the following messages:






  1. If the user is 1 year old or younger, print: "You are an infant"




  2. If the user is over 1 year old and 3 years old or younger, print: "You are a toddler"




  3. If the user is over 3 years old and 12 years old or younger, print: "You are a child"




  4. If the user is over 12 years old and 19 years old or younger, print: "You are a teenager"




  5. If the user is over 19 years old and 21 years old or younger, print: "You are a young adult"




  6. If the user is over 21 years old and 50 years old or younger, print: "You are an adult"




  7. If the user is over 50 years old but 65 years old or younger, print: "You are middle aged"




  8. If the user is over 65 years, print: "You are a senior citizen"






For example:




If the user entered: 350, your program would output: You are an infant

If the user entered: 800, your program would output: You are a toddler

If the user entered, 1825, your program would output: You are a child

If the user entered, 5475, your program would output: You are a teenager

If the user entered, 7300, your program would output: You are a young adult

If the user entered, 10950, your program would output: You are an adult

If the user entered, 23725, your program would output: You are middle aged

If the user entered, 25550, your program would output: You are a senior citizen


Your prompt to the user to enter the number of days must be:


Enter an age in number of days :


Please note that your class should be named AgeLabel.






Homework 4-3


Write a Java program that asks the user for a date entered as 4 integers: dayNumber monthNumber date year. Where:




dayNumber


An integer from 1-7, where 1 = Sunday, 2 = Monday, ..., 7 = Saturday




monthNumber


An integer from 1-12, where 1 = January, 2 = February, ..., 12 = December




date


An integer from 1-31 representing the date.




year


An integer representing the year.




_____________________________________________________________________________________________




Your prompt to the user should be:


Enter 4 integers representing dayNumber monthNumber date year:


_____________________________________________________________________________________________



You program will compute the proper dayName from the specified dayNumber and the proper monthName from the specified monthNumber. Your program will print out the specified date in the following format:




dayNumber monthNumber date year is dayName monthName date, year


Please note your program will have to error check the input as follows:






  1. First the dayNumber is checked for being in the range 1..7. If that is not the case, your program should print out the following message and terminate execution:



    Invalid day number: dayNumber, please enter a number from 1..7.




  2. Then the monthNumber is checked for being in the range 1..12. If that is not the case, your program should print out the following message and terminate execution:



    Invalid month number: monthNumber, please enter a number from 1..12.




  3. Then the date is checked for being in the range 1..31. If that is not the case, your program should print out the following message and terminate execution:



    Invalid date number: date, please enter a number from 1..31.




  4. Then the date must be checked for validity. For example, there is no February 30, February 31, April 31, June 31, September 31, November 31. If the date is invalid, your program should print out the following message and terminate execution:



    Invalid date: monthName, does not have date days, please enter a valid date.




  5. Lastly, if the monthNumber = 2, and date = 29 you must verify that the year entered is a leap year, which is the only time that February 29 exists. Please see
    Wikipidia's Page on Leap Year. If the year is not a leap year and the user entered a date = 29, your program should print out the following message and terminate execution:



    Invalid date: year is not a leap year, February does not have date days, please enter a valid date.



Please note that your class should be named DateConverter.
Answered Same DayMar 02, 2021

Answer To: Write a program that computes the fare on the Copenhagen Transit system given two inputs from the...

Aditya answered on Mar 03 2021
149 Votes
import java.util.Scanner;
public class AgeLabel {
    public static void main(String[] args) {
        Sca
nner sc = new Scanner(System.in);
        System.out.println("Enter an age in number of days: ");
        int age = sc.nextInt();
        int year = age / 365;
        if(year <= 1)
        {
            System.out.println("You are...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here