1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
nadya68 [22]
3 years ago
8

Write a program that randomly chooses between three different colors for displaying text on the screen. Use a loop to display tw

enty lines of text, each with a randomly chosen color. The probabilities for each color are to be as follows: white = 30%, blue = 10%, green = 60%. Hint: generate a random integer between 0 and 9. If the resulting integer is in the range 0-2, choose white. If the integer equals 3, choose blue. If the integer is in the range 4-9, choose green.
Engineering
1 answer:
11Alexandr11 [23.1K]3 years ago
6 0

Answer:

INCLUDE Irvine32.inc

.data

msgIntro  byte "This is Your Name's fourth assembly extra credit program. Will randomly",0dh,0ah

         byte "choose between three different colors for displaying twenty lines of text,",0dh,0ah

         byte "each with a randomly chosen color. The color probabilities are as follows:",0dh,0ah

         byte "White=30%,Blue=10%,Green=60%.",0dh,0ah,0

msgOutput byte "Text printed with one of 3 randomly chosen colors",0

.code

main PROC

;

//Intro Message

       mov edx,OFFSET msgIntro  ;intro message into edx

       call WriteString         ;display msgIntro

       call Crlf                ;endl

       call WaitMsg             ;pause message

       call Clrscr              ;clear screen

       call Randomize           ;seed the random number generator

       mov edx, OFFSET msgOutput;line of text

       mov ecx, 20              ;counter (lines of text)

       L1:;//(Loop - Display Text 20 Times)

       call setRanColor         ;calls random color procedure

       call SetTextColor        ;calls the SetTextColor from library

       call WriteString         ;display line of text

       call Crlf                ;endl

       loop L1

exit

main ENDP

;--

setRanColor PROC

;

; Selects a color with the following probabilities:

; White = 30%, Blue = 10%, Green = 60%.

; Receives: nothing

; Returns: EAX = color chosen

;--

       mov eax, 10              ;range of random numbers (0-9)

       call RandomRange         ;EAX = Random Number

       .IF eax >= 4          ;if number is 4-9 (60%)

       mov eax, green           ;set text green

       .ELSEIF eax == 3         ;if number is 3 (10%)

       mov eax, blue            ;set text blue

       .ELSE                    ;number is 0-2 (30%)

       mov eax, white           ;set text white

       .ENDIF                   ;end statement

       ret

setRanColor ENDP

You might be interested in
You will create three classes, the first two being Student and LineAtOfficeHour. The instances of the first class defines a sing
White raven [17]

Answer:

Complete solution is given below:

Explanation:

//student class

class Student{

  private String firstname,lastname;

 

  //constructor

  Student(String first,String last){

      this.firstname=first;

      this.lastname=last;

  }

 

  //getters and setters

  public String getFirstname() {

      return firstname;

  }

  public void setFirstname(String firstname) {

      this.firstname = firstname;

  }

  public String getLastname() {

      return lastname;

  }

  public void setLastname(String lastname) {

      this.lastname = lastname;

  }

  //function to get the fullname of student

  public String fullName() {

      return this.firstname+" "+this.lastname;

  }

}

//class for line at office hour

class LineAtOfficeHour{

 

  private Student line[];

  private int N=0;

  private int back=0;

 

  //empty constructor

  LineAtOfficeHour() {

      line=new Student[5];

  }

  //parameterized constructor

  LineAtOfficeHour(Student st[]) {

      int i=0;

      line=new Student[5];

      while(i<st.length && i<5) {

          line[i]=st[i];

          i++;

      }

      this.N=i;

      this.back=i-1;

  }

  //function to check if line is empty or not

  public boolean isEmpty() {

      if(this.N==0)

          return true;

      else

          return false;

  }

  //function to check if line is full

  public boolean isFull() {

      if(this.N==5) {

          return true;

      }else

          return false;

  }

  ///function to get the size of line

  public int size() {

      return this.N;

  }

 

  //function to add a student to the line

  public void enterLine(Student s) {

      if(isFull())

          System.out.println("Line is full!!!!");

      else {

          line[++back]=s;

          this.N++;

      }

  }

  public Student seeTeacher() {

      Student result=null;

      if(this.N>=0) {

          result=line[0];

          int i=0;

          for(i=1;i<N;i++) {

              line[i-1]=line[i];

          }

          line[i-1]=null;

          this.N--;

          this.back--;

      }

     

     

      return result;

  }

  //function to print students in line

  public String whosInLine() {

      String result ="";

      for(int i=0;i<this.N;i++) {

          result+=line[i].fullName()+",";

      }

      return result;

  }

}

//driver method

public class TestLine {

  public static void main(String[] args) {

      LineAtOfficeHour list=new LineAtOfficeHour();

     

      if(list.isEmpty()) {

          System.out.println("Line is empty!!!!!!!!!");

      }

     

      Student s1[]=new Student[3];

      s1[0]=new Student("John","Smith");

      s1[1]=new Student("Sam","Zung");

      s1[2]=new Student("Peter","Louis");

      list=new LineAtOfficeHour(s1);

     

      if(list.isEmpty()) {

          System.out.println("Line is empty!!!!!!!!!");

      }else {

          System.out.println("Line is not empty.........");

      }

     

      System.out.println("Students in line: "+list.whosInLine());

     

      System.out.println("Student removed: "+list.seeTeacher().fullName());

     

      System.out.println("Students in line: "+list.whosInLine());

  }

}

6 0
4 years ago
Assign numMatches with the number of elements in userValues that equal matchValue. userValues has NUM_VALS elements. Ex: If user
erica [24]

Answer:

import java.util.Scanner;

public class FindMatchValue {

  public static void main (String [] args) {

     Scanner scnr = new Scanner(System.in);

     final int NUM_VALS = 4;

     int[] userValues = new int[NUM_VALS];

     int i;

     int matchValue;

     int numMatches = -99; // Assign numMatches with 0 before your for loop

     matchValue = scnr.nextInt();

     for (i = 0; i < userValues.length; ++i) {

        userValues[i] = scnr.nextInt();

     }

     /* Your solution goes here */

         numMatches = 0;

     for (i = 0; i < userValues.length; ++i) {

        if(userValues[i] == matchValue) {

                       numMatches++;

                }

     }

     System.out.println("matchValue: " + matchValue + ", numMatches: " + numMatches);

  }

}

6 0
3 years ago
The 5 ft wide gate ABC is hinged at C and contacts a smooth surface at A. If the specific weight of the water is 62.4 lb/ft3 , f
pochemuha

Answer:

The solution is given in the attachments.

5 0
3 years ago
Considet a three-phase transmission line operating at the sending end voltage of 500kV. Theseries impedance is z= 0.045+j0.4Ωper
Roman55 [17]
Txt you. U u u yxigzextctvyb
4 0
3 years ago
Just getting to your class is enough for showing up.<br> A) True<br> B) False
Lady bird [3.3K]
False you have to do the work and perricapate
8 0
4 years ago
Read 2 more answers
Other questions:
  • A power plant operates on a regenerative vapor power cycle with one open feedwater heater. Steam enters the first turbine stage
    15·1 answer
  • 1) Pareto charts are used to: A) identify inspection points in a process. B) outline production schedules. C) organize errors, p
    6·1 answer
  • The cylindrical aluminum air tank below is to be rated for 300 psi and it must comply with the ASME Boiler Code which requires a
    5·2 answers
  • Take water density and kinematic viscosity as p=1000 kg/m3 and v= 1x10^-6 m^2/s. (c) Water flows through an orifice plate with a
    13·1 answer
  • A rigid bar ABCD is pinned at A and supported by two steel rods connected at B and C, as shown. There is no strain in the vertic
    10·1 answer
  • Which of the following terms describes the path from an electrical source to a switch or plug?
    10·2 answers
  • Question # 3
    13·1 answer
  • A wall that cannot be moved because it is carrying the weight of the roof is considered a wall
    12·1 answer
  • Which of the following can effect LRO?
    12·1 answer
  • A(n) _____________ is used commonly in open split-phase motors to disconnect the start winding from the electrical circuit when
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!