Create three classes the Calculation class, Conversion class and Menu Class.
The Conversion class should have the following methods.
double KMToMiles(double distance)
double MilesToKM(double distance)
double FeetToMetres(double distance)
double MetresToFeet(double distance)
double KgToPounds(double weight)
double PoundsToKg(double weight)
double CelciusToFahrenheit(double temperature)
double FahrenheightToCelcius(double temperature)
The Calculation class should have the following methods
int SumOfSeries(int start, int end, int incr)
int SumOfArray(int data[], int size)
int ProductOfSeries(int start, int end, int incr)
int ProductOfArray(int data[], int size)
e.g. SumOfSeries(10,20,2) should produce the answer 90
Hint : 10+12+14+16+18+20
Similary ProductOfSeries(100,200,50) should produce 3,000,000
Hint : 100x150x200 = 3,000,000

The Menu class should have the following methods
void displayMainMenu()
void displayConversionSubMenu()
void displayCalculationSubMenu()
void displayConversionLengthSubmenu()
void displayConversionWeightSubmenu()
void displayConversionTemperatureSubmenu()
The menu class methods should display the options available under each selected menu. e.g. The
displayCalculationSubMenu() method should display the following.
Calculation Sub Menu

  1. Sum of Series
  2. Sum of Array
  3. Product of Series
  4. Product of Array
  5. Exit
    If the user selects the sum of array option (option 2), your program should input the size of the array,
    get values to the array from the keyboard, create a Calculation type object and invoke the SumOfArray()
    method to calculate the sum of the Array element and to display it. After displaying the answer the
    same sub menu should be displayed. When the user selects Exit (option 0), you should exit from that
    sub menu.
rproffitt commented: Reads like homework or assignment. Show your work. Where did you get stuck? -3

Dani AI

Generated

Keep responsibilities separate and make the logic testable. Put the pure math/conversion routines in one class (no I/O), the series/array algorithms in another, and leave all printing/input to a Menu/controller class. That makes unit testing simple and keeps the menu loop small and readable. As pointed out, show the code you’ve written when you ask for help; as suggested, just start implementing — small, working pieces are easier to fix.

Useful implementation notes and examples:

  • Use named constants for conversion factors and double arithmetic (avoid integer division like 9/5). Return doubles for conversions and validate inputs.
private static final double KM_PER_MILE = 1.609344;
private static final double METRES_PER_FOOT = 0.3048;
private static final double KG_PER_POUND = 0.45359237;

public static double toMiles(double km) { return km / KM_PER_MILE; }
public static double toMetres(double feet) { return feet * METRES_PER_FOOT; }
public static double cToF(double c) { return c * 9.0/5.0 + 32.0; }
  • For series/array operations prefer simple, correct loops; use arithmetic formulas only when you can guarantee the step fits evenly. Watch step == 0, sign mismatches, and overflow. For products use BigInteger if values can grow large.
public static int sumSeries(int start, int end, int step) {
    if (step == 0) throw new IllegalArgumentException("step must not be 0");
    int sum = 0;
    if ((start <= end && step > 0) || (start >= end && step < 0)) {
        for (int i = start; (step > 0) ? i <= end : i >= end; i += step) sum += i;
    }
    return sum;
}

public static BigInteger productSeries(int start, int end, int step) {
    if (step == 0) throw new IllegalArgumentException("step must not be 0");
    BigInteger p = BigInteger.ONE;
    for (int i = start; (step > 0) ? i <= end : i >= end; i += step) p = p.multiply(BigInteger.valueOf(i));
    return p;
}
  • Menu/controller tips: keep display methods separate from handlers, validate Scanner input, call nextLine() after nextInt() to clear input, loop back to the submenu after each action, and catch InputMismatchException.

If you post a short snippet showing what you tried and the exact runtime/compile error, the thread can give specific fixes.

Recommended Answers

All 5 Replies

Anyone have an answer for this question???

The question was never answered because a question was never asked. The OP just posted a homework assignment.

That's basically saying "Here's my homework. Do it for me." That never goes well.

commented: So How can I find the correct answer for this?? +0

You write a Java program as specified in the assignment. Have you even tried to start writing?

commented: yes +0

A tip - the comment tool is used for commenting on a post. Commenting does not cause the thread to be marked as having new content so it will likely not be read. Add a new post to the thread instead.

As for getting help with your code, if you've written some then post it here so we can have a look. Tell us where you are stuck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.