r/javahelp • • May 23 '15

need some help, new java user

0 Upvotes

im new to java and this is my first assignment can anyone help me solving it:

compile the class final grades, based on the students’ scores obtained in the classwork, mid-term, and final exams. According to the course syllabus, the classwork accounts for 65%, the mid-term exam accounts for 15% and the final exam account for 20% of the total class score. A. Write program to calculate the following: a. Students’ average score (taking into account the three weights provided above). b. Students’ grade (A, B, C, D or F) c. Class average (sum of all students’ average score divided by total number of students) d. Highest students’ average score e. Pass rate (total number of students who passed divided by the total number of students)

Assumptions:

  • Grading: Assume the following grade scale: 90% - 100% (A); 80% - 89.99% (B)70% - 79.99% (C); 60% - 69.99 % (D); and 0 – 59.99% (F). Also, as per the course policy, if the student achieves less than 55% in the final exam, he will fail the course even if the average score is above 60%.

  • Input Data: You may assume the following input data. Please note that the scores correspond to classwork, midterm and final exam scores, respectively (in this order). Naji Hasan 90 85 87 Lisa Smith 80 67 70 Andy Malik 75 80 52 Ravi Gupta 90 95 98 Dave Blair 50 61 70 Sara Clark 70 65 81 Sami Moosa 55 50 71 Imed Radhi 90 83 89 Kira Sunny 65 70 69 Hind Ahmed 70 81 88

You must use arrays to store each of the above records.

i only need the pseduo code for this one please do help


r/javahelp • • Jul 04 '21

Can Anyone help me with this code?

0 Upvotes
class A{
	public void process(){
		System.out.print("A,");
	}
}
public class Questions extends A{
	public void process() throws IOException{
		super.process();
		System.out.print("B,");
		throw new IOException();
	}
	public static void main(String[] args) {
		try{
			new Questions().process();
		}
		catch(IOException e){
			System.out.print("Exception");
		}
	}
}

Why is it giving Compilation error?

Error -> Exception IOException is not compatible with throws clause in A.process()


r/javahelp • • Jul 20 '21

Solved Can't create executable jar file

0 Upvotes

Hey guys,

i use Bluej for programming java (it's for school) and we made a little project with JFrames, etc... I didn't want to open bluej everytime just to start the program so I wanted to export it to a .jar file.

BlueJ includes this feature so I only have to say which is the class with the main-method and if I want to download the java libraries too.

That's fine but if I now open the Jar file there's just this error:

"error a jni error has occurred please check your installation and try again"

this is my class with the main-method: (is there my mistake?)

public class Simulation
{
   private Controller controller;
   private Login_Model lm;
   private Game_Model gm;
   
    public static void main(String[] args) {
        new Simulation();
    }
    public Simulation() {
        lm = new Login_Model();
        gm = new Game_Model();
        controller = new Controller(lm, gm);
    }
}

r/javahelp • • Jul 25 '21

Solved it's for printing high score for snake games created in java used txt file used for storage

0 Upvotes
 File file = new File("scoredata.txt");

               try  {
                    BufferedReader reader = new BufferedReader(new FileReader(file));
                    String line = reader.readLine();
                    while (line != null)          
                    { 
                        try {
                             int score2 = Integer.parseInt(line.trim());   
                              
                            if (score2 <= highScore)                     
                            {  
                                highScore = score2; 
                            }

                            line = reader.readLine();
                        } catch (NumberFormatException e1) {

                        }
                        
                    }
                    reader.close();

                } catch (IOException ex) {
                    System.err.println("ERROR reading scores from file");

data is not being stored in highScore and printing it as zero when I use it

link to the code file https://pastebin.com/YwF4Rxi2


r/javahelp • • Jul 23 '21

Why is my program outputing text horizontally?

0 Upvotes

As you can see in the images, the text from the file looks like this: https://imgur.com/a/ooduRtx

However, when I run the program it prints out in the console like this: https://imgur.com/a/YDhmoqC

I want it to print out in the console the same way it looks in the .txt file.

Here's the code in pastebin: https://pastebin.com/0TU5b3Ba

Edit: forgot to mention I'm using eclipse IDE.


r/javahelp • • Jul 09 '21

Unsolved .class file help

0 Upvotes

Heyo, does anyone know how to open a .class file so I can read the code inside?


r/javahelp • • Mar 20 '24

I hate strings

0 Upvotes
import java.util.Scanner;
public class Main {
public static void main(String[]args){
Scanner in = new Scanner(System.in);

String s = in.next();
String rest = s;
String result = ""; // empty string?
int i = 0;

while (rest.length() > 0) 
{
String first = rest.substring(0,1); //extracts first character of 'rest' string
rest = rest.substring(1); // now it removes the first character?

if (rest.contains(first))
{
result = result + first; // what is being added if 'result' is empty
}
}
System.out.println(result);
}
}

any video recomms for this type of use for loops and strings?? I tried using a table chart to understand a little better but it didnt work out for me, and i still dont understand how it works. Help would be appreaciated.


r/javahelp • • Mar 04 '24

Homework Help with displaying graphics using java code

0 Upvotes

I'm in AP computer science A and I have a project due tmrw that I hardly worked on, so I'm basically fucked. I need to add an outside element that we didn't learn in the class to the project and the only thing I could think of is a graphic element. The only issue is I have no idea where to start. Everything I found online is not at all what I am looking for. I just need to show images that I will make on like a blank screen or something and then change the images based on my code. I am going to use replit so if that helps idk??? I just need a source I can reference on how to do this or a point in the right direction because I have no idea what I'm doing


r/javahelp • • Mar 11 '24

java project

0 Upvotes

what should i make as my first project in java


r/javahelp • • Feb 27 '20

Homework Why is 17.0f is less than 4.567?

0 Upvotes

I am reading this OCJP exercise and there is a comparison as follows:

public classPrim { public static void main(String[] args) { int num1 = 12; float num2 = 17.8f boolean resultVal = num1 >= 12 && num2 < 4.567 || eJavaResult == true; System.out.println(returnVal); }}

N one of the explanation is :

boolean returnVal = (num1 >= 12 && num2 < 4.567) || eJavaResult == true;

My question is num2 should be less than 4.567 right ? But if the rest of the conditions are met so it returns true.

Hope someone can clarify my doubts. Tks.


r/javahelp • • Mar 11 '22

Unwanted Else statements?

0 Upvotes

This is a Java project I am practicing. I am trying to have it output the user-selected options. However, it keeps outputting all of the options' else statements. How do I prevent this from outputting all of the else statements? Is it possible to write this as a while statement?

import java.util.Scanner;

public class ShadyRestRoom2 {

`public static void main(String[] args)`

`{`

	`Scanner input = new Scanner(`[`System.in`](https://System.in)`);`

	

	`int queen = 125;`

	`int king = 139;`

	`int couch = 165;`

	`int invalid = 0;`

	

	`System.out.println("Welcome to the Shady Rest Hotel. Input 1 for a queen bed, 2 for a king, or 3 for a king and a pullout couch.");`

	`int option = input.nextInt();`

	`System.out.println("Insert (1) for a lake view or (2) for a park view.");`

	`int view = input.nextInt();`

	

	`// Selection statements for the queen bed.`

	`if (option == 1 && view == 1)`

	`{`

		`queen = queen + 15;`

		`System.out.println("Option " + option + " has been selected. You will be assigned the queen bed with a lake view. That will be $" + queen + ".");`

	`}`

	`else if (option == 1 && view == 2)`

	`{`

		`System.out.println("Option " + option + " has been selected. You will be assigned the queen bed with a park view. That will be $" + queen + ".");`

	`}`

	`else`

	`{`

		`queen = queen + 15;`

		`System.out.println("Did you intend to select the queen bed with a lake view? That will be $" + queen + ".");`

	`}`

	

	`// Selection statements for the king bed.`

	`if (option == 2 && view == 1)`

	`{`

		`king = king + 15;`

		`System.out.println("Option " + option + " has been selected. You will be assigned the king bed with a lake view. That will be $" + king + ".");`

	`}`

	`else if (option == 2 && view == 2)`

	`{`

		`System.out.println("Option " + option + " has been selected. You will be assigned the king bed with a park view. That will be $" + king + ".");`

	`}`

	`else`

	`{`

		`king = king + 15;`

		`System.out.println("Did you intend to select the king bed with a lake view? That will be $" + king + ".");`

	`}`

	

	`// Selection statements for the king bed and a pull-out couch.`

	`if (option == 3 && view == 1)`

	`{`

		`couch = couch + 15;`

		`System.out.println("Option " + option + " has been selected. You will be assigned the king bed and a pull-out couch with a lake view. That will be $" + couch + ".");`

	`}`

	`else if (option == 3 && view == 2)`

	`{`

		`System.out.println("Option " + option + " has been selected. You will be assigned the king bed and a pull-out couch with a park view. That will be $" + couch + ".");`

	`}`

	`else`

	`{`

		`couch = couch + 15;`

		`System.out.println("Did you intend to select the king bed and a pull-out couch with a lake view? That will be $" + couch + ".");`

	`}`		

`}`

}


r/javahelp • • Apr 02 '22

Homework I desperately need help on this Java GUI code of displaying random images with a button, assistance please!

0 Upvotes

I need to help figuring out this code, I want to make an array of images appear randomly by a button click, and another image appear with another button click.

But there is an error, I can't figure it out:

 package m03Test;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Color;
import java.awt.Font;
import java.util.Random;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;

public class M03 extends JFrame {
	
	private ImageIcon Light1 = new ImageIcon(M03.class.getResource("/resources/Planet1.png"));
	private ImageIcon Light2 = new ImageIcon(M03.class.getResource("/resources/Planet2.png"));
	private ImageIcon Light3 = new ImageIcon(M03.class.getResource("/resources/Planet3.png"));
	private ImageIcon Light4 = new ImageIcon(M03.class.getResource("/resources/Planet4.png"));
	private ImageIcon Light5 = new ImageIcon(M03.class.getResource("/resources/Planet5.png"));
	private ImageIcon Light6 = new ImageIcon(M03.class.getResource("/resources/Planet6.png"));
	private ImageIcon Light7 = new ImageIcon(M03.class.getResource("/resources/Planet7.png"));
	private ImageIcon Light8 = new ImageIcon(M03.class.getResource("/resources/Planet8.png"));
	private ImageIcon Light9 = new ImageIcon(M03.class.getResource("/resources/Planet9.png"));
	
	private JLabel lblDisplay;
	
	
	private final Random rand = new Random();
	int spread = rand.nextInt(9);
	int vertify = 0;
			

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					M03 frame = new M03();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public M03() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JPanel ImagePanel = new JPanel();
		ImagePanel.setBackground(new Color(0, 0, 139));
		contentPane.add(ImagePanel, BorderLayout.SOUTH);
		
		JButton ResetButton = createResetButton();
		ImagePanel.add(ResetButton);
		
		JButton RandomButton = createRandomButton();
		ImagePanel.add(RandomButton);
		
		JLabel lblTitle = createlblTitle();
		contentPane.add(lblTitle, BorderLayout.NORTH);
		
		lblDisplay = satellite();
		
		JLabel lblDisplay = satellite();
		contentPane.add(lblDisplay, BorderLayout.CENTER);
	}

	private JButton createRandomButton() {
		JButton RandomButton = new JButton("Random");
		RandomButton.setBackground(new Color(0, 191, 255));
		ImageIcon[] Satellite = { Light1, Light2, Light3, Light4, Light5, Light6, Light7, Light8, Light9};
		
		RandomButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				do
				{
					spread = rand.nextInt(9);
					
				} while (spread == vertify);
				
				vertify = spread;
				
				lblDisplay.setIcon(Satellite[vertify]);
			}
			
		});
		
		return RandomButton;
	}

	private JLabel satellite() {
		JLabel lblDisplay = new JLabel("");
		lblDisplay.setIcon(Satellite [spread]);
		lblDisplay.setHorizontalAlignment(SwingConstants.CENTER);
		return lblDisplay;
	}

	private JButton createResetButton() {
		ImageIcon Starlight = new ImageIcon(M03.class.getResource("/resources/Solar.jpeg"));
		
		JButton ResetButton = new JButton("Solar Reset");
		ResetButton.setBackground(new Color(0, 191, 255));
		
		ResetButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ResetButton.setIcon(Starlight);
			}
		});
		return ResetButton;
	}

	private JLabel createlblTitle() {
		JLabel lblTitle = new JLabel("New label");
		lblTitle.setForeground(new Color(255, 255, 0));
		lblTitle.setBackground(new Color(0, 0, 0));
		lblTitle.setFont(new Font("Verdana", Font.PLAIN, 12));
		lblTitle.setHorizontalAlignment(SwingConstants.CENTER);
		lblTitle.setOpaque(true);
		return lblTitle;
	}

}

r/javahelp • • Feb 23 '22

Bytecode editor?

0 Upvotes

I'm aware that class files are a binary format but I want to be able to edit class files and have the corresponding bytecode generated for me. So basically just open up a jar and edit a ClassFile and have the jar updated to match. Does such a tool exist?


r/javahelp • • Mar 06 '22

I was wondering if it is worth it to get a maxed out Macbook Pro for programming Java

0 Upvotes

I currently live in Brazil and a maxed out Macbook Pro costs U$ 14,400.00 here. So I was wondering if the investment is worth it if I'm going to be mostly working with Java. Thanks for your help!


r/javahelp • • Apr 01 '22

help with java code

0 Upvotes

hi i’m trying to write code for an assignment and a part of my code (i < drywet.length && i < wetwet.length) are underlined red. it says “the operator < is undefined for the argument type(s) int, Object”

can someone please explain what i need to do to fix it?


r/javahelp • • Apr 02 '16

help?

0 Upvotes

I am new trying to learn java programming i started watching "thenew****" Tutorials, everything was fine untill i reached the second video where i reach the command prompt part to load my code. When i want to put ex " java Hello.java" It says Error: Could not find or load main class. DOnt even know if i have the right java or version anyway this is it . jre1.8.0_45 . Hope i get helped.


r/javahelp • • Dec 30 '14

Need some help with various aspects

0 Upvotes

I am adding sound into my program, and since I'm new to this, I watched a sound tutorial, (Heres my code http://pastebin.com/b3VJiaqf) but it still does not work... Also, currently using g.fillRect() to add a solid colored background. How can I change this to use an image instead? Next, I need to know how to change the Jframe icon (Also the program icon) from the default Java icon. Finally is this: I would like to add (As a beta test joke) an error window that will randomly pop up and crash the game every X times the game is opened. The window would pop up, and the program would stop responding. Thanks


r/javahelp • • Sep 04 '15

I really can't think of a better place to ask this [Job advice]

0 Upvotes

So I'm going to graduate with a bachelors from ohio state university in about a year in CSE, but I keep seeing all these reddit posts about how every job needs 5 years experience, and finding a job is too difficult etc, is this really how it is for CSE as well? did you find a job relatively easy?


r/javahelp • • Jan 05 '18

Could you please check my code?

0 Upvotes

Task: https://pastebin.com/4TS4GHF4 RESTcontrol.java: https://pastebin.com/m5F0guF4 IMdbManager.java: https://pastebin.com/3TaWdMXs

Thank you very much for help.


r/javahelp • • Nov 25 '20

New to Java

0 Upvotes

I’m new to Java and am taking a class online. I’m having trouble understanding anything. I can’t get any program to run, even when the instructor gives me the program to copy. Can anyone explain it in terms that an idiot can understand? I can create a class...then I’m at a loss. My instructor just seems annoyed that I don’t get it. I’m afraid he’s just going to fail me without helping.


r/javahelp • • Nov 23 '20

Need a look over to why I'm getting multiple of the same returns in from my code. explained slightly better inside.

0 Upvotes

I'm looking to get 10 unique random numbers from my code. It is giving me 10 unique numbers, but not before displaying the "unique" numbers a lot of times before getting through the loop. I'm pretty terrible with explaining this stuff.

My code is supposed to ask the user to enter a number from 1 to 100, give an error if the number is outside those bounds, and generate 10 random numbers larger than the entered number.

https://pastebin.com/s9KgQ6Bm -- this is my code thus far.

Edit-1: Forgot to mention, I'm not getting any errors from the code currently as it stands.


r/javahelp • • Feb 05 '25

Receiving list of strings or strings, what's the enterprise level of doing this?

0 Upvotes

Is writing a JsonDeserializer component the best way to do this if I can possibly receive a list of strings or strings for an object as a payload from a server?


r/javahelp • • Jul 27 '22

Need help with this code

0 Upvotes

I am trying to create a class called point which will have an x and y as coordinates however error squiggles show up and it's not running can someone point out the problem btw the code is not complete

public class Circle_class {
class Point(int x,int y)
    {
int x;
int y;
        x = x;
        y = y;
    }
class circle
    {
double radius;
Point center;
    }
}


r/javahelp • • Aug 18 '22

Codeless Help on Scanners

0 Upvotes

Why do we need to pass scanner as parameter to a method?? Is it necessary? Tried google but every thing bounced over my head. Can somebody explain this in easy terms. Thanks!