Urgent Java homework question help?

Urgent Java homework question help? Topic: Urgent Java homework question help?
June 24, 2019 / By Ula
Question: I need help solving this last question, I am horrible at programming(this class in a requirement for me to graduate in the spring) and this 1 question will determine whether or not I get a 0% or 10% on the homework portion of my mark but I don't know were to start. Here it is: Write a class named Fan to model fans. The properties, as shown in the UML diagram below are speed, on, radius and color. You need to provide the setter and getter methods for the properties and the toString method for returning a string consisting of all the values of all the properties in this class. Suppose the fan has three fixed speeds. Use constants 1, 2, and 3 to denote slow, medium and fast speeds. Write a client program to test the Fan class. In the client program, create a Fan object. Assign maximum speed, radius 10, color white and turn it on. Display the object by invoking its toString method. Fan - speed: int - on: boolean - radius: double - color: String + Fan() + getSpeed(): int + setSpeed(speed: int): void + isOn(): boolean + setOn(on: boolean) : void + getRadius() : double + setRadius(radius: double): void + getColor(): String + setColor (color: String): void + toString(): String
Advertisement
Best Answer

Best Answers: Urgent Java homework question help?

Sapphire Sapphire | 4 days ago
Start here Fan - speed: int - on: boolean - radius: double - color: String + Fan() + getSpeed(): int + setSpeed(speed: int): void + isOn(): boolean + setOn(on: boolean) : void + getRadius() : double + setRadius(radius: double): void + getColor(): String + setColor (color: String): void + toString(): String This is a list of the variables for the class and the methods used in the class. Create a class with those attributes as skeletons and then fill in the details. So for example + toString(): String You know the method name toString. You know that there are no parameters () and you know that the return type is String. So public String toString() { } Have fun.
👍 256 | 👎 4
Did you like the answer? Urgent Java homework question help? Share with your friends
Sapphire Originally Answered: I need help with a dumb Java Question?
In Java, length is a method, not a data member or property. Use s1.length() and s2.length() instead. @Vaibhav: Greg has it right, except for the parentheses. The assignment he posted said specifically to compare lengths only and return true if and only if s1 is longer than s2.
Sapphire Originally Answered: I need help with a dumb Java Question?
It should be return( s1.length( )>s2.length( )); But length() will not always give correct answer Check your third case they both have same length but then also it should return false because s1 is lexicographical bigger than s2 so you should use compareTo like if( s1.compareTo( s2 )>0 ) return true; else return false; @husoski please check the third example which he gave both have same lengths but the method returns false because first one is lexicographically smaller

Nolene Nolene
Start by writing down the functions You can see you have data types with names such as double radius; int speed and then functions called Fan(), getSpeed() which returns an int (meaning you put something in it and it has to spit out an int when its done) other than that, we can't do your homework assignment for you A good place to start is to construct a skeleton first and then proceed one function at a time. Also from my experience in teaching, the people who don't know anything about programming' this late in the game usually have cheated in the class. Cheating never pays, ESPECIALLY with programming and computer science, cause' is just gets harder. I'm not saying that you did though, I'm just warning you and letting you know that it doesn't work.
👍 110 | 👎 -4

Lysette Lysette
Wow you are even provided a UML diagram for this assignment. You could copy and paste it into your jdk and make a few changes and be done. If you're going to ask for help here at least try it first and come back with any problems you have.
👍 107 | 👎 -12

Lysette Originally Answered: Question about File I/O in Java?
import javax.swing.JOptionPane; import java.io.*; public class CaseStudy2 { public static void main(String[] args) throws IOException { String fileName = JOptionPane.showInputDialog( null, "Please enter filename"); File f = new File(fileName); FileOutputStream out = null; try { out = new FileOutputStream(f); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } int anArray[] = new int[6]; // declares the array for(int i = 0; i < anArray.length; i++) { anArray[i] = 0; } final int TARGET = 6; int thisRoll = 0; int i = 0; do{ String rollStr = JOptionPane.showInputDialog("Roll the dice and enter the number: "); thisRoll = Integer.parseInt(rollStr); anArray[thisRoll-1]++; byte[] b = (new Integer( thisRoll).toString()+"\n").getBytes(); try { out.write(b); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } while ((thisRoll != TARGET ));// when the dice throw is not a 6, a message dialog will appear asking the user to enter a number //end while JOptionPane.showMessageDialog(null, "You rolled a six"); JOptionPane.showMessageDialog(null, "Top Score"); displayData(anArray); JOptionPane.showMessageDialog(null, "Game Over"); }//end main public static void displayData(int[] anArray) { JOptionPane.showMessageDialog(null,"Nu... one was thrown " + anArray[0] + "\n" + "Number two was thrown " + anArray[1] + "\n" + "Number three was thrown " + anArray[2] + "\n" + "Number four was thrown " + anArray[3] + "\n" + "Number five was thrown " + anArray[4] + "\n" + "It took " + anArray[5] + " goes for number six to be reached"); }//end displayData() }//end class
Advertisement

If you have your own answer to the question Urgent Java homework question help?, then you can write your own version, using the form below for an extended answer.