Adding an interface to previous code: Build an interface for your Splits program
ID: 3569335 • Letter: A
Question
Adding an interface to previous code:
Build an interface for your Splits program(Included below) . The interface cannot simply use the JOptionPane.showInputDialog call.
It must contain some more advanced form of input and output such as a drop down menu, multiple text boxes on one form, a table, tabs, radio buttons, or other method of input/output. The overall design and layout is up to you.
Include frequent comments in your code stating where you got sample code and what you are attempting to do with it. The code must be cited in the program!
The examples below can be used but they do not have to be used:
http://docs.oracle.com/javase/tutorial/uiswing/examples/components/index.html
Previous Code:
***************************************************************************************
import java.util.Scanner;
public class Split_Race_Times {
static int mins[];
static double secs[];
public static void main (String args[]){
Scanner kb = new Scanner(System.in);
System.out.print("How many laps are in the race? ");
int lap = Integer.parseInt(kb.nextLine());
mins = new int[lap];
secs = new double[lap];
userInputTime(kb, lap);
outputTime();
}
public static void userInputTime(Scanner kb, int lapTotal){
for(int i = 0; i < lapTotal; i++){
System.out.println("Enter lap "+(i+1)+" total time:");
String input = kb.nextLine();
String temp[] = input.split(":");
int m = Integer.parseInt(temp[0]);
double s = Double.parseDouble(temp[1]);
mins[i] = m;
secs[i] = s; }
}
public static void outputTime(){
System.out.println();
System.out.println(" Total Time: Lap Time: Difference:");
System.out.println("");
int[] lapMin = new int[mins.length];
double[] lapSec = new double[secs.length];
for(int i = 0; i < mins.length; i++){
if(i==0)
{
lapMin[i] = mins[i];
lapSec[i] = secs[i];}
else{
lapMin[i] = mins[i] - mins[i - 1];
lapSec[i] = (double)Math.round((secs[i] - secs[i-1]) * 100)/100; }
}
for(int i = 0; i < mins.length; i++){
int m = mins[i];
double s = secs[i];
if(i == 0){
System.out.println("Lap1 : "+m+":"+s+" "+m+":"+s+" "+"---");
}
else{
double differenceOfTime = (double)Math.round((lapSec[i] - lapSec[i-1]) * 100) / 100;
String difference= ((differenceOfTime < 0) ? "" : "+") + String.valueOf(differenceOfTime);
System.out.println("Lap"+(i+1)+" : "+ m +":"+ s +" "
+ lapMin[i] + ":" + lapSec[i]+" " + difference);
}
}
}
}
***************************************************************************************
Explanation / Answer
A=0;
x=0;
n=input('How many variables=');
disp('Enter the coefficients along with constants For instance if x+y+3z=-5 then enter 1 1 3 -5 each number followed by an enter not space');
for i=1:n
for j=1:n+1
A(i,j)=input('');
end
end
%pivoting
for i=1:n-1
for j=i+1:n
if abs(A(j,i))>abs(A(i,i))
T=A(j,:);
A(j,:)=A(i,:);
A(i,:)=T;
end
end
end
disp('After pivoting');
disp(A);
for k=1:n-1
for i=k+1:n
m=A(i,k)/A(k,k);
for j=k:n+1
A(i,j)=A(i,j)-m*A(k,j);
end
end
end
disp('Triangularize Form ');
disp(A);
if A(n,n)==0
disp('No unique solution');
end
x(n)=A(n,n+1)/A(n,n);
for j=n-1:-1:1
sum=0;
for i=1:n
sprintf('x%.0f=%.10f',i,x(i))
end
for i=1:n-j
sum=sum+A(j,n+1-i)*x(n+1-i);
end
x(j)=(A(j,n+1)-sum)/A(j,j);
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.