IntercortAirways
Tried my best to convert the code from c++ into java
A program use to record the total weight that a flight can carry load. Then parcels are loaded into the flight until it full. There are 3 flights. In the end user can generate a report all flights and how much profits gained. I used Netbeans to create and run my code. Below are the print screens.





















Code:





















Code:
/** To change this license header, choose License Headers in Project Properties.* To change this template file, choose Tools | Templates* and open the template in the editor.*/package intercortairways;import java.util.Scanner;/**** @author Yvonne Kwarteng*/public class IntercortAirways {/*** @param args the command line arguments*///public variablespublic static int i=0, y=0, x=0; //setup lools for element of parcels.public static int space1=0, space2=0, space3=0; // for calculating space left over// after entering parcels.public static int load_limit1; // load_limit for flight no.1.public static int weight1; //reading of parcels for flight no.1.public static int totweight1; // totalweight for flight no.1 initailisedpublic static int total=0;public static float average_utilisation; // average for all the flights.public static float total_Revenue; // revenue for all the flighs.public int choice; // reading for entering choice enter meun.//utilisations for the flightspublic static float flight_utilisation1,flight_utilisation2, flight_utilisation3;//revenue for the flights.public static float flight_revenue1, flight_revenue2, flight_revenue3;public static int load_limit2; //load_limit for flight no.2.public static int weight2; // reading of parcels for flight no.2.public static int totweight2; // totalweight for flight no.2 initailised.public static int load_limit3; // load limit for flight no.3.public static int weight3; // reading of parcels for flight no.3.public static int totweight3; //total weight for flight no.3 initailised.public static int totweight, load_limit;//public menu();public static void main(String[] args) {// TODO code application logic here//call mainmain();}//static methods are used to control the error of not static variable or static//method not calling at main abovepublic static void main(){Scanner reader = new Scanner(System.in); // Reading from System.inSystem.out.println("Enter your choice: ");int n;do{menu();n = reader.nextInt(); // Scans the next token of the input as an int.switch(n){case 1: load_flight1();break;case 2: load_flight2();break;case 3: load_flight3();break;case 4: generate_report(totweight, load_limit);//case 4: generate_report();break;case 5: exit();break;default: System.out.println("Invalid menu choice");System.out.println("press any key:");}}while ((n!=1) && (n!=2) && (n!=3) && (n!=4) && (n!=5));}public static void menu(){System.out.println("=========================================");System.out.println("Y Y");System.out.println("Y INTERSCORT AIRWAYS LTD Y");System.out.println("Y Y");System.out.println("=========================================");System.out.println("Y Y");System.out.println("Y 1. Load_flight1 to Aircraft Y");System.out.println("Y Y");System.out.println("Y 2. load_flight2 to Aircraft Y");System.out.println("Y Y");System.out.println("Y 3. load_flight3 to Aircraft Y");System.out.println("Y Y");System.out.println("Y 4. Generate_report Y");System.out.println("Y Y");System.out.println("Y 5. Exit Y");System.out.println("Y Y");System.out.println("=========================================Y");}public static void load_flight1(){Scanner reader = new Scanner(System.in); // Reading from System.inSystem.out.println("Enter flight no.1 load limit in kg: ");// for reading load limit//int s;//for reading parceldo{load_limit1 = reader.nextInt(); // Scans the next token of the input as an int.System.out.println("total limit1 " + load_limit1);System.out.println("\nEnter the weight of parcel no. " + i + ":");weight1 = reader.nextInt(); // Scans the next token of the input as an int.i=i++;totweight1=weight1+totweight1; // calculations for total weight.// calculations for space left over after entering parcels.space1=load_limit1-totweight1;space1++;//1; // increment space left over.if (load_limit1-totweight1==0){//go to mainmain();}System.out.println("\nspace left is: " + space1 + "kg");//System.out.println("\nspace left is: " + space1++ + "kg");if(totweight1>load_limit1){System.out.println("\n********Parcel rejected - refer to next flight.******");totweight1=totweight1-weight1; //weight is substruct from total weight.i=i-1; // array of parcels is decrement from loop.}main();}if (weight1==0)main();weight1=weight1-1; //decrement parcel.}while (weight1!=0);main();}//end of flight 1public static void load_flight2(){//clrscr ();int total;Scanner reader = new Scanner(System.in); // Reading from System.inSystem.out.println("Enter flight no.2 load limit in kg: ");do{load_limit2 = reader.nextInt(); // Scans the next token of the input as an int.System.out.println("total limit1 " + load_limit2);System.out.println("\nEnter the weight of parcel no. " + y + ":");weight2 = reader.nextInt(); // Scans the next token of the input as an int.//for reading parcel weightsy=y++;totweight2=weight2+totweight2; // calculation for total weight.// calculations for space left over after enter parcels.space2=load_limit2-totweight2;space2++; //increment loop for space left.if (load_limit2-totweight2==0){//go to mainmain();}System.out.println("\nspace left is: " + space2 + "kg");//System.out.println("\nspace left is: " + space2++ + "kg");if(totweight2>load_limit2){System.out.println("\n********Parcel rejected - refer to next flight.******");totweight2=totweight2 - weight2; //weight is substruct from total weight.y=y-1; // array of parcels is decrement from loop.main();}if (weight2==0)main();weight2=weight2-1; //decrement reading parcel.}while (weight2!=0);main();//menu();}public static void load_flight3 (){Scanner reader = new Scanner(System.in); // Reading from System.inSystem.out.println("Enter flight no.3 load limit in kg: ");//int load_limit3;// for reading load limitdo{load_limit3 = reader.nextInt(); // Scans the next token of the input as an int.System.out.println("total limit1 " + load_limit3);System.out.println("\nEnter the weight of parcel no. " + x + ":");weight3 = reader.nextInt(); // Scans the next token of the input as an int.x=x++;totweight3=weight3+totweight3; // calculations for total weight.// calculations for space left over after enter parcels.space3=load_limit3-totweight3;space3++; //increment loop for space left.if (load_limit3-totweight3==0){//go to mainmain();}//System.out.println("\nspace left is:" + space3++ + "kg");System.out.println("\nspace left is:" + space3 + "kg");if(totweight3>load_limit3){total=weight3;System.out.println("\n********Parcel not accepted.******");totweight3=totweight3-total; //weight is substruct from total weight.x=x-1; // array of parcels is decrement from loop.main();}if (weight3==0)main();weight3=weight3-1; //decrement reading parcel.}while (weight3!=0);//send data to generate reportgenerate_report(totweight1,load_limit1);//send data to generate reportgenerate_report(totweight2,load_limit2);//send data to generate reportgenerate_report(totweight3,load_limit3);main();//menu();}public static void generate_report (int totweight,int load_limit)//public static void generate_report (){System.out.println("*****************************************");System.out.println("\n* *");System.out.println("\n* DAILY PAYLOAD CONTROL SYSTEMS *");System.out.println("\n* *");System.out.println("\n* *");System.out.println("\n***************************************");if(totweight1==0 || load_limit1==0){System.out.println("they are empty");System.out.println(" total weight for flight 1 " + totweight1 + " load limit flight 1 " + load_limit1);}//utilisation calculation for flight no.1.flight_utilisation1=(totweight1/load_limit1) * 100;System.out.println("print " + i);//calculation of revenue for flight no.1.flight_revenue1=(float) ((10 * i)+(1.50*totweight1));System.out.println("\n*******flight No.1 loading Completed,\n" + flight_utilisation1+ "%Utilisation********\n");System.out.println("*******Revenue for" + i +"Parcels, £" + flight_revenue1+ "**********\n");//utilisation calculation for flight no.2.flight_utilisation2=(totweight2/load_limit2) * 100;//calculation of revenue for flight no.2.flight_revenue2=(float) ((10 * y)+(1.50*totweight2));System.out.println("\n*******flight No.2 loading Completed,\n" + flight_utilisation2+"%Utilisation********\n");System.out.println("*******Revenue for " + y +" Parcels, £" + flight_revenue2+ "**********\n");System.out.println(" total weight for flight 3 " + totweight3 + " load limit flight 3 " + load_limit3);//utilisation calculation for flight no.3.flight_utilisation3=(totweight3/load_limit3) * 100;//calculation of revenue for flight no.3.flight_revenue3=(float) ((10 * x)+(1.50*totweight3));System.out.println("\n*******flight No.3 loading Completed,\n " +flight_utilisation3+" %Utilisation********\n");System.out.println("*******Revenue for " + x +" Parcels,£" +flight_revenue3+ " **********\n");//calculations of average utilisation for all the flights.average_utilisation=(flight_utilisation1+flight_utilisation2+flight_utilisation3)/3;//calculations of revenue of the day for all the flights.total_Revenue=flight_revenue1+flight_revenue2+flight_revenue3;System.out.println("\nThe average utilisation of all the flights are: " + " % "+ average_utilisation);System.out.println("\nThe revenue for the day is: " + "£" + total_Revenue);System.out.println("\nPress any key to continue: ");menu();}public static void exit (){System.out.println("The program is finish." + "Good bye!!");}}
Comments
Post a Comment