Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HELP IN JAVA: Write a program that inputs feet and inches, creates a FeetAndInches object, puts it in a Node, and then adds (appends) these

HELP IN JAVA:

Write a program that inputs feet and inches, creates a FeetAndInches object, puts it in a Node, and then adds (appends) these nodes to a list. Input is from the keyboard. Files Node.java and FeetAndInches.java have already been uploaded, you just have to write the main method.

public static void main(String[] args) { Scanner keyboard = new Scanner (System.in);

Node tail= null; Node head=null; System.out.println("Please enter the number of feet and inches separated by space, enter 0 0 to quit"); feet = keyboard.nextInt(); inches = keyboard.nextInt(); while( ) { //create a node and add to list } System.out.println("Please enter the number of feet and inches separated by space, enter 0 0 to quit"); feet = keyboard.nextInt(); inches = keyboard.nextInt(); } PrintList(head); } public static void PrintList(Node head) { Node curr=head; FeetAndInches m; while(curr !=null) {m= (FeetAndInches) curr.item; System.out.println(m); curr=curr.next; //end while } }

public class Node { Object item; Node next; Node(Object newItem) { item = newItem; next=null; } Node(Object newItem, Node nextNode) { item = newItem; next=nextNode; } }

public class FeetAndInches {

int f; int i; FeetAndInches () { f=0; i=0;} FeetAndInches (int newf, int newi) { f=newf; i=newi;} public void setFeet(int newf) {f = newf;} public void setInches(int newi) { i = newi;} public int compareTo(FeetAndInches c) {int thisInches, inches; thisInches = this.f*12 + this.i; inches = c.f*12 + c.i; if (thisInches < inches)return -1; else if (thisInches>inches) return 1; else return 0; } public String toString() { return this.f + " feet and " + this.i + " inches"; }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions