Question

During our academic life we all have been exposed to many mathematical operations. Some in higher...

During our academic life we all have been exposed to many mathematical operations. Some in higher degree than others, but every one of us can at least recall some computation they need to do in their daily lives. For example, calculating the average of your grades; or the area of your backyard; or how long will it take you to get home if you are traveling at 50 miles per hour. All these computations can be expressed in Java code. This is your task for this discussion: Please come up with a formula you like (“is there such thing?”) and write a small piece of code to calculate it. You must decide what type of variables you need, what are their values, and you need to express the formula using assignments in correct Java syntax. Use the compiler to verify that your program works. Let me give you an example: To calculate the average of two grades I could do the following inside the main method in a class: Scanner stdIn = new Scanner(System.in) ; double grade1; double grade2; double average; System.out.println(“Give me the first grade:”); grade1 = stdIn.nextDouble(); System.out.println(“Give me the second grade:”); grade2 = stdIn.nextDouble(); average = (grade1+grade2)/2.0;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1) Average of grades

import java.util.Scanner;
import java.text.DecimalFormat;
public class area {
   public static void main(String args[])
   {
       double grade1,grade2,average;
       Scanner stdIn = new Scanner(System.in);
       System.out.println("Give me first grade");//asks user to enter first grade
       grade1 = stdIn.nextDouble();
       System.out.println("Give me second grade");//asks user to enter second grade
       grade2 = stdIn.nextDouble();
       average = (grade1+grade2)/2.0;
       System.out.println("Average of "+grade1 + "&"+ grade2 +" is "+average);//prints average of grade1 and grade2
   }
}

1import java.util.Scanner; 3 public class area { public static void main(String args[]) 40 double grade1, grade2, average; Sc

<terminated > area Java Application) C:\Program File Give me first grade 1.5 Give me second grade 3.5 Average of 1.583.5 is 2

2)Area of backyard

import java.util.Scanner;
import java.text.DecimalFormat;
public class area {
   public static void main(String args[])
   {
       int width , breadth,area;
       Scanner stdIn = new Scanner(System.in);
       System.out.println("Enter width of backyard");
       width = stdIn.nextInt();
       System.out.println("Enter breadth of backyard");
       breadth = stdIn.nextInt();
       area = width * breadth;
       System.out.println("Area of the backyard is "+ area + "sqmeters");
      
              
   }
}
1. import java.util.Scanner; 3 public class area { public static void main(String args[]). int width , breadth, area; Scanner

<terminated > area [Java Application] C:\Program FilesVava\jre 1.8.0_191 Enter width of backyard 10 Enter breadth of backyard

3)Time to reach home

import java.util.Scanner;
import java.text.DecimalFormat;
public class area {
   public static void main(String args[])
   {
       int milesperhour = 50, distance;
       double time;
       Scanner stdIn = new Scanner(System.in);
       System.out.println("Enter distance of your home from starting point in miles");
       distance = stdIn.nextInt();
       time = distance / milesperhour;
       System.out.println("TIme taken to reach home is "+ time + " hours");      
   }
}
U month.java u Student.java Pl hacker Pl comp X.classpat Ptact Dl concat P 35 P large l reverse Pl koti Pikk 21import java.ut

Add a comment
Know the answer?
Add Answer to:
During our academic life we all have been exposed to many mathematical operations. Some in higher...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I ONLY need question 2 part C AND D answered...it is in bold. Please do not...

    I ONLY need question 2 part C AND D answered...it is in bold. Please do not use hash sets or tables. In java, please implement the classes below. Each one needs to be created. Each class must be in separate file. The expected output is also in bold. I have also attached the driver for part 4 to help. 1. The Student class should be in the assignment package. a. There should be class variable for first and last names....

  • Java Programming Language Edit and modify from the given code Perform the exact same logic, except...

    Java Programming Language Edit and modify from the given code Perform the exact same logic, except . . . The numeric ranges and corresponding letter grade will be stored in a file. Need error checking for: Being able to open the text file. The data makes sense: 1 text line of data would be 100 = A. Read in all of the numeric grades and letter grades and stored them into an array or arraylist. Then do the same logic....

  • I need to change the following code so that it results in the sample output below...

    I need to change the following code so that it results in the sample output below but also imports and utilizes the code from the GradeCalculator, MaxMin, and Student classes in the com.csc123 package. If you need to change anything in the any of the classes that's fine but there needs to be all 4 classes. I've included the sample input and what I've done so far: package lab03; import java.util.ArrayList; import java.util.Scanner; import com.csc241.*; public class Lab03 { public...

  • (Java) Rewrite the following exercise below to read inputs from a file and write the output...

    (Java) Rewrite the following exercise below to read inputs from a file and write the output of your program in a text file. Ask the user to enter the input filename. Use try-catch when reading the file. Ask the user to enter a text file name to write the output in it. You may use the try-with-resources syntax. An example to get an idea but you need to have your own design: try ( // Create input files Scanner input...

  • Must be written in JAVA Code Write a program that will read in a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be written...

    Must be written in JAVA Code Write a program that will read in a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be written to a file. Each line of the input file will contain the student name (a single String with no spaces), the number of semester hours earned (an integer), the total quality points earned (a double). The following shows part of a typical...

  • IT Java code In Lab 8, we are going to re-write Lab 3 and add code...

    IT Java code In Lab 8, we are going to re-write Lab 3 and add code to validate user input. The Body Mass Index (BMI) is a calculation used to categorize whether a person’s weight is at a healthy level for a given height. The formula is as follows:                 bmi = kilograms / (meters2)                 where kilograms = person’s weight in kilograms, meters = person’s height in meters BMI is then categorized as follows: Classification BMI Range Underweight Less...

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

  • This is the contents of Lab11.java import java.util.Scanner; import java.io.*; public class Lab11 { public static...

    This is the contents of Lab11.java import java.util.Scanner; import java.io.*; public class Lab11 { public static void main(String args[]) throws IOException { Scanner inFile = new Scanner(new File(args[0])); Scanner keyboard = new Scanner(System.in);    TwoDArray array = new TwoDArray(inFile); inFile.close(); int numRows = array.getNumRows(); int numCols = array.getNumCols(); int choice;    do { System.out.println(); System.out.println("\t1. Find the number of rows in the 2D array"); System.out.println("\t2. Find the number of columns in the 2D array"); System.out.println("\t3. Find the sum of elements...

  • Declare and initialize 4 Constants for the course category weights: The weight of Homework will be...

    Declare and initialize 4 Constants for the course category weights: The weight of Homework will be 15% The weight of Tests will be 35% The weight of the Mid term will be 20% The weight of the Fin al will be 30% Remember to name your Constants according to Java standards. Declare a variable to store the input for the number of homework scores and use a Scanner method to read the value from the Console. Declare two variables: one...

  • using Java program please copy and paste the code don't screenshot it import java.util.Scanner; import java.io.File;...

    using Java program please copy and paste the code don't screenshot it import java.util.Scanner; import java.io.File; public class { public static void main(String[] args) { // Create a new Scanner object to obtain // input from System.in // --> TODO // Ask user for a word to search for. Print // out a prompt // --> TODO // Use the Scanner object you created above to // take a word of input from the user. // --> TODO // ***...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT