[Solved]Create Java Class Create Java Class File Read Write Outcome Come Word Nice Weather Read Ni Q37256568
create java class
create java class // there is no file to read and write so theoutcome should come out as this
word: Nice weather
read: Nice weather
I have to include these
class Stream {
private String buffer;
//create code
}
public String read() {
//create code
}
public void write(String s) {
// create code
}
}
here is my code
class File {
public String content;
}
class Reader extends Stream {
private File ff;
public Reader(File h) {
ff = h;
}
class Writer extends Stream {
private File ff;
public Writer(File h) {
ff = h;
}
class Main {
public static void main(String[] args) {
File ff = new File();
Writer writer = newWriter(ff);
Reader reader = newReader(ff);
writer.write(“Nice weather”);
String msg = reader.read();
System.out.println(” word:” +ff.msg);
System.out.println(” read:” +msg);
}
}
///////////////////////////////////////////////////////additionalqueeestion!
also I need to fix this code there is a minor mistake and Icouldn’t find it
outcome should be this
30 50
Mz’s current speed: 30
Gs’s current speed: 50
and this is my code
class Motor {
private int speed;
public Motor(int speed) {
this.speed = speed;
}
public int getSpeed() {
return this.speed;
}
public void speedUp(int speed) {
this.speed += speed;
}
public void speedDown(int speed) {
this.speed -= speed;
if (this.speed < 0)
this.speed =0;
}
}
class Car {
Motor motor;
private String name;
private int highSpeed;
public Car(Motor m, String name, int range) {
this.motor = m;
this.name = name;
this.highSpeed = range;
}
public void speedUp(int speed) {
if (motor.getSpeed() + speed >highSpeed)
System.out.println(“Can’t accelerate!”);
else
motor.speedUp(speed);
}
public String toString() {
return name + “‘s current speed : “+ motor.getSpeed();
}
}
class Main {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
Motor m = new Motor(0);
Car oldCar = new Car(m, “Mz”,100);
Car newCar = new Car(m, “Gs”,200);
oldCar.speedUp(keyboard.nextInt());
newCar.speedUp(keyboard.nextInt());
System.out.println(oldCar);
System.out.println(newCar);
keyboard.close();
}
}
Expert Answer
Answer to create java class create java class // there is no file to read and write so the outcome should come out as this word: N… . . .
OR

