Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Error: java:50: error: '.class' expected... Problem

$
0
0
Hi guys, I've got work to do with a conversion program and our professor got a bit specific. All in all we have to do this:
Conversion Program (using Methods): Write a program that converts meters to kilometers, inches, or feet depending on the user's selection from a menu.



Your program is required to have the following 4 methods:

showKilometers - This must be a method that accepts the number of meters as an argument and returns the number of kilometers (NOT A VOID METHOD). Convert meters to kilometers using the following formula:

o kilometers = meters * 0.001

showInches - This must be a method that accepts the number of meters as an argument and returns the number of inches (NOT A VOID METHOD). Convert meters to inches using the following formula:

o inches = meters * 39.37



showFeet - This must be a method that accepts the number of meters as an argument and returns the number of feet (NOT A VOID METHOD). Convert meters to feet using the following formula:

o feet = meters * 3.281



showMenu - this must be a void method that accepts no arguments (this one is void). It should display the following menu:



METER CONVERSION

1) Convert to Kilometers

2) Convert to Inches

3) Convert to Feet

4) Quit the Program



Please make a selection:





The program should run as follows:



The program should start (in the main method) by calling the showMenu method to display the menu. The program should then get the user's selection.



Once the program (main method) gets the user's selection it should ask the user for a number of meters. The number of meters the user enters will then be passed as an argument into one of the methods depending on what the user's selection was.



-If the user chose 1, the showKilometers method should be called with the number of meters the user entered passed to it as an argument. The number of meters converted to kilometers should be returned to the main method.

-If the user chose 2, the showInches method should be called with the number of meters the user entered passed to as an argument. The number of meters converted to inches should be returned to the main method.

-If the user chose 3, the showFeet method should be called with the number of meters the user entered passed to it as an argument. The number of meters converted to kilometers should be returned to the main method.

-If the user chose something other than 1-4, an invalid selection message should print and then the menu should re-display. This should NOT require and extra loop, it is part of the menu if-else if or switch.

Once the program (main method) receives the converted number of meters from the: showKilometers, showInches, or showFeet method, it should display the results.



Example output:

500.0 meters is 0.5000 kilometers.
_________________________________--
So far I've tried and have gotten my code until the current point which I will attach. However I'm having problems getting the "ShowKilometers" to work and accept the variable.. Any ideas to why I might be receiving the error message??


import java.util.Scanner;
import java.text.DecimalFormat;

public class Homework8Problem2
{
  public static void main(String[] args)
  {
    showMenu();
  }
  	
  public static double showMenu()
   {
	  Scanner keyboard = new Scanner (System.in);
	  DecimalFormat formatter = new DecimalFormat("#0.000"); 
	  int selection;
	  double meters = 0;
	  double kilometers;
	  double inches;
	  double feet;
	  
	  
	  System.out.println("\nMETER CONVERSION");
	  System.out.println(" 1)Convert to Kilometers");
	  System.out.println(" 2)Convert to Inches");
	  System.out.println(" 3)Convert to Feet");
	  System.out.println(" 4)Quit the Program");
	  System.out.println("Please make a selection:");
	  selection = keyboard.nextInt();
	  	  
	  System.out.println("Please enter the number of meters you want to convert: ");
	  meters = keyboard.nextDouble();
	  
	  if(meters < 0)
	  {
	    System.out.println("Invalid entry.");
		 System.out.println("Please enter a positive number: ");
		 System.out.println("Please enter the number of meters you want to convert: ");
		 meters = keyboard.nextDouble();
	  }

	  while(selection != 4)
	  {
	    if(selection == 1)
		 {
		   showKilometers = double meters;
			
			System.out.println(meters + " meters is " + formatter.format(kilometers) + " kilometers."); 
		 }
		 else if(selection == 2)
		 {
		   showInches(inches);
			
			System.out.println(meters + " meters is " + formatter.format(inches) + " inches.");
		 }
		 else if(selection == 3)
		 {
		   showFeet(feet);
			
			System.out.println(meters + " meters is " + formatter.format(feet) + " feet.");
		 }
		 else if(selection == 4)
		 {
		   System.exit(0);
		 }
		 else
		 {
		   System.out.println("Invalid selection.");
		 }
	  }
	  	  
	}
	
	public static double showKilometers(double meters,double kilometers)
	{
	  return kilometers = meters * 0.001;
	}
	
	public static double showInches(double meters,double inches)
	{
	  return inches = meters * 39.37;
	}
	
	public static double showFeet(double meters,double feet)
	{
	  return feet = meters * 3.281;
	}
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>