Question

In: Computer Science

Please Use the ECLIPSE AND FOLLOW THESE RULES Apply the naming conventions for variables, methods, classes,...

Please Use the ECLIPSE AND FOLLOW THESE RULES

Apply the naming conventions for variables, methods, classes, and packages:

- variable names start with a lowercase character

- classes start with an uppercase character

- packages use only lowercase characters

methods start with a lowercase character

question1:

Design a Lotto class with one array instance variable to hold three random integer values (from 1 to 9). Include a constructor that randomly populates the array for a lotto object. Also, include a method in the class to return the array.

Use this class to simulate a simple lotto game in which the user chooses a number between 3 and 27. The user runs the lotto up to 5 times and each time the sum of lotto numbers is calculated. If the number chosen by the user matches the sum, the user wins and the game ends. If the number does not match the sum within five rolls, the computer wins.

question2:

Write a Java class that implements a set of three overloaded static methods. The methods should have different set of parameters and perform similar functionalities. Call the methods within main method and display the results.

eclipse...

Solutions

Expert Solution

//Question1

//Lotto.java

package lotto_game;

import java.util.Random;

public class Lotto {
   private int arr[];

   Lotto() {
       Random r = new Random();
       arr = new int[3];
       for (int i = 0; i < 3; i++) {
           arr[i] = r.nextInt(9) + 1;
       }
   }

   public int[] getArray() {
       return arr;
   }
}

========================================================

//Game_driver.java

package lotto_game;

import java.util.Scanner;

public class Game_driver {
   public static void main(String[] args) {
       int n;
       Lotto l;
       Scanner input = new Scanner(System.in);
       System.out.print("Enter a number between (3 and 27): ");
       n = input.nextInt();
       while (n < 3 || n > 27) {
           System.out.println("Try Again!!");
           System.out.print("Enter a number between (3 and 27): ");
           n = input.nextInt();
       }
       for (int i = 0; i < 5; i++) {
           l = new Lotto();
           int arr[] = l.getArray();
           int sum = arr[0] + arr[1] + arr[2];
           if (sum == n) {
               System.out.println("You Win!!");
               System.exit(0);
           }
       }
       System.out.println("Computer Wins!!");
   }
}

//Output

===========================================================================

===========================================================================

//Question 2

public class Overloaded {
   public static void add(int a, int b) {
       System.out.println(a + " + " + b + " = " + (a + b));
   }

   public static void add(float a, float b) {
       System.out.println(a + " + " + b + " = " + (a + b));
   }

   public static void add(double a, double b) {
       System.out.println(a + " + " + b + " = " + (a + b));
   }

   public static void main(String[] args) {
       int a = 5, b = 10;
       add(a, b);
       double c = 5.5060, d = 10.5845;
       add(c, d);
       float e = (float) 3.3, f = (float) 5.6;
       add(e, f);
   }
}

//Output


Related Solutions

PLEASE Use the ECLIPSE... AND FOLLOW THIS RULES.. Apply the naming conventions for variables, methods, classes,...
PLEASE Use the ECLIPSE... AND FOLLOW THIS RULES.. Apply the naming conventions for variables, methods, classes, and packages: - variable names start with a lowercase character - classes start with an uppercase character - packages use only lowercase characters methods start with a lowercase character Write a Java application that simulates a test. The test contains at least five questions about first three lectures of this course. Each question should be a multiple-choice question with 4 options. Design a Test...
Please change this code to follow the rules. The program must not use global variables. In...
Please change this code to follow the rules. The program must not use global variables. In another words, it must use local variables and pass-by-value or pass-by-reference parameters. #include <iostream> #include <string> #include <algorithm> using namespace std; struct expense { string Desc; double exp; }; expense arr[100]; int c = 0; void menu(); //1. show all void showArray(){ if (c>0){ for(int i=0;i<c;i++){ cout<<"AMOUNT("<<arr[i].exp<<") DESC"<<arr[i].Desc<<")"<<endl; } }else{ cout<<"There is no expense entry available"; } menu(); } //2. spend void addArray(){ string...
Discuss why naming conventions are important and why as a programmer you should consistently follow them....
Discuss why naming conventions are important and why as a programmer you should consistently follow them. Include in this discussion, problems that could arise in naming variables if one convention is NOT followed.
Please focus on Nurse Practitioners 1. Discuss the controversy surrounding the naming conventions for APRNs (example...
Please focus on Nurse Practitioners 1. Discuss the controversy surrounding the naming conventions for APRNs (example DNP prepared nurse practitioners using the title "doctor")
use eclipse Develop the classes for the following requirements: 1. A class named Employee (general, for...
use eclipse Develop the classes for the following requirements: 1. A class named Employee (general, for college) 2. A class named Instructor (more specific, for college) 3. A class named Staff (more specific, for college, HR officer, Marking staff) Tasks: 1. Figure out the relationships among the classes; 2. Determine the abstract class, and the child classes; 3. For the abstract class, determine at least one abstract method; 4. Each class should at least two data members and one extra...
7. Explain the use and rules that apply to C Corporation subsidiaries.
7. Explain the use and rules that apply to C Corporation subsidiaries.
   Assignment ID is p1 NOTE: Algebraic expressions follow FORTRAN conventions. Use full calculator precision for...
   Assignment ID is p1 NOTE: Algebraic expressions follow FORTRAN conventions. Use full calculator precision for intermediate values. Use the bisection method with the function defined by: A=(X + 1.62) / 5.39 B=(X - 3.77) / 5.39 P1=((A-1)**2)*(1+2*A) P2=((B+1)**2)*(1-2*B) F(X) = (P1 * (-1.24) ) + (P2 * 4.13) Start with interval (Xleft,Xright) = (-1.62, 3.77) The function values at these end points are F(Xleft) = -1.24 F(Xright) = 4.13 The new approximation interval bracketing the root after ONE bisection...
Which of the following are characteristics of NeoclassicalEconomics? (Select all that apply)individuals use rules...
Which of the following are characteristics of Neoclassical Economics? (Select all that apply)individuals use rules of thumbindividuals act independently of one anotherreference points matterrational preferencesindividuals use mental accountingfirms maximize profits
PLEASE NUMBER EACH ANSWER Students will use advanced looping methods including replicate(), lapply(), sapply(), and apply(),...
PLEASE NUMBER EACH ANSWER Students will use advanced looping methods including replicate(), lapply(), sapply(), and apply(), and access datasets provided with R packages in an R script. The function call, rnorm(1), generates a normal random number. Use replicate() to generate 10 normal random numbers and assign them to a vector called nums. The R statement, data(iris), loads the built-in R data set iris. This dataset has 150 rows and 5 columns. The 5 column names are "Sepal.Length","Sepal.Width","Petal.Length","Petal.Width" and "Species". Write...
Please use Java Eclipse and show code/output Please create a program that determines when a good...
Please use Java Eclipse and show code/output Please create a program that determines when a good day to go to the beach is. Please use the users input and its returning output. If the weather is 70 degree or greater, the program should say yes it is a good day to go If the weather is less than 70 degrees to say no the weather is not a good day to go
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT