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

I need help getting this program to output... public class Packet extends Packag

ID: 440550 • Letter: I

Question

I need help getting this program to output... public class Packet extends Packages { // instance variables - replace the example below with your own public int idNumber; public String state; public double weight; public Packet(int id, String s, double d) { this.idNumber = id; this.state = s; this.weight = d; } public boolean isHeavy() { if (weight > 12) return true; else return false; } public boolean isLight() { if (weight < 7) return true; else return false; } public String toString() { String s = "ID: " + idNumber + " " + "Weight: " + weight + " " + "State: " + state; return s; } } import java.util.ArrayList; import java.util.Scanner; import java.io.*; public class Packages { double totalWeight; public ArrayList shipment; public void Packages () throws IOException { totalWeight = 0.0; shipment = new ArrayList(); Scanner fileScan; fileScan = new Scanner (new File("allPackets.txt")); // Read and process each line in the file while (fileScan.hasNext()) { int id = fileScan.nextInt(); String s = fileScan.next(); double d = fileScan.nextDouble(); Packet p = new Packet (id, s, d); shipment.add(p); } System.out.println(shipment); } public void displayLightPackages() { System.out.println("ALL LIGHT PACKAGES "); for(Packet mypacket : shipment) if (mypacket.isLight()) System.out.println(mypacket); } public void displayHeavyPackages() { System.out.println("ALL HEAVY PACKETS "); for(Packet mypacket : shipment) if (mypacket.isHeavy()) System.out.println(mypacket); } public void displayOtherPackages() { for(Packet mypacket : shipment) if(mypacket.isHeavy() || mypacket.isLight()) System.out.println("ALL REGULAR PACKETS "); else System.out.println(mypacket); } public void displayTotalWeight() { for(Packet mypacket : shipment) totalWeight += mypacket.weight; System.out.println ("Total weight of all packets is " + totalWeight); } public void displayAverageWeight() { for(Packet mypacket : shipment) { totalWeight = shipment.size(); } System.out.println("Average weight of all packets is " + totalWeight); } public String toString() { String s = "ALL PACKETS "; for(Packet mypacket : shipment) s += mypacket; return s; } } public class TestPackages { public static void main(String[] args) { Packages mypacket = new Packages(); System.out.println(mypacket); } }

Explanation / Answer

The code you have given is difficult to read and deduce.......... post your question directly so that we can answer. for java tutorial http://www.tutorialspoint.com/java/index.htm

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