Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objectives One of the primary objectives of this practice assignment is for you

ID: 3600522 • Letter: O

Question

Objectives

One of the primary objectives of this practice assignment is for you to get your Java programming environment up and running. You have three alternatives for the environment (see the Alternative Software Announcement):

Download and install NetBeans

Use the NetBeans desktop on Citrix

Use Eclipse (either your own copy, or the copy on Citrix)

Make sure you view the Media Gallery on accessing Citrix and downloading installing NetBeans.

Let's practice writing some Java methods and refresh our programming skills!

Post your Solutions to the Discussion Forum

When you complete these programs post them (use a new post for each program) in the Practice Programs and Programming Help Discussion forum.

Practice 1

Write a program that accepts a distance in kilometers, sends it to a method which converts it to miles, and then displays the result. The formula for conversion is Miles = Kilometers * 0.6214

Practice 2

Insurance companies suggest that people should insure a building for at least 80 percent of the cost to replace it. Write a program that accepts the cost of a building, sends it to a method which calculates the recommended insurance, and then displays the result in a currency format.

Explanation / Answer

Here are the classes for you:

import java.util.*;
class KilometersToMiles
{
    public static double kilometersToMiles(double kms)
    {
       return kms * 0.6214;
    }
    public static void main(String[] args)
    {
       Scanner sc = new Scanner(System.in);
       System.out.print("Enter the distance in kilometers: ");
       double kms = sc.nextDouble();
       System.out.println(kms + " kms is " + kilometersToMiles(kms) + " miles.");
    }
}

import java.util.*;
import java.text.NumberFormat;
class InsuranceCalc
{
    public static double calcInsurance(double costOfBuilding)
    {
       return 0.8 * costOfBuilding;
    }
    public static void main(String[] args)
    {
       Scanner sc = new Scanner(System.in);
       System.out.print("Enter the cost of building: ");
       double costOfBuilding = sc.nextDouble();
       NumberFormat formatter = NumberFormat.getCurrencyInstance();
       String insuranceCost = formatter.format(calcInsurance(costOfBuilding));
       System.out.println("Recommended insurance cost is: " + insuranceCost);
    }
}