Question

In: Computer Science

Complete each of the programs here. Create a separate Netbeans project for each program using the...

Complete each of the programs here. Create a separate Netbeans project for each program using the name I specified. Create a single java main class for each of the programs using the filename I specified.

Task 1: (5 points)
Project name: CtoFConverter
Main file name: TempConverter.java
A program that converts an inputted temperature in C and provides the equivalent temperature in F. Hint: Google is your friend! Given C, solve for F. Again, check for a valid input value and only respond with the F value if you got it, otherwise output an appropriate error msg to the user. Testing: 3 conditions: Bad Input, then test for the known freezing and boiling points.

EMBED SCREEN SHOT(S) OR COPY THE OUTPUT WINDOW OF NETBEANS HERE SHOWING YOUR PROGRAM TEST RUN(S):

Task 2: (5 points)
Project name: FuelCosts
Main file name: FuelCost.java
Write a program that asks the user to input
• The number of gallons of gas currently in the tank
• The fuel efficiency in miles per gallon
Then print how far the car can go with the gas in the tank. Again, check for valid input and exit with an error msg if you do not have it. Testing: here just use some reasonable values that you can inspect the calculations and determine they are correct.

Solutions

Expert Solution

Here is your required code in JAVA:

A)

import java.util.Scanner;

public class TempConvertor
{
// converts Celsius to Fahrenheit scale
static float convert(float n)
{
return ((n * 9.0f / 5.0f) + 32.0f);
}
  
// Driver code
public static void main(String[] args) {
  
Scanner sc = new Scanner(System.in);
  
//number of test cases
//chnage accordingly
int t=4;
for(int i=0;i<t;i++)
{
try
{
float c;
System.out.println("\nTest Case "+i+": ");
System.out.print("Enter temperature in Celsius: ");
  
//taking input
c = sc.nextFloat();
  
//displaying output
System.out.println("Temperature in Fahrenheit: " + convert(c));
}
catch(Exception e)
{
//displaying error
System.out.println("Error: Bad Input!");
}
}
}
}

B)

import java.util.Scanner;

public class FuelCosts
{
// calculate maximum distance that can betraveled
static double max_dis(double fuel, double efficiency)
{
return efficiency * fuel;
}
  
// Driver code
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
  
//number of test cases
//chnage accordingly
int t=4;
for(int i=0;i<t;i++)
{
try
{
float f, e;
Exception ex = new Exception();
  
System.out.println("\nTest Case "+i+": ");
System.out.print("Enter gallons of Fuel in tank: ");
//taking input
f = sc.nextFloat();
if(f<0)
throw ex;
  
System.out.print("Enter efficiency in miles per gallon: ");
//taking input
e = sc.nextFloat();
if(e<0)
throw ex;
  
//displaying output
System.out.println("Maximum Distance that can be covered: " + max_dis(f, e));
}
catch(Exception e)
{
//displaying error
System.out.println("Error: Bad Input!");
}
}
}
}


Please refer to the screenshot of the code to understand the indentation of the code:

A)

B)


Here is the Output for the sample Test Cases:

A)

B)


Related Solutions

in Java using netbeans create a project and in it a class with a main. We...
in Java using netbeans create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?");...
in Java using netbeans create a project and in it a class with a main. We...
in Java using netbeans create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?");...
in netbeans using Java Create a project and a class with a main method, TestCollectors. ☑...
in netbeans using Java Create a project and a class with a main method, TestCollectors. ☑ Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. ☑ Add a method addToCollection. In this method,...
Create a Netbeans project called LineNumbers The program should do the following: –Ask the user for...
Create a Netbeans project called LineNumbers The program should do the following: –Ask the user for how many lines of text they wish to enter –Declare and initialize an array of Strings to hold the user’s input –Use a while loop to prompt for and read the Strings (lines of text) from the user at the command line. Typically, this would be a 'for' loop since we know the number of times to execute the loop based upon the number...
2. Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a...
2. Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a student gradebook using a two-dimensional array. It should allow the user to enter the number of students and the number of assignments they wish to enter grades for. This input should be used in defining the two-dimensional array for your program. For example, if I say I want to enter grades for 4 students and 5 assignments, your program should define a 4 X...
Start NetBeans. Create a new project called Lab7. Create a Java main class file using the...
Start NetBeans. Create a new project called Lab7. Create a Java main class file using the class name YourlastnameLab7 with your actual last name. Create a Java class file for a Polygon class. Implement the Polygon class. Add a private instance variable representing the number of sides in the polygon. Add a constructor that takes a single argument and uses it to initialize the number of sides. If the value of the argument is less than three, display an error...
Using NetBeans, create a Java project named FruitBasket. Set the project location to your own folder....
Using NetBeans, create a Java project named FruitBasket. Set the project location to your own folder. 3. Import Scanner and Stacks from the java.util package. 4. Create a Stack object named basket. 5. The output shall: 5.1.Ask the user to input the number of fruits s/he would like to catch. 5.2.Ask the user to choose a fruit to catch by pressing A for apple, O for orange, M for mango, or G for guava. 5.3.Display all the fruits that the...
Java Program using Netbeans IDE Create class Date with the following capabilities: a. Output the date...
Java Program using Netbeans IDE Create class Date with the following capabilities: a. Output the date in multiple formats, such as MM/DD/YYYY June 14, 1992 DDD YYYY b. Use overloaded constructors to create Date objects initialized with dates of the formats in part (a). In the first case the constructor should receive three integer values. In the second case it should receive a String and two integer values. In the third case it should receive two integer values, the first...
Part A Java netbeans ☑ Create a project and in it a class with a main....
Part A Java netbeans ☑ Create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class , after the package statement, paste import java.util.Scanner; As the first line inside your main method, paste Scanner scan = new Scanner(System.in); Remember when you are getting a value from the user, first print a request, then use the Scanner to read the right type...
Create a Maven project in NetBeans using the maven-archetype-quickstart template, with Group Id: com.lastname.firstname and Artifact...
Create a Maven project in NetBeans using the maven-archetype-quickstart template, with Group Id: com.lastname.firstname and Artifact Id: exam2p1. 2. Use search.maven.org and/or mvnrepository.com to find three different artifacts that you will demonstrate in your project. a. Each artifact you use should be in a different category (e.g. cloud, JSON, regex, etc.). Hint: You can search by category at mvnrepository.com. DO NOT USE any artifact we have already used in a project in-class assignments or demos. b. Make sure you can...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT