Question

# A new city “Ballymanus” has been announced in a state in Australia and the state government has planned to extend the public transport where the fares will be calculated according to the existing fare...

The code is implemented in java which is an OOP language

If you face any difficulty in understanding the code..please let me know..

I have provided detailed comments for your understanding and also attached the screenshot

**********************************************************************************************************************************************

Code:

import java.util.*;
public class Main
{
static double moveMoneyFullfare [] = new double [] {8.80,6.40};//Weekdays (Daily), Weekends (Daily)
static double moveMoneyConcession [] = new double [] {4.40,3.20};//Weekdays (Daily), Weekends (Daily)
static double movePassFullfare [] = new double [] {44.00,5.30};//Weekly rate (7 days pass), Daily rate for 28-365 days
static double movePassConcession [] = new double [] {22.00,2.65};//Weekly rate (7 days pass), Daily rate for 28-365 days
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int fareType,weekdays, weekends,weeks;
System.out.println("Fare type: 1 OR 2 (1= Full fare, 2= Concession)");
fareType = sc.nextInt();
System.out.println("Number of days to travel on weekdays: a number between 0 and 5");
weekdays = sc.nextInt();
System.out.println("Number of days to travel on weekends: a number between 0 and 2");
weekends = sc.nextInt();
System.out.println("Number of weeks you are planning to travel: a number between 1 and 52");
weeks = sc.nextInt();

double fullFare = calculeteFareForFullFare(weekdays, weekends,weeks);
double concession = calculeteFareForConcession(weekdays, weekends,weeks);
if(fareType == 1)
System.out.println("You chose full fare.\nYour total fare = \$"+fullFare);
else
System.out.println("You chose concession fare.\nYour total fare = \$"+fullFare);

System.out.println("The recommendation option for cost effective fare for the user : " + (fullFare<concession?"Full Fare i.e \$"+fullFare:"Concession i.e \$"+concession));
}

public static double calculeteFareForFullFare(int weekdays, int weekends, int weeks){
double fare = 0;
fare+=moveMoneyFullfare[0]*weekdays;//calculation for weekdays
fare+=moveMoneyFullfare[1]*weekends;//calculation for weekends
if(weeks<=4)//calculation for weeks less than or equal to 4
fare+=movePassFullfare[0]*weeks;
else//calculation for weeks more than 4
fare+= (movePassFullfare[0]*4) + (movePassFullfare[1]*((weeks-4)*7));
return fare;
}

public static double calculeteFareForConcession(int weekdays, int weekends, int weeks){
double fare = 0;
fare+=moveMoneyConcession[0]*weekdays;//calculation for weekdays
fare+=moveMoneyConcession[1]*weekends;//calculation for weekends
if(weeks<=4)//calculation for weeks less than or equal to 4
fare+=movePassConcession[0]*weeks;
else//calculation for weeks more than 4
fare+= (movePassConcession[0]*4) + (movePassConcession[1]*((weeks-4)*7));
return fare;
}
}

**********************************************************************************************************************************************

Output screenshot:

**********************************************************************************************************************************************

#### Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions