Question

In: Computer Science

I don't know why my java code is not running this error code pops up -->...

I don't know why my java code is not running this error code pops up --> Error: Could not find or load main class DieRoll Caused by: java.lang.ClassNotFoundException: DieRoll.

Code below:

   import java.util.Random;

   import java.util.Scanner;

   public class Assignment {

   public static void combineStrings() {

   String school = "Harvard";

   String city = "Boston, MA";

   int stringLen;

  

   String upper, changeChar, combine;

  

   stringLen = school.length();

   System.out.println(school+" contains "+stringLen+" characters." );

  

   upper = school.toUpperCase();

   System.out.println(upper);

  

   changeChar = upper.replace("A", "*");

   combine = school +" "+city;

   System.out.println("The final string is "+combine );

   }

  

   public static void dieRoll()

   {

   Scanner scanner = new Scanner(System.in);

   Random random = new Random();

   int sides, n1, n2, n3;

  

   System.out.print("How many sides? ");

   sides = scanner.nextInt();

  

  

   n1 = random.nextInt(sides)+1;

   n2 = random.nextInt(sides)+1;

   n3 = random.nextInt(sides)+1;

  

   System.out.println("First Roll\t="+n1);

   System.out.println("Second Roll\t="+n2);

   System.out.println("Third Roll\t="+n3);

   System.out.println("Die Total\t="+(n1+n2+n3));

   System.out.println("Average Roll\t="+((n1+n2+n3)/3.0));

   }

  

  

   public static void candy()

   {

   int numCarton=0,candyBars;

   Scanner scanner = new Scanner(System.in);

  

   System.out.println("Enter the number of candy bars : ");

   candyBars = scanner.nextInt();

   do

   {

   numCarton++;

   candyBars = candyBars-24;

   }while(candyBars > 0);

  

   System.out.println("Number of Cartons needed = "+numCarton);

   }

  

public static void main(String[] args) {

  

   combineStrings();

   dieRoll();

   candy();

   }

}

Solutions

Expert Solution

The code is absolutely fine but your error is Error: Could not find or load main class DieRoll Caused by: java.lang.ClassNotFoundException: DieRoll.

Then follow the below steps:

1.save the java code as Assignment.java then it will work fine.

This because if you won't save as Assignment.java it can't find the main class.

SOURCE CODE:

import java.util.Random;

   import java.util.Scanner;

   public class Assignment {

   public static void combineStrings() {

   String school = "Harvard";

   String city = "Boston, MA";

   int stringLen;

  

   String upper, changeChar, combine;

  

   stringLen = school.length();

   System.out.println(school+" contains "+stringLen+" characters." );

  

   upper = school.toUpperCase();

   System.out.println(upper);

  

   changeChar = upper.replace("A", "*");

   combine = school +" "+city;

   System.out.println("The final string is "+combine );

   }

  

   public static void dieRoll()

   {

   Scanner scanner = new Scanner(System.in);

   Random random = new Random();

   int sides, n1, n2, n3;

  

   System.out.print("How many sides? ");

   sides = scanner.nextInt();

  

  

   n1 = random.nextInt(sides)+1;

   n2 = random.nextInt(sides)+1;

   n3 = random.nextInt(sides)+1;

  

   System.out.println("First Roll\t="+n1);

   System.out.println("Second Roll\t="+n2);

   System.out.println("Third Roll\t="+n3);

   System.out.println("Die Total\t="+(n1+n2+n3));

   System.out.println("Average Roll\t="+((n1+n2+n3)/3.0));

   }

  

  

   public static void candy()

   {

   int numCarton=0,candyBars;

   Scanner scanner = new Scanner(System.in);

  

   System.out.println("Enter the number of candy bars : ");

   candyBars = scanner.nextInt();

   do

   {

   numCarton++;

   candyBars = candyBars-24;

   }while(candyBars > 0);

  

   System.out.println("Number of Cartons needed = "+numCarton);

   }

  

public static void main(String[] args) {

  

   combineStrings();

   dieRoll();

   candy();

   }

}


Related Solutions

I'm getting an error message with this code and I don't know how to fix it...
I'm getting an error message with this code and I don't know how to fix it The ones highlighted give me error message both having to deal Scanner input string being converted to an int. I tried changing the input variable to inputText because the user will input a number and not a character or any words. So what can I do to deal with this import java.util.Scanner; public class Project4 { /** * @param args the command line arguments...
My Java program keeps "running." I know I need to close a "loop" but I can't...
My Java program keeps "running." I know I need to close a "loop" but I can't find it. I'm learning how to code. This is confusing for me. import java.util.Scanner; import java.util.ArrayList; public class SteppingStone4_Loops {    public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String recipeName = ""; ArrayList<String> ingredientList = new ArrayList(); String newIngredient = ""; boolean addMoreIngredients = true; System.out.println("Please enter the recipe name: "); recipeName = scnr.nextLine();    do {    System.out.println("Would you...
PHP Language I have XAMPP and I don't know how to display my PHP code. For...
PHP Language I have XAMPP and I don't know how to display my PHP code. For instance, when I create a basic HTML webpage I just open the code into a web browser and it shows me a basic web page. When I try to show a PHP calculation it doesn't show. What are the steps in displaying my PHP doc?
I don't know how to build my last code for TestPairOfDice...below the question is in bold....
I don't know how to build my last code for TestPairOfDice...below the question is in bold. I'm including my code for the previous problems which are all needed for number 6 1. Implement a method named surface that accepts 3 integer parameters named width, length, and height as user input. It will return the total surface area (6 sides) of the rectangular box it represents. The formula for Surface Area is 2(length * width) + 2(length * height) + 2(height...
I don't know why I keep getting the following error: AttributeError: 'tuple' object has no attribute...
I don't know why I keep getting the following error: AttributeError: 'tuple' object has no attribute 'size' I am using python in Anaconda. import numpy as np def information_gain(x_array, y_array): parent_entropy = entropy(x_array) split_dict = split(y_array) for val in split_dict.values(): freq = val.size / x_array.size child_entropy = entropy([x_array[i] for i in val]) parent_entropy -= child_entropy* freq return parent_entropy x = np.array([0, 1, 0, 1, 0, 1]) y = np.array([0, 1, 0, 1, 1, 1]) print(round(information_gain(x, y), 4)) x = np.array([0,...
JAVA JAVA JAVA Hey i need to find a java code for my homework, this is...
JAVA JAVA JAVA Hey i need to find a java code for my homework, this is my first java homework so for you i don't think it will be hard for you. (basic stuff) the problem: Write a complete Java program The transport Company in which you are the engineer responsible of operations for the optimization of the autonomous transport of liquid bulk goods, got a design contract for an automated intelligent transport management system that are autonomous trucks which...
Hello I have this error in the code, I do not know how to fix it....
Hello I have this error in the code, I do not know how to fix it. It is written in C++ using a Eclipse IDE Error: libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string bus.h =========== #pragma once #include using namespace std; class Bus { private:    string BusId; // bus ID    string Manufacturer; // manufacturer of the bus    int BusCapacity; // bus capacity    int Mileage; // mileage of bus    char Status; // current status...
I have an error on my code. the compiler says 'setLastName' was not declared in this...
I have an error on my code. the compiler says 'setLastName' was not declared in this scope. this is my code : #include <iostream> using std::cout; using std::cin; using std::endl; #include <string> using std::string; class Employee {    public :               Employee(string fname, string lname, int salary)        {            setFirstName(fname);            setLastName(lname);            setMonthlySalary(salary);        }               void setFirstName(string fname)        {       ...
I'm getting an error with my code on my EvenDemo class. I am supposed to have...
I'm getting an error with my code on my EvenDemo class. I am supposed to have two classes, Event and Event Demo. Below is my code.  What is a better way for me to write this? //******************************************************** // Event Class code //******************************************************** package java1; import java.util.Scanner; public class Event {    public final static double lowerPricePerGuest = 32.00;    public final static double higherPricePerGuest = 35.00;    public final static int cutOffValue = 50;    public boolean largeEvent;    private String...
I was wondering is someone could tell me why my code isn't compiling - Java ------------------------------------------------------------------------------------------------------------...
I was wondering is someone could tell me why my code isn't compiling - Java ------------------------------------------------------------------------------------------------------------ class Robot{ int serialNumber; boolean flies,autonomous,teleoperated; public void setCapabilities(int serialNumber, boolean flies, boolean autonomous, boolean teleoperated){ this.serialNumber = serialNumber; this.flies = flies; this.autonomous = autonomous; this.teleoperated = teleoperated; } public int getSerialNumber(){ return this.serialNumber; } public boolean canFly(){ return this.flies; } public boolean isAutonomous(){ return this.autonomous; } public boolean isTeleoperated(){ return this.teleoperated; } public String getCapabilities(){ StringBuilder str = new StringBuilder(); if(this.flies){str.append("canFly");str.append(" ");} if(this.autonomous){str.append("autonomous");str.append("...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT