# Lab Question# We must create a program that do the following: Allow the user to type in a student name the coorosponds with the student's exam score. The program will be able to accpet exam scores till the user types in the phrase "allDone". The code will determine which student has the highest score and give the name and the score to the user. Here is an example of what will be shown in the console.... *Sample Input* Bob 82 Mary 90 James 87 alldone *Sample Output* Mary has the highest score. Her score is: 90. ## Question ## …

Member Avatar
Member Avatar
+0 forum 6

Hi, something weird happened with my program, I mean when I run it I see only grey frame (like I had only JFrame object in my app), then I minimalize application, maximalize it and only then I see all components painted (JButton, rectangels and lines inside Jpanel,...). Changing of frame size helped too, but now I have fixed size, so this is not anoption. Can you tell me what can cause that behaviour. This is class which draw everything: public class Simulation{ JFrame frame; JPanel background; RoadSystem roads; Stats stats; Settings settings; JButton startButton; public Simulation() { frame = new …

Member Avatar
Member Avatar
-1 forum 2

Hi. I'm trying to create a Traffic simulator and I'm stuck on how to get a Car object to turn into a road. I've managed to have a car go straight (which is really easy anyway lol) but I can't really find a way to get it to turn into a road, specifically a left turn. The code I have currently is this: [CODE]import java.applet.*; import java.awt.*; import java.awt.geom.AffineTransform; public class Traffic3 extends Applet implements Runnable { //thread variables Thread t; int i; //double buffer variables Image offscreenImage; Graphics offscr; int width; int height; //car //coordinates for lanes //south road, …

Member Avatar
Member Avatar
+0 forum 9

I need to create a class that represents one crayon of a particular color and height(length). Then, I need to design an applet that lets me draw a box of different colored crayons. This is what I have so far: **CLASS:** import java.awt.*; public class Crayon { private final int BOTTOM = 150; private final int WIDTH = 25; private Color color; private int length, location; //---------------------------------------------------------------------------------------------- // Crayon's characteristics. //---------------------------------------------------------------------------------------------- public Crayon (Color color, int length, int position) { color = color; length = length; location = position; } //---------------------------------------------------------------------------------------------- // Draws crayon. //---------------------------------------------------------------------------------------------- public void draw (Graphics page) …

Member Avatar
Member Avatar
+0 forum 5

Is there any method in java to generate random number (integer, byte or float) ? Please tell me if any i need it in my program. If possible please give full example. Thanks!

Member Avatar
Member Avatar
+0 forum 1

Howdy All - I am just wondering if anyone has successfully converted a *massive* (subjectivity implied) COBOL application to another language. If so, into which language was your system converted and when was this done? What were the potholes you, no doubt, hit? Was the conversion far more expensive than anticipated? What hidden costs were exposed? Was there a performance gain/loss in the new language? Did anyone convert from COBOL to PL/SQL? to T-SQL? to Java? to C#.NET? Thanks, and have a great day!

Member Avatar
Member Avatar
+0 forum 10

I have a program that is meant to display the total, average, student name and letter grade for a student. I'm almost done writing it but I have no idea how to make it loop so it goes back to step 1 from step 4. Everything I've read on using "while" loops hasn't really been helpful to me with this particular application. import java.util.Scanner; public class Averages5 { public static void main(String[] args) { // variable declaration String name; int mark1, mark2, mark3 ; int grade = 0; int A, B, C, F; double average; // input Scanner input = …

Member Avatar
Member Avatar
+0 forum 2

The API docs are now found at [ Java Development Kit Version 11 API Specification](https://docs.oracle.com/en/java/javase/11/docs/api/)

Member Avatar
Member Avatar
+0 forum 3

Hi all, I need to read a text file (I've attached it, you can take a look), and then store all the numbers in it into a 2D array. After which, I need to parse it. I need urgent help here! ):

Member Avatar
Member Avatar
-2 forum 49

Question from codility test Write a function: class Solution { public int solution(int[] A); } that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A. For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5. Given A = [1, 2, 3], the function should return 4. Given A = [−1, −3], the function should return 1. Write an efficient algorithm for the following assumptions: > > N is an integer within the range [1..100,000]; > each element of array A is an …

Member Avatar
Member Avatar
+0 forum 8

I have class with main method like: public class Main { public static void main(String[] args) { long timeCheck; long periodOfTime; ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2); long initialDelay = 0; // the time from now to delay execution long period = 1; // the period between successive executions scheduler.scheduleAtFixedRate(new FeedReader(img, url, title, price), initialDelay, period, TimeUnit.DAYS); ... ... } } and another class with some code: public class FeedReader implements Runnable { private String img; private String url; private String title; private String price; public FeedReader(String img, String url, String title, String price) { this.img = img; this.url = url; this.title …

Member Avatar
Member Avatar
+0 forum 8

I am trying to display this SQL query in a table. String query = "SELECT COUNT(`appointmentId`),EXTRACT(MONTH FROM `start`) FROM `appointment` WHERE YEAR(start) = '" + year + "' GROUP BY EXTRACT(MONTH FROM `start`)"; Unfortunately I cannot alter the database. I am trying to list the total appointments per month on a table or perhaps a TextArea. Any ideas please? Thanks!

Member Avatar
Member Avatar
+0 forum 2

All, For the life of me I cannot get this program to compile. The error message "error: non-static variable this cannot be referenced from a static context" occurs on lines 23 and 24. Here is the entire program: [CODE]public class ThreadTest { public static int x = 0; public class Counter implements Runnable { private int i; private int temp; public void run() { for (i=0; i<10; i++) { temp = x + 1; x = temp; } } //End run() } //End class Counter public static void main (String[] args){ Counter myCounter1 = new Counter(); Counter myCounter2 = new …

Member Avatar
Member Avatar
+0 forum 9

Hi Guys, I ussually dont post anything here often, just get everything off of everyone elses questions, but I'm having a strange problem that im scratching my head over, I have a JTable where I can Add and remove rows... This is just for testing purposes, I'm about to make a ingrediants program. The thing is whenever I change one of the Comboboxes they all seem to change.. its really wierd, Could Someone run this and help me out, this is probably a stupid mistake? See my Code Below, My Main package doughtracker; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; /** * * …

Member Avatar
Member Avatar
+0 forum 13

Hey guys, I have a little bit confused on below code and output **Main ** public class Main { public static void main(String[] args) { ClassA classA = new ClassA(); System.out.println("====== Before ====="); classA.checking(); System.out.println("===== After ====="); classA.checking(); } } ** Class A** public class ClassA { boolean b = true; public String checking() { System.out.println("B value is " + b); if (b = true) { System.out.println("B is true"); b = false; } else { System.out.println("B is false"); } return null; } } ** Output** ====== Before ===== B value is true B is true ===== After ===== B value …

Member Avatar
Member Avatar
+0 forum 4

I have to print some text to printer. I needed to translate that text in Urdu language also. For that I used google translation API and all was set. But I am facing problem in order of output. // this is the code which is giving my desired output String text = "Honda head light large size" String translatedText = GoogleTranslate.translate("ur", text); String myString = "Saboor" String printString = String.format("%-15s %-15s %-10s",text,translatedText,myString); graphics.drawString(printString,x,y) //Above code is giving me correct output as following Honda head light large size urdu translation Saboor // Now pasting the code which create problem: String text …

Member Avatar
Member Avatar
+0 forum 1

Guys, Ive gotten it into my head to do somthing fairly difficult for me, I want to communicate with a swing application, to a proximetly sensor, and track live when it senses somthing and how many times it has sensed somthing, I want to use java. theres alot more to it than this, eventually connect a multitude of sensors, temperture, photo eyes, etc, I want to recieve these signals wirlessly as i want to see it on my office computer, and the sensors with be in another room, How would I get started with this? Treat me like a noob, …

Member Avatar
Member Avatar
+0 forum 3

Hey guys! help me out, i'm really out of ideas, how can i save the datas i inputed to have a rotation of value , like the computation in the withdraw, when i 1st use the withdraw or deposit, it computes, yes but when the 2nd time i use it, it still on 10000 value. heres my codes (sorry not my native language) /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package bank; import java.util.Scanner; /** …

Member Avatar
Member Avatar
+0 forum 4

I'm trying to read in from a .txt file with a Scanner (see code). For some reason this line of code will never execute even though it can open the file and there is, in fact, data in it as such: Name Name Number Number [CODE] File playerFile = new File(fileName); Scanner dataFile = new Scanner(playerFile); while(dataFile.hasNextLine()) [/CODE] Why would datafile.hasNextLine() return false?

Member Avatar
Member Avatar
+0 forum 12

Define a class named Pair where the data(state) part contains two double-typed numbers, num1 and num2. The method(behaviour) part contain the following methods: o getSum() – returns the result of adding num1 with num2 o getdifference() – returns the result of substracting num2 from num1 o getProduct() - returns the multiplication of num1 with num2 o getAverage() – returns the average of num1 & num2 o getMax() - returns the larger of the two numbers o getMin() – returns the smaller of the two numbers You also need to define a constructor method as described below: public Pair(double aFirst, double …

Member Avatar
Member Avatar
+0 forum 1

Hello all, I have a code to encrypt data in C# and I want it to b decrypted in Java... following is the C# code [CODE]string Encrypt(string textToEncrypt, string key) { RijndaelManaged rijndaelCipher = new RijndaelManaged(); rijndaelCipher.Mode = CipherMode.CBC; rijndaelCipher.Padding = PaddingMode.PKCS7; rijndaelCipher.KeySize = 0x80; rijndaelCipher.BlockSize = 0x80; byte[] pwdBytes = Encoding.UTF8.GetBytes(key); byte[] keyBytes = new byte[0x10]; int len = pwdBytes.Length; if (len > keyBytes.Length) { len = keyBytes.Length; } Array.Copy(pwdBytes, keyBytes, len); rijndaelCipher.Key = keyBytes; rijndaelCipher.IV = keyBytes; ICryptoTransform transform = rijndaelCipher.CreateEncryptor(); byte[] plainText = Encoding.UTF8.GetBytes(textToEncrypt); return Convert.ToBase64String(transform.TransformFinalBlock(plainText, 0, plainText.Length)); }[/CODE] and the java decryption is as follows... [CODE]String …

Member Avatar
Member Avatar
+0 forum 8

I'm having problems compiling my program, I was wondering if someone could tell me where I went wrong and how to fix it. I would be deeply apreaciative of your help!!!! :) import java.util.Random; import java.io.Console; class project2_0 { int[] race = new int[70]; int tortoise; int hare; Random randomnumbers = new Random(); boolean again = true; public void StartRace() { tortoise = 1; hare = 1; Console.WriteLine("ON YOUR MARK, GET SET.... BANG!!!"); Console.WriteLine("AND THEY'RE OFF!!!!"); while (tortoise < 70 && hare < 70) { MoveHare(); MoveTortoise(); DisplayCurrentLocation(); string request; } //end while if (tortoise > hare) { Console.WriteLine("\n TORTOISE …

Member Avatar
Member Avatar
-1 forum 14

Hi guys, I'm playing around ith optionals a little, but I'm not surewhether this is the correct behavious as I'm getting a null pointer exeption (I thought the point of Optionals was not to get a null pointer.) SO I'm setting an object to null and before calling toString on it I'm using isPresent() on it. Here is the code: package optional_test; import java.util.Optional; public class Optional_test { public static void main(String[] args) { Optional<Customer> customer1 = Optional.ofNullable(new Customer("John", "Doe")); Optional<Customer> customer2 = null; if(customer1.isPresent()){ System.out.println(customer1.get()); } if(customer2.isPresent()){ System.out.println(customer2.orElse(new Customer("Unknown", "Unknown"))); } } } And the cCustomer class: package optional_test; …

Member Avatar
Member Avatar
+0 forum 4

I trying to write a `spring batch` using `SpringBoot`. At first the program will read data from database, then write it to `.csv` file format. This is the code I have tried **Reader** @Bean public ItemReader<A> Reader() throws Exception { List list = new ArrayList<>(); JdbcCursorItemReader<A> reader = new JdbcCursorItemReader<A>(); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sql = "SELECT ID AS id FROM TABLE_A "; list = jdbcTemplate.query(sql, new Mapper()); // store all retrieved data to list reader.setSql(sql); reader.setDataSource(dataSource); reader.setRowMapper(new Mapper()); if (list != null) { for (A c : (List<A>) list) { c.setId("123"); // overwrite the id c.setState("Active"); } …

Member Avatar
Member Avatar
+0 forum 1

Hey guys this is my first time using this site. Im having trouble creating a grading scale that averages out grades. Whenever I enter the grades in from the console I get some odd answers that make no sense. Can someone give me some pointers in the right direction? public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter Final Exam average"); int Fexam = input.nextInt(); System.out.println("Enter Midterm average"); int Midterm = input.nextInt(); System.out.println("Enter Quiz average"); int Quiz = input.nextInt(); System.out.println("Enter Homework Average"); int HW = input.nextInt(); System.out.println("Class Average"); int CA = input.nextInt(); double Final = (Fexam / …

Member Avatar
Member Avatar
+0 forum 2

Hello, I would like to develop a sprite editor. Therefore I have programmed a software like paint. As you can see on the picture, on the right, there is a canvas with a grid on it. I use a GridBagLayout to manage every widgets inside my window. The canvas is represented by a JLabel which is inside a JLayeredPane. I have set the size of the JPanel with setPreferredSize. It works well with my screen resolution because there is enough space to display the canvas. However on smaller screen, it doesn't show up. Any idea on how to adapt the …

Member Avatar
Member Avatar
+0 forum 1

I feel hard to understand how the LayoutManager work even the GUI is quite simple. I trying to make the button place below the Tel No JTextField, but it placed beside Address JTextField , not below TelNo JTextField. package gui; import java.awt.BorderLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SpringLayout; import javax.swing.SwingUtilities; public class OrderPage extends JPanel { public static void main(String[] args) { OrderPage order = new OrderPage(); order.createAndShowGUI(); JFrame frame = new JFrame(); frame = new JFrame(); frame.setTitle("Details"); frame.getContentPane().add(order); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } public …

Member Avatar
Member Avatar
+0 forum 7

I am trying to understand the SynchronizedMap and I ran the below code. I get the below Output with an exception. According to my understanding the exception is caused when the get() methods are trying to access the syncmap when a thread is still executing a write on the map or Thread is in the Sleep state. Is my understanding correct or am I missing something ? class MapHelper1 implements Runnable { Map<String, Integer> map; public MapHelper1(Map<String, Integer> map) { this.map = map; new Thread(this, "MapHelper1").start(); } public void run() { map.put("One", 1); try { System.out.println("MapHelper1 sleeping"); Thread.sleep(100); } catch …

Member Avatar
Member Avatar
+0 forum 1

I was wondering what would be the best way to implement an algorythm to figure out what side a circle has collided with a rectangle? After check to make sure a circle has collided with the rectangle im trying to figure out how to know what side of the rectangle was hit. The problem is the rectangle is smaller than the circle somtimes.... everything ive tried so far will only work if the rectangle is bigger than the circle.. Any ideas will be greatly appreciated. Scheppy.

Member Avatar
Member Avatar
+0 forum 39

Hi Guys, Im currantly having a problem with simulating balls bouncing of each other in a 2d space, everything is working and all, but it just doesant seem natural for me... If we had any math wizzes here now is your time please:) my circles are painted inside of rectangles..... This is what is the code im using to find the new x and y coordinates of the circles. specifically this piece here... //Pythagerum theorem, a^2 + b^2 = c^2, to figure out the distance between the two circles' centers. int distance = (int) Math.sqrt(((currantXa - currantXb) * (currantXa - …

Member Avatar
Member Avatar
+0 forum 14

The End.