Answer to Question #272917 in Java | JSP | JSF for anna

Question #272917

Develop a Java GUI application that will display the petrol cost per litre for three different cities with a time span of three years. Q.1.1 On the form create a list box, to allow a user to select between three different cities. Also create a combo box for the user to select the year. Finally add a submit button. Once the user has selected a city, year and clicked the submit button display the petrol price per litre for that year. Use the following table for the city and yearly petrol prices per litre:


1
Expert's answer
2021-11-29T00:00:24-0500
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
	    Scanner input=new Scanner(System.in);
		System.out.println("1.Johanesburg\n2.Durban\n3.Cape Town\n");
		System.out.print("Select a city");
		int city=input.nextInt();
		System.out.print("Select a year: ");
		int year=input.nextInt();
		if(city==1 && year==2017){
		    System.out.println("Price of petrol for Johanesburg in the year 2017 is 10.72 ");
		}
		else if(city==1 && year==2018){
		    System.out.println("Price of petrol for Johanesburg in the year 2018 is 10.35 ");
		}
		else if(city==1 && year==2019){
		    System.out.println("Price of petrol for Johanesburg in the year 2019 is 10.20 ");
		}
		else if(city==2 && year==2017){
		    System.out.println("Price of petrol for Durban in the year 2017 is 12.75 ");
		}
		else if(city==2 && year==2018){
		    System.out.println("Price of petrol for Durban in the year 2018 is 12.32 ");
		}
		else if(city==2 && year==2019){
		    System.out.println("Price of petrol for Durban in the year 2019 is 12.22 ");
		}
		else if(city==3 && year==2017){
		    System.out.println("Price of petrol for Cape Town in the year 2017 is 13.70 ");
		}
		else if(city==3 && year==2018){
		    System.out.println("Price of petrol for Cape Town in the year 2018 is 13.31 ");
		}
		else if(city==3 && year==2019){
		    System.out.println("Price of petrol for Cape Town in the year 2019 is 13.23 ");
		}
		else{
		    System.out.println("Invalid choices");
		}
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS