Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Coding Guidelines (20 points) (a) (10 points) Rewrite the following according

ID: 3873893 • Letter: 1

Question

1. Coding Guidelines (20 points) (a) (10 points) Rewrite the following according to the coding guidelines. (b) (10 points) Mention 5 features of this class that violate the coding guidelines.

char c1;

c1 = GetChoice();

switch (c1)

{

     case 'a':

     case 'A':

           OptionA();

           break;

     case 'i':

     case 'I':

           OptionI();

           break;

     case 'w':

     case 'W':

           ProcessOptionW();

           break;

     default:

           println("Not a valid choice )";

}

2. Control Structures (40 points) 20 points for correctness, 20 for following the coding guidelines. Write a program to generate a random number from 1 to 100 and keep it as a secret number. The program will then check if a user can guess the secret number. The user can continue guessing the number until the number is found or the user can enter 0, which will terminate the program. Name this program SecretNumber.java.

Each time the user makes a guess, the program will report as below:

1. Way Too High or Way Too Low (more than 30 off)

2. High or Low (between 10 and 30 points off)

3. A Little High or A Little Low (less than 10 points off)

If secret number is 74 and the user enters 26, the program will print "Way too Low". If the user then says 65, then the program will print "A Little Low".   

3. Classes (40 points). 20 points for correctness, 20 for following the coding guidelines. Design and implement a class called Die (for a die in a pair of dice). Include a constructor for a die (which will set its value as null or -1), methods to set and get the individual die values, and a method to print the die. For instance, a 5 will print as

        *   *

          *

        *   *

Create a driver class called CreatePairOfDice to instantiate and print a pair of dice. The value of each die should be a randomly generated integer from 1 to 6. You must use Math.random().

EECS 1570 Java Programming Is Not So Easy. Linear Data Structures!

Explanation / Answer

1. I dont have the coding guidelines so this part is incomplete.

2. i m writing the main logic of the program:

code

import java.*

public static void main(string args[])

{

system.out.println("enter the secret number");

scanner sc=new scanner(system.in);

int num=sc.nextint();

int min=1;

int max=100;

while(c!=0&&c!=num)

{

c=math.random*(max-min)+min;

if(c-num>30){system.out.printf("Way too high");}

else if(num-c>30){system.out.println("Way Too low");}

else if(c-num>10){system.out.println("High");}

else if(num-c>10){system.out.println("Low");}

else if(c-num<10){system.out..println("A little high");}

else if(num-c<10){system.out..println("A little low");}

}

}

3. code

public Class Die{

public Die(int value){

value=-1;}

public getvalue(){

int value,in=1,max=6;

value=math.random*(max-min)+min;

}

public display(int value){

if(value==1){system.out.println("*");}

else if(value==2){system.out.println("* *");}

else if(value==3){

system.out.println(" *");

system.out.println(" *");

system.out.println("*");}

else if(value==4){

system.out.println("* *");

system.out.println("* *");

}

else if(value==5){

system.out.println("* *");

system.out.println(" * ");

system.out.println("* *");

}

else if(value==6){

system.out.println("* * *");

system.out.println("* * *");

}

}

}

public static void main(string args[])

{

getvalue();

display();

}