package car;
import java.util.*;
import java.io.*;
public class fitness {
final int limit=7;
final static int requiredcolory=1500;
public static void main(String[] args) {
int arr[][]=new int[7][];
String line="";
int counter=0;
int allcounter=0;
int sum=0;
try{
BufferedReader br=new BufferedReader(new FileReader(new
File("src/car/colory")));
while((line=br.readLine())!=null){
String[] splits=line.split(" ");
arr[counter]=new int[splits.length];
System.out.print("Day:"+(counter+1)+"=");
for(int i=0;i<arr[counter].length;i++){
arr[counter][i]=Integer.parseInt(splits[i]);
System.out.print(arr[counter][i]+" ");
//System.out.print(arr[counter].length);
}
counter++;
System.out.println();
if(counter>7){
System.out.println("input data exceding limit 7:");
break;
}
}
}catch(Exception e){
System.out.println("error in reading file:"+e);
}
for(int i=0;i<arr.length;i++){
for(int j=0;j<arr[i].length;j++){
sum+=arr[i][j];
if(arr[i][j]>requiredcolory)
System.out.println("Day:"+(i+1)+" has colory greter than
requirement");
allcounter++;
}
}
System.out.println("average colories is:"+(sum/allcounter));
}
}
output:
Day:1=800 1000 100
Day:2=450 100 845 20 1200 200
Day:3=1800 1250 400
Day:4=0 1500 800 200
Day:5=600 500
Day:6=700 1400 1700 100
Day:7=675
Day:3 has colory greter than requirement
Day:6 has colory greter than requirement
average colories is:710
input file:
colory.txt
800 1000 100
450 100 845 20 1200 200
1800 1250 400
0 1500 800 200
600 500
700 1400 1700 100
675
screenshots:
/* i had package called
car..so i place both text file and fitness file in that
package..and be sure about the path of text file you mentioned in
your program
i used "src/car/colory" as per my directory..
*/
Java Objective: The goal of this assignment is to practice 2-dimensional ragged arrays. Background: Within a...
The goal of this assignment is to practice one dimensional arrays. Objective: The goal of this assignment is to practice one-dimensional arrays. Background: A local FedEx ship center needs support to compute volume of the packages that are delivered on each day Assignment: The shipping center manages deliveries of each day in a single text file. Each text file contains exactly three lines. Each line contains n double numbers representing a dimension of n boxes. The first line represents the...
Step 1: Getting Started Create a new .java file named Lab12.java. At the beginning of this file, include your assignment documentation code block. After the documentation block, you will need several import statements. import java.util.Scanner; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; Next, declare the Lab12 class and define the main function. public class Lab12 { public static void main (String [] args) { Step 2: Declaring Variables For this section of the lab, you will need to declare...
For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...
Write a java program to sort arrays using 3 different methods: Bubble Sort, Selection Sort and Insertion Sort. The numbers to be sorted will be obtained using a library function which generates pseudo-random numbers. TO Do 1. Fill an array with 140 real numbers between 0.00 and 945.00. Generate the numbers using the subroutine that generates random numbers. Make a spare copy of the array; you will need it later. 2. Call a subroutine to print the contents of the...
JAVA - Natural Quick Sort .txt and Return ----------------------------------------------------------------------------- The program should input a .txt file like below and must use a Quick sort Algorithm ================ 6 10 4 19 10 12 8 6 0 1 2 3 ================ The first number "6" represents the index of the element to return after sort the second number on the top "10" represents the number of elements or size of array. The following numbers and lines are the elements that need to...
Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a student's name (on one line). Then, for each course the student took last semester, the file has 2 data lines. The course name is on the first line. The second line has the student's grade average (0 to 100) and the number of credits for the course Sample data: Jon P. Washington, Jr. Computer Science I 81 4 PreCalculus 75 3 Biology I 88...
Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...
What to submit: your answers to exercises 2. Write a Java program to perform the following tasks: The program should ask the user for the name of an input file and the name of an output file. It should then open the input file as a text file (if the input file does not exist it should throw an exception) and read the contents line by line. It should also open the output file as a text file and write...
C++ Background information: A company has four salespeople who sell five different products. Once a day, each salesperson passes in a slip for each different type of product sold. First on the line is the salesperson name, second is the product number, and third is the sales volume for this product by this salesperson in dollars. For example, the line Tara 2 200.00 means that salesperson Tara reported sales of volume $200.00 for product number 2. Data: Eric 1 200000.00...
Write one single program that does all of the following tasks, in order. You should practice proper Top Down Design and Procedural Abstraction techniques unless otherwise noted. -Write a program with the following functions, with the correct number of arguments for each function. -void fillUpArray ( argument1, argument2) This function should read in a text file called "villagers.txt" (You will create your own). "villagers.txt" is a text file of numbers in ascending order, ranging anywhere from 1 to 100, nonrepeating....