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

Interstellar explorers find an Earth-like planet orbiting FH-3299. Some cute, ha

ID: 3871999 • Letter: I

Question

Interstellar explorers find an Earth-like planet orbiting FH-3299. Some cute, harmless creatures have evolved there. You decide to set up a petting zoo, with three types of creatures: skwilks, zambos, and drufts.

The creatures eat earthworms and paperclips. Each week:

Skwilks eat 1.8 kilos of earthworms, and 5.3 kilos of paperclips

Zambos eat 2.3 kilos of earthworms, and 6.2 kilos of paperclips

Drufts eat 3.9 kilos of earthworms, and 7.7 kilos of paperclips

A kilos of worms costs $4.52. A kilo of paperclips costs $7.55.

Write a program to compute the weekly cost of feeding your critters, given the number of each type of critter you have in the zoo. Here’s a screenshot:

Round the cost to the neatest cent. It’s OK to leave off the last digit if it’s zero. Check the rounding numbers hint; it might be useful.

All inputs should be numeric, and not less than zero. Your program should show an error message and stop when there’s an error. For example:

Your program can stop immediately when it detects an error, or show all applicable error messages and then stop. Your choice.

You must use subroutines. Use three at least: input, processing, and output. You may use more if you want.

1 Petting zoo weekly food cost 3 Skwilks 4 Zambos 5 Drufts 6 12 Run 8 9 Earth worms 0 Paperclips 59.5 kilos 151.7 kilos 12 Total cost: 1414.28 13

Explanation / Answer

import java.util.*;

public class PettingZoo {
private int numSkwills=0;
private int numZambos=0;
private int numDrufts=0;
private double totalCost=0;
public static void main(String args[]) {
PettingZoo p = new PettingZoo();
p.input();
p.process();
p.output();
}
private void input(){
System.out.println("Enter number of Skwills");
Scanner s = new Scanner(System.in);
try{
numSkwills=s.nextInt();
s = new Scanner(System.in);
numZambos=s.nextInt();
s = new Scanner(System.in);
numDrufts=s.nextInt();
}
catch(Exception e){
System.out.println("Please enter a valid number");
}

}
private void process(){
totalCost=numSkwills*(1.8*4.52 + 5.3*7.55) + numZambos * (2.3 * 4.52 + 6.2*7.55) + numDrufts*(3.9*4.52 + 7.7*7.55);
}
private void output(){
System.out.println("Total weekly cost: " + totalCost);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote