Question: JAVA What's wrong with my code??? I am getting the same prompts (illegal start...and identifier expected) in 4 main method calls Here is what I

JAVA What's wrong with my code??? I am getting the same prompts (illegal start...and identifier expected) in 4 main method calls

Here is what I have so far (I included the error messages on the line where it applies):

import java.util.*;

public interface Incrementable{

public void increment(); public void getValue(); } public class SequentialIncrementer implements Incrementable{ int value = 0; public void increment(){ value = value+1; } public void getValue() { return value; } }

public class RandomIncrementer implements Incrementable{ int value; public void increment(){ this.value = (int)(Math.random()*100); value = value + (int)(Math.random()*100); } public int getValue(){ return value; } } public class Tester{ public static void main (String []args); SequentialIncrementer sequence = new SequentialIncrementer(); RandomIncrementer random = new RandomIncrementer();

System.out.println /* error: expected*/ ( "SequentialIncrementer"); //error: illegal start of type sequence.increment(); //error: expected

System.out.println /*34: error: expected*/(sequence.getValue()); //34: error: expected System.out.println /*35: error: expected*/ ("RandomIncrementer"); random.increment(); 36: error: expected System.out.println /*37: error: expected*/(random.getValue()); // 35: error: expected } }

Here is the problem I wish to solve:

Declare an interface called 'Incrementable' that stores integers to be incremented in some way; create a method called 'increment' that increments; create a method called 'getValue' that returns the value; write 2 classes called SequentialIncrementer and RandomIncrementer that implements the interface; The SequentialIncrementer begins with its value at 0 and increases it by one each time; the RandomIncrementer begings its value at a random integer and changes it to a new random integer at each increment.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!