Java homework questions: Answer all exercises Not copied answer plzz Exercise 1 • Import and edit the Input04 project. • Run the code and examine the output. • Read through each next line until you find "BlueBumper". • The two numbers following "BlueBumper" are the object’s xPositon and yPosition. Store these coordinates as integers and print them. • Examine input04text.txt, if necessary. Input04.java package input04; import java.util.Scanner; public class Input04 { public static void main(String[] args){ Scanner sc = new Scanner(Input04.class.getResourceAsStream("input04text.txt")); //Edit these lines to advance the scanner sc.nextLine(); System.out.println(sc.nextLine()); //Does this line contain "BlueBumper"? System.out.println(sc.findInLine("BlueBumper")); //Store the next two numbers as xPosition and yPosition //Print these positions System.out.println("X: " +", Y: " ); sc.close(); } } input04text.txt 128 3.141 Puppies! Line2 This is Line2. 100002 This is still Line2. Line3 Line4 444 BlueBumper 90 120 Exercise 2: • Import and edit the Chickens01 project. • Read this story and calculate/print the totalEggs collected between Monday and Wednesday: – Farmer Brown’s chickens always lay eggsPerChicken eggs precisely at noon, which he collects that day. – On Monday, Farmer Brown has chickenCount chickens. – On Tuesday morning, Farmer Brown gains 1 chicken. – On Wednesday morning, a wild beast eats half the chickens! – How many eggs did Farmer Brown collect if he starts with … • eggsPerChicken = 5, chickenCount = 3 • eggsPerChicken = 4, chickenCount = 8 Your program should produce the following output: 45 First scenario 84 Second scenario Chickens01.java package chickens01; public class Chickens01 { public static void main(String[] args) { //Put yout code here System.out.println(totalEggs); } } Exercise 3 Import and edit the Chickens02 project. • Read this story and calculate/print the required values: – On Monday, Farmer Fred collects 100 eggs. – On Tuesday, Farmer Fred collects 121 eggs. – On Wednesday, Farmer Fred collects 117 eggs. – What is the dailyAverage of eggs collected? – How many eggs could be expected in a 30-day monthlyAverage? – If an egg can be sold for a profit of $0.18, what is Farmer Fred’s total monthlyProfit for all eggs? Your program should produce the following output: Daily Average: 112.66666666666667 Monthly Average: 3380.0 Profit: $608.4 Chickens02.java package chickens02; public class Chickens02 { public static void main(String[] args) { //Put yout code here System.out.println("Daily Average: " +dailyAverage); System.out.println("Monthly Average: " +monthlyAverage); System.out.println("Monthly Profit: $" +monthlyProfit); } }
Java homework questions:
Answer all exercises Not copied answer plzz
Exercise 1
• Import and edit the Input04 project.
• Run the code and examine the output.
• Read through each next line until you find "BlueBumper".
• The two numbers following "BlueBumper" are the object’s xPositon and yPosition. Store these coordinates as integers and print them.
• Examine input04text.txt, if necessary.
Input04.java
package input04;
import java.util.Scanner;
public class Input04 {
public static void main(String[] args){
Scanner sc = new Scanner(Input04.class.getResourceAsStream("input04text.txt"));
//Edit these lines to advance the scanner
sc.nextLine();
System.out.println(sc.nextLine());
//Does this line contain "BlueBumper"?
System.out.println(sc.findInLine("BlueBumper"));
//Store the next two numbers as xPosition and yPosition
//Print these positions
System.out.println("X: " +", Y: " );
sc.close();
}
}
input04text.txt
128 3.141 Puppies!
Line2 This is Line2. 100002 This is still Line2.
Line3
Line4 444 BlueBumper 90 120
Exercise 2:
• Import and edit the Chickens01 project.
• Read this story and calculate/print the totalEggs collected between Monday and Wednesday:
– Farmer Brown’s chickens always lay eggsPerChicken eggs precisely at noon, which he collects that day.
– On Monday, Farmer Brown has chickenCount chickens.
– On Tuesday morning, Farmer Brown gains 1 chicken.
– On Wednesday morning, a wild beast eats half the chickens!
– How many eggs did Farmer Brown collect if he starts with …
• eggsPerChicken = 5, chickenCount = 3
• eggsPerChicken = 4, chickenCount = 8
Your
45 First scenario
84 Second scenario
Chickens01.java
package chickens01;
public class Chickens01 {
public static void main(String[] args) {
//Put yout code here
System.out.println(totalEggs);
}
}
Exercise 3
Import and edit the Chickens02 project.
• Read this story and calculate/print the required values:
– On Monday, Farmer Fred collects 100 eggs.
– On Tuesday, Farmer Fred collects 121 eggs.
– On Wednesday, Farmer Fred collects 117 eggs.
– What is the dailyAverage of eggs collected?
– How many eggs could be expected in a 30-day monthlyAverage?
– If an egg can be sold for a profit of $0.18, what is Farmer Fred’s total monthlyProfit for all eggs?
Your program should produce the following output:
Daily Average: 112.66666666666667
Monthly Average: 3380.0
Profit: $608.4
Chickens02.java
package chickens02;
public class Chickens02 {
public static void main(String[] args) {
//Put yout code here
System.out.println("Daily Average: " +dailyAverage);
System.out.println("Monthly Average: " +monthlyAverage);
System.out.println("Monthly Profit: $" +monthlyProfit);
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images