Question
Programming CycleFileOutput - Write in Java with comments Revisit the Cycle class in Unit 3. Modify your application such that the properties will be written
Programming CycleFileOutput - Write in Java with comments
Revisit the Cycle class in Unit 3. Modify your application such that the properties will be written to a text file called CycleOut.txt instead of to the screen.
Directions
Examine your application for the class called Cycle.
Add an appropriate throws statement in the main method.
Create a reference to a File class with the appropriate name of a text file (Cycle.txt).
Use appropriate code to ensure that the text file exist.
Output the values of the variables to the text file.
Close the file.
Note: Verify the contents were written to the text file using notepad (or any word processor).
Grading Rubric
Task | Points |
Throws clause added in main method | 1 |
Create a reference to the File class and text file | 1 |
Check whether the text file exists | 1 |
Output the properties to the text file | 1 |
Close the text file | 1 |
Proper documentation | 1 |
Program works effectively | 1 |
Total | 7 |
=========================================
Here is the existing cycle class:
Cycle.java
public class Cycle{
int numberOfWheels; int weight;
public Cycle(){
this(100,1000); }
public Cycle(int numberOfWheels,int weight){
this.numberOfWheels=numberOfWheels; this.weight=weight; }
public String toString(){ return "Number of Wheels: "+numberOfWheels+" Weight: "+weight; } }
=========================================
CycleTest.java
// testing the Cycle Class public class CycleTest { //main method public static void main(String args[]) { //creating the Cycle object with some values Cycle ob=new Cycle(4,100); //printing the values of the object using toString() method System.out.println(ob); } }
==========================
CycleTest2.java
// testing the Cycle Class - default constructor public class CycleTest2 { //main method public static void main(String args[]) { //creating the Cycle class object Cycle ob2=new Cycle(); //printing the values of the object using toString() method System.out.println(ob2); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started