top of page

Java Programming Help

Public·1 member

Slot Machine Game Assignment

Using the following UML, create a class called SlotMachine that simulates a casino slot machine in which three numbers between 0 and 9 are randomly selected and printed side by side. This is done using the “pullLever” method which is overloaded, a default method which uses one token, and a parameter method which can specify how many tokens to gamble for that single pull. There are five situations which occur when the lever is pulled.


1) {0,0,0} Super Jackpot, all zeros. Token input is multiplied by a factor of 500 and added to the machine token credit. Should output suitable “Super Jackpot Winner” message showing winnings.

2) {X,X,X} Three number win. Where X is a value 1-9, token input is multiplied by a factor of 50 and added to the machine token credit. Should output suitable “Jackpot Winner” message showing winnings.

3) {X,X,Z} Free spin. Where X and Z are…


2302 Views

Solve the n queens problems. You have to place n queens on an n × n chessboard such that no two attack each other. Important: the chessboard


How to Place Your Queens


• All assignments must be submitted through git. Please look at the Piazza guide

on submitting assignments.

• Please follow the naming conventions properly. Please look at the Piazza guide

on the checking script. Run the checking script to make sure your files are named

correctly. You will get no credit if the checking script fails!


68 Views

Transform XML documents with XSLT in Java

Java code to convert XML TO XSLT


 import java.io.*; 
 import javax.xml.transform.*; 
 import javax.xml.transform.stream.*;
  
public class Driver {

    public static void main(String[] args)
    {
        try
        {
            TransformerFactory tFactory = TransformerFactory.newInstance();

            Source xslDoc = new StreamSource("datasheet.xsl");
            Source xmlDoc = new StreamSource("datasheet.xml");

            String outputFileName = "datasheet.html";
            OutputStream htmlFile = new FileOutputStream(outputFileName);

            Transformer transformer = tFactory.newTransformer(xslDoc);
            transformer.transform(xmlDoc, new StreamResult(htmlFile));
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}

13 Views

Java Programming Help: How to set Precision for double value

You can set Precision for double value either via BigDecimal or DecimalFormat, depending on what you want to do with the value later.


1. Setting double precision using DecimalFormat

DecimalFormatExample.java


package com.codersarts;

import java.text.DecimalFormat;

public class DecimalFormatExample {

   // setting precision upto 2 decimal point
    private static DecimalFormat df = new DecimalFormat("#.##");

    public static void main(String[] args) {

        double piValue = 3.14159265359;
        System.out.println("double : " + piValue);
        System.out.println("double : " + df.format(piValue));    //3.14

    }

}

Output


5866 Views

Java Programming Help: Can I add a function to enums in Java - Codersarts

Yes, you can add as many function you wish .


A Java Enum is a special Java class that define group of constants which is unchangeable variables, like final variables. An enum can contain constants, methods etc. Java enums were added in Java 5.


To create an enum, use the enum keyword and separate the constants with a comma.


Note that they should be in uppercase letters:


Example 1: enum for movie RATING


enum RATING {
         GENERAL,
         PARENTGUIDANCE,
         MATURE
}

53 Views
    bottom of page